Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; systemd system service example
- ; See also https://pastebin.com/uqY2DcGs for a user service example.
- ;
- ; Save as this file: /etc/systemd/system/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 system
- ; services (see: systemctl 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:
- ; sudo systemctl daemon-reload
- ;
- ; Start your service right now:
- ; sudo systemctl start my-service.service
- ;
- ; If that works, enable your service to start at boot:
- ; sudo systemctl enable my-service.service
- ;
- ;
- ; Follow log output related to your service (use control-C to exit):
- ; journalctl --follow --unit=my-service.service
- ; which you can also abbreviate to:
- ; journalctl -f -u my-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
- ;
- ; For a list of special targets that may be useful as dependencies or
- ; for ordering constraints, see:
- ; man systemd.special
- ;
- ; 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 system service
- ; It may be necessary to include dependencies to prevent the script from
- ; running too early during boot.
- ; For example, if you need networking, you probably want:
- Wants=network-online.target
- After=network-online.target
- ; If you need stuff in /dev, you probably want:
- Wants=systemd-udev-settle.service
- After=systemd-udev-settle.service
- [Install]
- ; When enabled, start service at boot
- WantedBy=multi-user.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
- ; By default the service runs as root, but you can choose a different user:
- User=debian
- ; By default the service runs in /, but you can choose a different working dir:
- WorkingDirectory=/home/debian
- ; Program to run (absolute path required):
- ExecStart=/home/debian/my-service.sh
Advertisement
Add Comment
Please, Sign In to add comment