Installing a systemd service from an RPM?

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


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