Skip to content

Commit

Permalink
docs: fix systemd note
Browse files Browse the repository at this point in the history
closes #739
  • Loading branch information
caarlos0 committed Dec 6, 2023
1 parent 60cff80 commit aaaa3fb
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions www/docs/tips.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# Tips, Hints and useful information

## General maintainability of your packages
* Try hard to make all files work on all platforms you support.
* Maintaining separate scripts, config, service files, etc for each platform
quickly becomes difficult
* Put as much conditional logic in the pre/post install scripts as possible

- Try hard to make all files work on all platforms you support.
- Maintaining separate scripts, config, service files, etc for each platform
quickly becomes difficult
- Put as much conditional logic in the pre/post install scripts as possible
instead of trying to build it into the nfpm.yaml
* *if* you need to know the packaging system I have found it useful to add a
- _if_ you need to know the packaging system I have found it useful to add a
`/etc/path-to-cfg/package.env` that contains `_INSTALLED_FROM=apk|deb|rpm`
which can be sourced into the pre/post install/remove scripts
* *if/when* you need to ask questions during the installation process, create an
- _if/when_ you need to ask questions during the installation process, create an
`install.sh` || `setup.sh` script that asks those questions and stores the
answers as env vars in `/etc/path-to-cfg/package.env` for use by the pre/post
install/remove scripts
* If you only need to support deb packages you can use the debconf
template/config feature, but since rpm does not support this I would try to
unify the way you ask questions.
- If you only need to support deb packages you can use the debconf
template/config feature, but since rpm does not support this I would try to
unify the way you ask questions.

## Pre/post install scripts

Here are some useful links for how these scripts work in each packager:

* [APK Docs](https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package#install)
* [RPM Docs](https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/)
* [DEB Docs](https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html)
- [APK Docs](https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package#install)
- [RPM Docs](https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/)
- [DEB Docs](https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html)

### Examples

Expand Down Expand Up @@ -118,7 +119,6 @@ cleanup

</details>


<details>
<summary>Example Multi platform (RPM & Deb) post-remove script</summary>

Expand Down Expand Up @@ -163,8 +163,8 @@ esac

</details>


### Execution order

On upgrade, the scripts are being executed in the following order:

1. `pretrans` of new package (only applies to RPM)
Expand All @@ -177,25 +177,24 @@ On upgrade, the scripts are being executed in the following order:
## SystemD and upstart/init

### upstart / init
* try to just say no to supporting this, but if you must make sure you have a

- try to just say no to supporting this, but if you must make sure you have a
single script that works on all platforms you need to support.
* as the `post-install` script above does.
- as the `post-install` script above does.

### SystemD

* The docs you find for SystemD are generally for the latest and greatest
- The docs you find for SystemD are generally for the latest and greatest
version, and it can be hard to find docs for older versions.
* In the above `post-install` script you see I am doing a SystemD version
check to correct the `ExecStartPre=+...` and `ExecStop=+...` lines
* You should always use
- In the above `post-install` script you see I am doing a SystemD version
check to correct the `ExecStartPre=+...` and `ExecStop=+...` lines
- You should always use
[automatic directory creation and environment variables](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#id-1.14.4.3.6.2)
* With the note that only `RuntimeDirectory` is used in SystemD < 231
* `/bin/bash -c "$(which ...) ...` is a great way to make your single service
- With the note that only `RuntimeDirectory` is used in SystemD < 211
- `/bin/bash -c "$(which ...) ...` is a great way to make your single service
file work on all platforms since RHEL and Debian-based systems have standard
executables in differing locations and complain about `executable path is not
absolute`
* e.g. `/bin/bash -c '$(which mkdir) -p /var/log/your-service'`

executables in differing locations and complain about `executable path is not absolute`
- e.g. `/bin/bash -c '$(which mkdir) -p /var/log/your-service'`

## Debian packages

Expand All @@ -222,7 +221,6 @@ You can read more in [lintian's documentation](https://lintian.debian.org/manual

If you need a `copyright` file, you can add it using the `contents` directive:


```yaml
# nfpm.yaml
contents:
Expand All @@ -232,4 +230,3 @@ contents:
file_info:
mode: 0644
```

0 comments on commit aaaa3fb

Please sign in to comment.