Installing a systemd service from an RPM?

7

1

I've been creating RPMS (using CMake's CPack) which install everything into /opt, and then the postinstall script copies the service definition files to /etc/systemd/system.

I've toyed around with starting and stopping the services as well in the RPM postinstall and preuninstall scripts, but this doesn't seem to be a good idea, because yum will run the postinstall script before the preuninstall script if doing an upgrade, and that means that if you try to upgrade a service, you end up with the service not running anyways. Even enable/disable seems to have the same issue.

So the two questions I have

  1. Is it a good idea to install directly into /etc/systemd, or should a postinstall copy from /opt to /etc/systemd? Is cp followed by systemctl daemon-reload the "right" way of installing the service file?

  2. Is there a clean way of starting/stopping/enable/disable services from an RPM, or is this better left out of the RPM?

Related question (with no answers) for Debian:

Preferred/Idiomatic method to enable a systemd.service from a Debian package installation

Mark Lakata

Posted 2015-07-06T16:42:17.490

Reputation: 4 260

1I believe that in RPM-based distributions, it is frowned upon to ship (or copy) files in /etc. Instead, you should ship them into /lib/systemd. This way, your users can change the files by copying them to /etc, without losing changes on upgrade. – Wouter Verhelst – 2015-07-30T11:02:18.243

Answers

3

See: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd

In scriptlets you can use $1 variable for detecting if it is upgrade or clean install or upgrade or removal of package. The value of the variable is defined here: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax

msuchy

Posted 2015-07-06T16:42:17.490

Reputation: 504