Home Wiki > openSUSE:Systemd packaging guidelines
Sign up | Login

openSUSE:Systemd packaging guidelines

tagline: From openSUSE

This article describe packaging guidelines for systemd services

Contents

RPM macros

Starting with openSUSE 12.1, several RPM macros must be used to package systemd services files

Build Requirement

You should add :

%if 0%{?suse_version} >= 1210
BuildRequires: systemd
%endif

as Build Requires.

Requires

Add

%{?systemd_requires}

to ensure the needed dependencies are added to your package

Service files

Service files should always be installed in %_unitdir (ie /lib/systemd/system) and never in /etc/systemd/system (so they can be overriden by users without conflicting with packaging).

Register services in install scripts

add the following macros to your scripts :

if foo.service bar.service are two systemd services you are installing :

%pre
%service_add_pre foo.service bar.service

%post
%service_add_post foo.service bar.service

%preun
%service_del_preun foo.service bar.service

%postun
%service_del_postun foo.service bar.service

If your package is also providing sysv initscripts, those macros will handle sysv initscripts migration transparently (as long as initscripts and systemd services have similar names)

If your package is supposed to build for openSUSE older than 12.1, you should use condition test for those macros.

Enabling service

By default, services are not enabled when package is installed. If you want your service to be enabled by default, you should do a submit request (with OBS) on systemd-presets-branding-openSUSE package, modifying default-openSUSE.preset file by adding :

enable your_service_name.service

Creating files / subdirectories in /var/run and /run

Since openSUSE 12.2, /var/run (which is either bind mounted or symlinked to /run ) are mounted as tmpfs, so packages should not contain any directories (or files) under /var/run (or /run), since they will disappear at the next reboot.

If new files / directories need to be created there, you should package a tmpfiles.d file (see man tmpfiles.d for the syntax), installed in /usr/lib/tmpfiles.d/. One example of such a file:

# create a directory with permissions 0770 owned by user foo and group bar
d /var/run/my_new_directory 0770 foo bar

You should install them in %install section like this:

%{__install} -d -m 0755 %{buildroot}/usr/lib/tmpfiles.d/
%{__install} -m 0644 %{SOURCE4} %{buildroot}/usr/lib/tmpfiles.d/%{name}.conf

If you expect this file / directory to be available after package installation (and before reboot), remember to add in your package %post :

systemd-tmpfiles --create /usr/lib/tmpfiles.d/<file_name>