wlgb 3.9 KB

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