Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; systemd user service example
- ; See also https://pastebin.com/KXVdTNrL for a system service example.
- ;
- ; Make sure the directory exists (you only need to do this once):
- ; mkdir -p ~/.config/systemd/user
- ;
- ; Save this file as: ~/.config/systemd/user/my-service.service
- ;
- ; You can use any name instead of "my-service" of course (but then also adjust that
- ; in the commands below), as long as it doesn't conflict with any existing user
- ; services (see: systemctl --user list-unit-files '*.service').
- ;
- ; The file must have a ".service" suffix but you may omit that suffix in the various
- ; commands below, i.e. you can write "my-service" instead of "my-service.service".
- ; You cannot omit the suffix for other types of units (e.g. .timer or .path).
- ;
- ; Then, tell systemd to reload its configuration:
- ; systemctl --user daemon-reload
- ;
- ; Start your service right now:
- ; systemctl --user start my-service.service
- ;
- ; Check on the status of your service:
- ; systemctl --user status my-service.service
- ;
- ; If that works, enable your service to start automatically:
- ; systemctl --user enable my-service.service
- ;
- ; Make sure the systemd user instance for the "debian" user is started at boot,
- ; otherwise your service(s) will only run when you're logged in:
- ; sudo loginctl enable-linger debian
- ; (you only need to do this once)
- ;
- ;
- ; Follow log output related to your service (use control-C to exit):
- ; journalctl -f --user-unit=my-service.service
- ;
- ;
- ; For detailed information about the directives available in the [Unit]
- ; and [Install] sections of systemd units in general, see:
- ; man systemd.unit
- ;
- ; For directives available in the [Service] section of service units, see:
- ; man systemd.service
- ; man systemd.exec
- ; man systemd.resource-control
- ;
- ; Note that comment lines can either start with ; or with #. Using # is
- ; more common, but pastebin's syntax highlighting doesn't recognize # but
- ; only ; hence that's what I used.
- [Unit]
- Description=My user service
- [Install]
- ; When enabled, start service at startup
- WantedBy=default.target
- [Service]
- ; To create a service that remains running (most common), use:
- Type=simple
- ; or
- ;Type=exec
- ; The latter is better for diagnostics since if the program fails to start (e.g.
- ; the path in ExecStart is wrong) then with Type=exec the service will fail to
- ; start while with Type=simple the service will initially seem to start but then
- ; fail immediately afterwards. However, Type=exec is unavailable in older versions
- ; of systemd (e.g. if you're still using debian stretch) and Type=simple is also
- ; slightly more efficient than Type=exec
- ;
- ; If your program instead just does some setup and then exits, use:
- ;Type=oneshot
- ; and in this case you probably also want to set:
- ;RemainAfterExit=yes
- ; (see the systemd.service man page for more details on these options)
- ; By default the service runs in ~, but you can choose a different working dir:
- ;WorkingDirectory=~
- ; Program to run (absolute path required):
- ExecStart=/home/debian/my-service.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement