zmatt

my-service.service (system)

Dec 21st, 2018 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;; systemd system service example
  2. ; See also https://pastebin.com/uqY2DcGs for a user service example.
  3. ;
  4. ; Save as this file:  /etc/systemd/system/my-service.service
  5. ;
  6. ; You can use any name instead of "my-service" of course (but then also adjust that
  7. ; in the commands below), as long as it doesn't conflict with any existing system
  8. ; services (see: systemctl list-unit-files '*.service').
  9. ;
  10. ; The file must have a ".service" suffix but you may omit that suffix in the various
  11. ; commands below, i.e. you can write "my-service" instead of "my-service.service".
  12. ; You cannot omit the suffix for other types of units (e.g. .timer or .path).
  13. ;
  14. ; Then, tell systemd to reload its configuration:
  15. ;   sudo systemctl daemon-reload
  16. ;
  17. ; Start your service right now:
  18. ;   sudo systemctl start my-service.service
  19. ;
  20. ; If that works, enable your service to start at boot:
  21. ;   sudo systemctl enable my-service.service
  22. ;
  23. ;
  24. ; Follow log output related to your service (use control-C to exit):
  25. ;   journalctl --follow --unit=my-service.service
  26. ; which you can also abbreviate to:
  27. ;   journalctl -f -u my-service
  28. ;
  29. ;
  30. ; For detailed information about the directives available in the [Unit]
  31. ; and [Install] sections of systemd units in general, see:
  32. ;   man systemd.unit
  33. ;
  34. ; For directives available in the [Service] section of service units, see:
  35. ;   man systemd.service        
  36. ;   man systemd.exec
  37. ;   man systemd.resource-control
  38. ;
  39. ; For a list of special targets that may be useful as dependencies or
  40. ; for ordering constraints, see:
  41. ;   man systemd.special
  42. ;
  43. ; Note that comment lines can either start with ; or with #.  Using # is
  44. ; more common, but pastebin's syntax highlighting doesn't recognize # but
  45. ; only ; hence that's what I used.
  46.  
  47.  
  48. [Unit]
  49.  
  50. Description=My system service
  51.  
  52. ; It may be necessary to include dependencies to prevent the script from
  53. ; running too early during boot.
  54.  
  55. ; For example, if you need networking, you probably want:
  56. Wants=network-online.target
  57. After=network-online.target
  58.  
  59. ; If you need stuff in /dev, you probably want:
  60. Wants=systemd-udev-settle.service
  61. After=systemd-udev-settle.service
  62.  
  63.  
  64. [Install]
  65.  
  66. ; When enabled, start service at boot
  67. WantedBy=multi-user.target
  68.  
  69.  
  70. [Service]
  71.  
  72. ; To create a service that remains running (most common), use:
  73. Type=simple
  74. ;  or
  75. ;Type=exec
  76. ; The latter is better for diagnostics since if the program fails to start (e.g.
  77. ; the path in ExecStart is wrong) then with Type=exec the service will fail to
  78. ; start while with Type=simple the service will initially seem to start but then
  79. ; fail immediately afterwards.  However, Type=exec is unavailable in older versions
  80. ; of systemd (e.g. if you're still using debian stretch) and Type=simple is also
  81. ; slightly more efficient than Type=exec
  82.  
  83. ; By default the service runs as root, but you can choose a different user:
  84. User=debian
  85.  
  86. ; By default the service runs in /, but you can choose a different working dir:
  87. WorkingDirectory=/home/debian
  88.  
  89. ; Program to run (absolute path required):
  90. ExecStart=/home/debian/my-service.sh
Advertisement
Add Comment
Please, Sign In to add comment