supervisor 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: supervisord-initscript
  4. # Required-Start: $remote_fs $syslog $postgresql $rabbitmq-server
  5. # Required-Stop: $remote_fs $syslog
  6. # Should-Start: $nginx
  7. # Default-Start: 30 2 3 4 5
  8. # Default-Stop: 70 0 1 6
  9. # Short-Description: supervisord for KarmaWorld within a virtualenv
  10. # Description: supervisord for KarmaWorld within a virtualenv
  11. ### END INIT INFO
  12. # Modified by Bryan Bonvallet for FinalsClub Foundation
  13. # Original Author: Nicolas Kuttler
  14. # Original Script:
  15. # http://kuttler.eu/code/debian-init-script-virtualenv-gunicorn-django/
  16. #
  17. # Enable with update-rc.d gunicorn-example start 30 2 3 4 5 . stop 70 0 1 6 .
  18. # (parameters might not be necessary, test)
  19. # Do NOT "set -e"
  20. PROJECT=/var/www/karmaworld
  21. VIRTUALENV=$PROJECT/venv
  22. CONF=$PROJECT/confs/prod/supervisord.conf
  23. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  24. PATH=/bin:/usr/bin
  25. USER=vagrant
  26. GROUP=vagrant
  27. # I am lazy and just call the init script gunicorn-project
  28. NAME=`basename $0`
  29. DESC=$NAME
  30. PIDFILE=$PROJECT/var/run/$NAME.pid
  31. CMD="supervisord -c $CONF"
  32. # Load the VERBOSE setting and other rcS variables
  33. . /lib/init/vars.sh
  34. # Define LSB log_* functions.
  35. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  36. # and status_of_proc is working.
  37. . /lib/lsb/init-functions
  38. #
  39. # Function that starts the daemon/service
  40. #
  41. do_start() {
  42. # Return
  43. # 0 if daemon has been started
  44. # 1 if daemon was already running
  45. # 2 if daemon could not be started
  46. if [ -e $PIDFILE ]; then
  47. return 1
  48. fi
  49. cd $PROJECT
  50. . $VIRTUALENV/bin/activate
  51. $CMD
  52. if [ $? = 0 ]; then
  53. return 0
  54. else
  55. return 2
  56. fi
  57. }
  58. #
  59. # Function that stops the daemon/service
  60. #
  61. do_stop() {
  62. # Return
  63. # 0 if daemon has been stopped
  64. # 1 if daemon was already stopped
  65. # 2 if daemon could not be stopped
  66. # other if a failure occurred
  67. if [ -f $PIDFILE ]; then
  68. PID=`cat $PIDFILE`
  69. rm $PIDFILE
  70. kill -15 $PID
  71. if [ $? = 0 ]; then
  72. return 0
  73. else
  74. return 2
  75. fi
  76. else
  77. return 1
  78. fi
  79. }
  80. do_reload() {
  81. if [ -f $PIDFILE ]; then
  82. PID=`cat $PIDFILE`
  83. kill -HUP $PID
  84. return $?
  85. fi
  86. return 2
  87. }
  88. case "$1" in
  89. start)
  90. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  91. do_start
  92. case "$?" in
  93. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  94. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  95. esac
  96. ;;
  97. stop)
  98. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  99. do_stop
  100. case "$?" in
  101. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  102. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  103. esac
  104. ;;
  105. restart)
  106. log_daemon_msg "Restarting $DESC" "$NAME"
  107. do_stop
  108. case "$?" in
  109. 0|1)
  110. do_start
  111. case "$?" in
  112. 0) log_end_msg 0 ;;
  113. 1) log_end_msg 1 ;; # Old process is still running
  114. *) log_end_msg 1 ;; # Failed to start
  115. esac
  116. ;;
  117. *)
  118. # Failed to stop
  119. log_end_msg 1
  120. ;;
  121. esac
  122. ;;
  123. reload)
  124. log_daemon_msg "Reloading $DESC" "$NAME"
  125. do_reload
  126. case "$?" in
  127. 0) log_end_msg 0 ;;
  128. *) log_end_msg 1 ;;
  129. esac
  130. ;;
  131. *)
  132. echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
  133. exit 3
  134. ;;
  135. esac
  136. :