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

  • 1
    I 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 Jul 30 '15 at 11:02

See: https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#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://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Syntax

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.