etherpad.initd.j2 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: etherpad-lite
  4. # Required-Start: $local_fs $remote_fs $network $syslog
  5. # Required-Stop: $local_fs $remote_fs $network $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: starts etherpad lite
  9. # Description: starts etherpad lite using start-stop-daemon
  10. ### END INIT INFO
  11. PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin"
  12. LOGFILE="/srv/etherpad/etherpad/etherpad-lite.log"
  13. EPLITE_DIR="/srv/etherpad/etherpad"
  14. EPLITE_BIN="bin/safeRun.sh"
  15. USER="etherpad"
  16. GROUP="etherpad"
  17. DESC="Etherpad Lite"
  18. NAME="etherpad-lite"
  19. set -e
  20. . /lib/lsb/init-functions
  21. start() {
  22. echo "Starting $DESC... "
  23. start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true
  24. echo "done"
  25. }
  26. #We need this function to ensure the whole process tree will be killed
  27. killtree() {
  28. local _pid=$1
  29. local _sig=${2-TERM}
  30. for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
  31. killtree ${_child} ${_sig}
  32. done
  33. kill -${_sig} ${_pid}
  34. }
  35. stop() {
  36. echo "Stopping $DESC... "
  37. while test -d /proc/$(cat /var/run/$NAME.pid); do
  38. killtree $(cat /var/run/$NAME.pid) 15
  39. sleep 0.5
  40. done
  41. rm /var/run/$NAME.pid
  42. echo "done"
  43. }
  44. status() {
  45. status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $?
  46. }
  47. case "$1" in
  48. start)
  49. start
  50. ;;
  51. stop)
  52. stop
  53. ;;
  54. restart)
  55. stop
  56. start
  57. ;;
  58. status)
  59. status
  60. ;;
  61. *)
  62. echo "Usage: $NAME {start|stop|restart|status}" >&2
  63. exit 1
  64. ;;
  65. esac
  66. exit 0