User Tools

Site Tools


wiki:systemd_user_service

This is an old revision of the document!


systemd user service

1. Create user service in user's home directory ex. /home/debian/.config/systemd/user/

Example:

[Unit]
Description=my npm app
After=network.target

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/home/debian/mynpmapp/

[Install]
WantedBy=default.target

2. From root enable lingering so that it persists over reboots and logouts

loginctl enable-linger username

3. Use systemctl –user start|stop <servicename> to run service

TROUBLESHOOTING

systemd --user does not work: 'Failed to connect to bus'

apt install dbus-user-session

In .bashrc of the user put:

export XDG_RUNTIME_DIR=/run/user/$(id -u)
export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"

then logout and login again.

Tested on

  • Debian 10

See also

References

wiki/systemd_user_service.1624970778.txt.gz · Last modified: 2021/06/29 14:46 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki