Advertisement
zmatt

my-service.service (user)

Aug 2nd, 2019 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;; systemd user service example
  2. ; See also https://pastebin.com/KXVdTNrL for a system service example.
  3. ;
  4. ; Make sure the directory exists (you only need to do this once):
  5. ;   mkdir -p ~/.config/systemd/user
  6. ;
  7. ; Save this file as:  ~/.config/systemd/user/my-service.service
  8. ;
  9. ; You can use any name instead of "my-service" of course (but then also adjust that
  10. ; in the commands below), as long as it doesn't conflict with any existing user
  11. ; services (see: systemctl --user list-unit-files '*.service').
  12. ;
  13. ; The file must have a ".service" suffix but you may omit that suffix in the various
  14. ; commands below, i.e. you can write "my-service" instead of "my-service.service".
  15. ; You cannot omit the suffix for other types of units (e.g. .timer or .path).
  16. ;
  17. ; Then, tell systemd to reload its configuration:
  18. ;   systemctl --user daemon-reload
  19. ;
  20. ; Start your service right now:
  21. ;   systemctl --user start my-service.service
  22. ;
  23. ; Check on the status of your service:
  24. ;   systemctl --user status my-service.service
  25. ;
  26. ; If that works, enable your service to start automatically:
  27. ;   systemctl --user enable my-service.service
  28. ;
  29. ; Make sure the systemd user instance for the "debian" user is started at boot,
  30. ; otherwise your service(s) will only run when you're logged in:
  31. ;   sudo loginctl enable-linger debian
  32. ; (you only need to do this once)
  33. ;
  34. ;
  35. ; Follow log output related to your service (use control-C to exit):
  36. ;   journalctl -f --user-unit=my-service.service
  37. ;
  38. ;
  39. ; For detailed information about the directives available in the [Unit]
  40. ; and [Install] sections of systemd units in general, see:
  41. ;   man systemd.unit
  42. ;
  43. ; For directives available in the [Service] section of service units, see:
  44. ;   man systemd.service        
  45. ;   man systemd.exec
  46. ;   man systemd.resource-control
  47. ;
  48. ; Note that comment lines can either start with ; or with #.  Using # is
  49. ; more common, but pastebin's syntax highlighting doesn't recognize # but
  50. ; only ; hence that's what I used.
  51.  
  52.  
  53. [Unit]
  54.  
  55. Description=My user service
  56.  
  57.  
  58. [Install]
  59.  
  60. ; When enabled, start service at startup
  61. WantedBy=default.target
  62.  
  63.  
  64. [Service]
  65.  
  66. ; To create a service that remains running (most common), use:
  67. Type=simple
  68. ;  or
  69. ;Type=exec
  70. ; The latter is better for diagnostics since if the program fails to start (e.g.
  71. ; the path in ExecStart is wrong) then with Type=exec the service will fail to
  72. ; start while with Type=simple the service will initially seem to start but then
  73. ; fail immediately afterwards.  However, Type=exec is unavailable in older versions
  74. ; of systemd (e.g. if you're still using debian stretch) and Type=simple is also
  75. ; slightly more efficient than Type=exec
  76. ;
  77. ; If your program instead just does some setup and then exits, use:
  78. ;Type=oneshot
  79. ; and in this case you probably also want to set:
  80. ;RemainAfterExit=yes
  81. ; (see the systemd.service man page for more details on these options)
  82.  
  83. ; By default the service runs in ~, but you can choose a different working dir:
  84. ;WorkingDirectory=~
  85.  
  86. ; Program to run (absolute path required):
  87. ExecStart=/home/debian/my-service.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement