wlgb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: wlgb
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: writelatex-git-bridge
  9. # Description: Init script for writelatex-git-bridge service
  10. # placed in /etc/init.d.
  11. ### END INIT INFO
  12. # Author: Winston Li <winston.li12@imperial.ac.uk>
  13. #
  14. # Please remove the "Author" lines above and replace them
  15. # with your own name if you copy and modify this script.
  16. # Do NOT "set -e"
  17. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  18. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  19. DESC="Writelatex-Git Bridge startup and stop script"
  20. NAME=wlgb
  21. DAEMON=/usr/bin/java
  22. DAEMON_ARGS="-jar /usr/local/sbin/writelatex-git-bridge.jar /etc/wlgb/config.json"
  23. PIDFILE=/var/run/$NAME.pid
  24. SCRIPTNAME=/etc/init.d/$NAME
  25. # Exit if the package is not installed
  26. [ -x "$DAEMON" ] || exit 0
  27. # Read configuration variable file if it is present
  28. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  29. # Load the VERBOSE setting and other rcS variables
  30. . /lib/init/vars.sh
  31. # Define LSB log_* functions.
  32. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  33. # and status_of_proc is working.
  34. . /lib/lsb/init-functions
  35. #
  36. # Function that starts the daemon/service
  37. #
  38. do_start()
  39. {
  40. # Return
  41. # 0 if daemon has been started
  42. # 1 if daemon was already running
  43. # 2 if daemon could not be started
  44. if [ -f "$PIDFILE" ]; then
  45. echo "WriteLatex-Git Bridge is already started: use service wlgb stop to stop."
  46. return 1;
  47. fi
  48. echo "Starting WriteLatex-Git Bridge..."
  49. start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
  50. $DAEMON_ARGS >> /var/log/wlgb/out.log 2>> /var/log/err.log &
  51. echo "WriteLatex-Git Bridge started."
  52. echo "Config file at /etc/wlgb/config.json"
  53. echo "Log file at /var/log/wlgb/out.log"
  54. echo "Error file at /var/log/wlgb/err.log"
  55. echo
  56. return 0
  57. # Add code here, if necessary, that waits for the process to be ready
  58. # to handle requests from services started subsequently which depend
  59. # on this one. As a last resort, sleep for some time.
  60. }
  61. #
  62. # Function that stops the daemon/service
  63. #
  64. do_stop()
  65. {
  66. if [ -f "$PIDFILE" ]; then
  67. echo "Stopping Writelatex-Git Bridge..."
  68. kill -9 `cat $PIDFILE`
  69. # Many daemons don't delete their pidfiles when they exit.
  70. rm -f $PIDFILE
  71. echo "WriteLatex-Git Bridge stopped."
  72. return 0
  73. fi
  74. echo "WriteLatex-Git Bridge is not started: use service wlgb start to start."
  75. return 1
  76. }
  77. #
  78. # Function that sends a SIGHUP to the daemon/service
  79. #
  80. do_reload() {
  81. #
  82. # If the daemon can reload its configuration without
  83. # restarting (for example, when it is sent a SIGHUP),
  84. # then implement that here.
  85. #
  86. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  87. return 0
  88. }
  89. case "$1" in
  90. start)
  91. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  92. do_start
  93. case "$?" in
  94. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  95. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  96. esac
  97. ;;
  98. stop)
  99. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  100. do_stop
  101. case "$?" in
  102. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  103. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  104. esac
  105. ;;
  106. status)
  107. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  108. ;;
  109. #reload|force-reload)
  110. #
  111. # If do_reload() is not implemented then leave this commented out
  112. # and leave 'force-reload' as an alias for 'restart'.
  113. #
  114. #log_daemon_msg "Reloading $DESC" "$NAME"
  115. #do_reload
  116. #log_end_msg $?
  117. #;;
  118. restart|force-reload)
  119. #
  120. # If the "reload" option is implemented then remove the
  121. # 'force-reload' alias
  122. #
  123. log_daemon_msg "Restarting $DESC" "$NAME"
  124. do_stop
  125. case "$?" in
  126. 0|1)
  127. do_start
  128. case "$?" in
  129. 0) log_end_msg 0 ;;
  130. 1) log_end_msg 1 ;; # Old process is still running
  131. *) log_end_msg 1 ;; # Failed to start
  132. esac
  133. ;;
  134. *)
  135. # Failed to stop
  136. log_end_msg 1
  137. ;;
  138. esac
  139. ;;
  140. *)
  141. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  142. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  143. exit 3
  144. ;;
  145. esac
  146. :