From ArchWiki
< Systemd
Revision as of 21:00, 9 November 2012 by Sudokode (Talk | contribs) (Initial write)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

systemd offers users the ability to run an instance of systemd to manage their session and services. This allows users to start, stop, enable, and disable units found within certain directories when systemd is run by the user. This is convenient for daemons and other services that are commonly run as a user other than root or a special user, such as mpd.



Users should first set up systemd-logind to manage their session. If systemd is running as the system init daemon, then this is already happening, but it is broken when X is launched in another tty. This can be fixed by putting the following in the user's ~/.xserverrc:

$ exec /usr/bin/X -nolisten tcp vt$XDG_VTNR "$@"

Next, the user must launch systemd by putting the following in their ~/.xinitrc before the exec line:

$ systemd --user &

After starting X, the user can check whether their session is now being managed by systemd-logind with the following command:

$ loginctl --no-pager show-session $XDG_SESSION_ID | grep Active

If this command prints Active=yes, then the user is now using systemd-logind to manage their session. The user should remove any instances of ck-launch-session or dbus-launch from their ~/.xinitrc, as those commands are unneeded.

Display Managers

All of the major display managers are now using systemd-logind by default, so the loginctl command from the previous section should work as stated. A user simply has to add systemd --user as a program to be started by their desktop environment.

User Services

Users may now interact with units located in the following directories just as they would with system services (ordered by ascending precedence):

  • /usr/lib/systemd/user/
  • /etc/systemd/user/
  • ~/.config/systemd/user/

To control the systemd instance, the user must use the command systemctl --user.

Installed by packages

A unit installed by a package that is meant to be run by a systemd user instance should install the unit to /usr/lib/systemd/user/. The system adminstration can then modify the unit by copying it to /etc/systemd/user/. A user can then modify the unit by copying it to ~/.config/systemd/user/.


The following is an example of a user version of mpd.service:

Description=Music Player Daemon

ExecStart=/usr/bin/mpd --nodaemon


Example with variables

The following is an example of a user version of sickbeard.service, which takes into account variable home directories where SickBeard can find certain files:

Description=SickBeard Daemon

ExecStart=/usr/bin/sickbeard --config %h/.sickbeard/config.ini --datadir %h/.sickbeard


As detailed in man systemd.unit, the %h variable is replaced by the home directory of the user running the service. There are other variables that can be taken into account in the systemd manpages.