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