wlgb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 \
  50. --exec /usr/bin/env LANG="C.UTF-8" $DAEMON -- \
  51. $DAEMON_ARGS >> /var/log/wlgb/out.log 2>> /var/log/wlgb/err.log &
  52. echo "WriteLatex-Git Bridge started."
  53. echo "Config file at /etc/wlgb/config.json"
  54. echo "Log file at /var/log/wlgb/out.log"
  55. echo "Error file at /var/log/wlgb/err.log"
  56. echo
  57. return 0
  58. # Add code here, if necessary, that waits for the process to be ready
  59. # to handle requests from services started subsequently which depend
  60. # on this one. As a last resort, sleep for some time.
  61. }
  62. #
  63. # Function that stops the daemon/service
  64. #
  65. do_stop()
  66. {
  67. if [ -f "$PIDFILE" ]; then
  68. echo "Stopping Writelatex-Git Bridge..."
  69. start-stop-daemon --stop --quiet --retry=TERM/60/KILL/5 --pidfile $PIDFILE
  70. # Many daemons don't delete their pidfiles when they exit.
  71. rm -f $PIDFILE
  72. echo "WriteLatex-Git Bridge stopped."
  73. return 0
  74. fi
  75. echo "WriteLatex-Git Bridge is not started: use service wlgb start to start."
  76. return 1
  77. }
  78. #
  79. # Function that sends a SIGHUP to the daemon/service
  80. #
  81. do_reload() {
  82. #
  83. # If the daemon can reload its configuration without
  84. # restarting (for example, when it is sent a SIGHUP),
  85. # then implement that here.
  86. #
  87. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  88. return 0
  89. }
  90. case "$1" in
  91. start)
  92. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  93. do_start
  94. case "$?" in
  95. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  96. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  97. esac
  98. ;;
  99. stop)
  100. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  101. do_stop
  102. case "$?" in
  103. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  104. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  105. esac
  106. ;;
  107. status)
  108. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  109. ;;
  110. #reload|force-reload)
  111. #
  112. # If do_reload() is not implemented then leave this commented out
  113. # and leave 'force-reload' as an alias for 'restart'.
  114. #
  115. #log_daemon_msg "Reloading $DESC" "$NAME"
  116. #do_reload
  117. #log_end_msg $?
  118. #;;
  119. restart|force-reload)
  120. #
  121. # If the "reload" option is implemented then remove the
  122. # 'force-reload' alias
  123. #
  124. log_daemon_msg "Restarting $DESC" "$NAME"
  125. do_stop
  126. case "$?" in
  127. 0|1)
  128. do_start
  129. case "$?" in
  130. 0) log_end_msg 0 ;;
  131. 1) log_end_msg 1 ;; # Old process is still running
  132. *) log_end_msg 1 ;; # Failed to start
  133. esac
  134. ;;
  135. *)
  136. # Failed to stop
  137. log_end_msg 1
  138. ;;
  139. esac
  140. ;;
  141. *)
  142. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  143. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  144. exit 3
  145. ;;
  146. esac
  147. :