From Fedora Project Wiki
(original version)
 
(update links, remove some obsolete references)
Line 1: Line 1:
==== Scriptlets ====
==== Scriptlets ====
The systemd package in Fedora 18+ provides a set of helper macros to handle systemd scriptlet operations. These macros are functionally equivalent to the manual scriptlets used in older versions of Fedora, but they also add support for systemd "presets", as documented here: https://fedoraproject.org/wiki/Features/PackagePresets
The systemd package provides a set of helper macros to handle systemd scriptlet operations. These macros support systemd "presets", as documented in [[Features/PackagePresets]].
Note that the %systemd_requires macro must not be used.
Note that the %systemd_requires macro must not be used.


Line 17: Line 17:


%postun
%postun
%systemd_postun_with_restart apache-httpd.service  
%systemd_postun_with_restart apache-httpd.service
</pre>
</pre>


Line 23: Line 23:
<pre>
<pre>
%postun
%postun
%systemd_postun
%systemd_postun apache-httpd.service
</pre>
</pre>


If your package includes one or more systemd units that need to be enabled by default on package installation, they '''must''' be covered by the [[Starting_services_by_default | Fedora preset policy]].
If your package includes one or more systemd units that need to be enabled by default on package installation, they '''must''' be covered by the [[Packaging:DefaultServices | Fedora preset policy]].


For details on what these macros evaluate to, refer to the following sources:<BR>
For details on what these macros evaluate to, refer to the following sources:<BR>
http://cgit.freedesktop.org/systemd/systemd/tree/src/core/macros.systemd.in<BR>
https://github.com/systemd/systemd/blob/master/src/core/macros.systemd.in,<br>
http://www.freedesktop.org/software/systemd/man/daemon.html
​https://github.com/systemd/systemd/blob/master/src/core/triggers.systemd.in and<BR>
http://www.freedesktop.org/software/systemd/man/daemon.html.


=== Packages migrating to a systemd unit file from a SysV initscript ===
=== Packages migrating to a systemd unit file from a SysV initscript ===

Revision as of 15:34, 21 January 2016

Scriptlets

The systemd package provides a set of helper macros to handle systemd scriptlet operations. These macros support systemd "presets", as documented in Features/PackagePresets. Note that the %systemd_requires macro must not be used.

Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
BuildRequires: systemd

[...]
%post
%systemd_post apache-httpd.service

%preun
%systemd_preun apache-httpd.service

%postun
%systemd_postun_with_restart apache-httpd.service

Some services do not support being restarted (e.g. D-Bus and various storage daemons). If your service should not be restarted upon upgrade, then use the following %post scriptlet instead of the one shown above:

%postun
%systemd_postun apache-httpd.service

If your package includes one or more systemd units that need to be enabled by default on package installation, they must be covered by the Fedora preset policy.

For details on what these macros evaluate to, refer to the following sources:
https://github.com/systemd/systemd/blob/master/src/core/macros.systemd.in,
https://github.com/systemd/systemd/blob/master/src/core/triggers.systemd.in and
http://www.freedesktop.org/software/systemd/man/daemon.html.

Packages migrating to a systemd unit file from a SysV initscript

When updating from a package containing a SysV initscript to a package containing a systemd unit file, we "start-over fresh" with default start and stop policy from the new package and do not migrate what the user had previously configured. For this reason, you can simply use the above scriptlets and not worry about converting the sysv information to something relevant to systemd.

Warning.png
Only migrate between releases
Packages are strictly forbidden from migrating to systemd within updates to a Fedora release because migration will reset the user's choices about whether to start or stop the service. Migration is only allowed between Fedora releases.