etherpad-lite.sysvinit.j2 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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="/var/log/etherpad-lite/etherpad-lite.log"
  13. EPLITE_DIR="{{ etherpad_path }}"
  14. EPLITE_BIN="bin/safeRun.sh"
  15. USER="{{ etherpad_user }}"
  16. GROUP="{{ etherpad_group }}"
  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. if test -f /var/run/$NAME.pid; then
  38. while test -d /proc/$(cat /var/run/$NAME.pid); do
  39. killtree $(cat /var/run/$NAME.pid) 15
  40. sleep 0.5
  41. done
  42. rm /var/run/$NAME.pid
  43. fi
  44. echo "done"
  45. }
  46. status() {
  47. status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $?
  48. }
  49. case "$1" in
  50. start)
  51. start
  52. ;;
  53. stop)
  54. stop
  55. ;;
  56. restart)
  57. stop
  58. start
  59. ;;
  60. status)
  61. status
  62. ;;
  63. *)
  64. echo "Usage: $NAME {start|stop|restart|status}" >&2
  65. exit 1
  66. ;;
  67. esac
  68. exit 0