From Fedora Project Wiki
(Created page with "=== Systemd === Packages containing systemd unit files need to use scriptlets to ensure proper handling of those services. Services can either be enabled or disabled by defau...")
 
No edit summary
Line 1: Line 1:
=== Systemd ===
Packages containing systemd unit files need to use scriptlets to ensure proper handling of those services. Services can either be enabled or disabled by default. To determine which case your specific service falls into, please refer to FESCo's policy here: [[Packaging:DefaultServices]]. On upgrade, a package may only restart a service if it is running; it may not start it if it is off.  Also, the service may not enable itself if it is currently disabled.
==== New Packages ====
{{admon/note|What is a new package?|In this context, a new package is a package which has never included a SysV initscript.}}
==== Scriptlets ====
==== 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]].  The <code>%systemd_requires</code> macro is a shortcut for listing the per-scriptlet dependencies on systemd.
The systemd package provides a set of helper macros to handle systemd scriptlet operations. These macros support systemd "presets", as documented in [[Features/PackagePresets]].  The <code>%systemd_requires</code> macro is a shortcut for listing the per-scriptlet dependencies on systemd.
Line 29: Line 22:
</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 [[Packaging:DefaultServices | 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]].
 
===== User units =====
 
There are additional macros for user units (those installed under <code>%_userunitdir</code>) that should be used similarly to those for system units.  These enable and disable user units according to presets, and are <code>%systemd_user_post</code> (to be used in <code>%post</code>) and <code>%systemd_user_preun</code> (to be used in <code>%preun</code>).
 
<pre>
%{?systemd_requires}
BuildRequires: systemd
 
[...]
%post
%systemd_user_post %{name}.service
 
%preun
%systemd_user_preun %{name}.service
</pre>
 
===== Macro details =====


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>

Revision as of 16:46, 27 October 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. The %systemd_requires macro is a shortcut for listing the per-scriptlet dependencies on systemd.

%{?systemd_requires}
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 %postun 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.

User units

There are additional macros for user units (those installed under %_userunitdir) that should be used similarly to those for system units. These enable and disable user units according to presets, and are %systemd_user_post (to be used in %post) and %systemd_user_preun (to be used in %preun).

%{?systemd_requires}
BuildRequires: systemd

[...]
%post
%systemd_user_post %{name}.service

%preun
%systemd_user_preun %{name}.service
Macro details

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.