Difference between revisions of "Systemd/User"

From ArchWiki
Jump to: navigation, search
(Initial write)
 
m (Fixing page details)
Line 1: Line 1:
 +
{{Lowercase title}}
 +
[[Category:Daemons and system services]]
 +
[[Category:Boot process]]
 +
{{Article summary start}}
 +
{{Article summary text|Covers how to set up [[systemd]] user sessions.}}
 +
{{Article summary heading|Related}}
 +
{{Article summary wiki|systemd}}
 +
{{Article summary end}}
 +
 
[[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]].
 
[[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]].
  

Revision as of 21:05, 9 November 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary end

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.

Setup

startx

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/.

Example

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

[Unit]
Description=Music Player Daemon

[Service]
ExecStart=/usr/bin/mpd --nodaemon

[Install]
WantedBy=default.target

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:

[Unit]
Description=SickBeard Daemon

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

[Install]
WantedBy=default.target

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.