Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides: exampledaemon
  5. # Required-Start: $local_fs $network $syslog
  6. # Required-Stop: $local_fs $network $syslog
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Example
  10. # Description: Example start-stop-daemon - Debian
  11. ### END INIT INFO
  12.  
  13. NAME="my-service"
  14. PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
  15. APPDIR="/home/svc-user"
  16. APPBIN="/home/svc-user/my-binary"
  17. APPARGS=""
  18. USER="svc-user"
  19. GROUP="svc-user"
  20.  
  21. # Include functions
  22. set -e
  23. . /lib/lsb/init-functions
  24.  
  25. start() {
  26. printf "Starting '$NAME'... "
  27. start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS || true
  28. printf "donen"
  29. }
  30.  
  31. #We need this function to ensure the whole process tree will be killed
  32. killtree() {
  33. local _pid=$1
  34. local _sig=${2-TERM}
  35. for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
  36. killtree ${_child} ${_sig}
  37. done
  38. kill -${_sig} ${_pid}
  39. }
  40.  
  41. stop() {
  42. printf "Stopping '$NAME'... "
  43. [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] ||
  44. while test -d /proc/$(cat /var/run/$NAME.pid); do
  45. killtree $(cat /var/run/$NAME.pid) 15
  46. sleep 0.5
  47. done
  48. [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
  49. printf "donen"
  50. }
  51.  
  52. status() {
  53. status_of_proc -p /var/run/$NAME.pid "" $NAME && exit 0 || exit $?
  54. }
  55.  
  56. case "$1" in
  57. start)
  58. start
  59. ;;
  60. stop)
  61. stop
  62. ;;
  63. restart)
  64. stop
  65. start
  66. ;;
  67. status)
  68. status
  69. ;;
  70. *)
  71. echo "Usage: $NAME {start|stop|restart|status}" >&2
  72. exit 1
  73. ;;
  74. esac
  75.  
  76. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement