Systemd services for user in Linux
The traditional way of starting up program after user login, is using user profile. The systemd provides a new way for such tasks.
Usage
The systemd regular services are running as root privileges, unless User
value in Service
session. They are triggerred as background jobs, no matter user login or not. The systemd user services are running for user and run as that user id, and they are triggered after that user login.
Definition
To define services run as a normal user, they can be defined in user's home directory in ~/.config/systemd/user
folder, they will be picked up by systemd as a user service.
Managing
To manage these services, folowing commands can be used.
Check all systemd services for user
systemctl status --user
Enable and start up
systemctl --user enable myuser.service
systemctl --user start myuser.service
Reload all systemd configuration. It is required after service definition files modified.
systemctl --user daemon-reload
For all users
The /etc/systemd/user/
folder is to define services for all users. The default available user services definition files are in /usr/lib/systemd/user/
folder, they can be used to enable systemd user service. For example,
# ls /usr/lib/systemd/user/syncthing.service
syncthing.service
# systemctl --user status syncthing
Unit syncthing.service could not be found.
# systemctl status syncthing
* syncthing.service - Syncthing - Open Source Continuous File Synchronization
...
Other systemd user definition file locations can be defined by administrator
$XDG_RUNTIME_DIR/systemd/user/
~/.local/share/systemd/user/
Common usage
The most common usage of systemd user servers, are X window related processes, they need to be run after user login, running as background services for user, such as reminder, window manager, etc., but not the background services for system.
References
systemd user services and systemctl --user
What does "systemctl daemon-reload" do?