Advertisement
Guest User

Untitled

a guest
Sep 27th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # supervisord This scripts turns supervisord on
  4. #
  5. # Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
  6. # Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,
  7. # use supervisord tools to start/stop, conditionally wait
  8. # for child processes to shutdown, and startup later
  9. # Mikhail Mingalev <mingalevme@gmail.com> Merged
  10. # redhat-init-jkoppe and redhat-sysconfig-jkoppe, and
  11. # made the script "simple customizable".
  12. # Brendan Maguire <maguire.brendan@gmail.com> Added OPTIONS to
  13. # SUPERVISORCTL status call
  14. #
  15. # chkconfig: 345 83 04
  16. #
  17. # description: supervisor is a process control utility. It has a web based
  18. # xmlrpc interface as well as a few other nifty features.
  19. # Script was originally written by Jason Koppe <jkoppe@indeed.com>.
  20. #
  21.  
  22. # source function library
  23. . /etc/rc.d/init.d/functions
  24.  
  25. set -a
  26.  
  27. PREFIX=/usr
  28.  
  29. SUPERVISORD=$PREFIX/bin/supervisord
  30. SUPERVISORCTL=$PREFIX/bin/supervisorctl
  31.  
  32. PIDFILE=/var/run/supervisord.pid
  33. LOCKFILE=/var/lock/subsys/supervisord
  34.  
  35. OPTIONS="-c /etc/supervisord.conf"
  36.  
  37. # unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock
  38. WAIT_FOR_SUBPROCESSES=yes
  39.  
  40. # remove this if you manage number of open files in some other fashion
  41. ulimit -n 96000
  42.  
  43. RETVAL=0
  44.  
  45.  
  46. running_pid()
  47. {
  48. # Check if a given process pid's cmdline matches a given name
  49. pid=$1
  50. name=$2
  51. [ -z "$pid" ] && return 1
  52. [ ! -d /proc/$pid ] && return 1
  53. (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
  54. return 0
  55. }
  56.  
  57. running()
  58. {
  59. # Check if the process is running looking at /proc
  60. # (works for all users)
  61.  
  62. # No pidfile, probably no daemon present
  63. [ ! -f "$PIDFILE" ] && return 1
  64. # Obtain the pid and check it against the binary name
  65. pid=`cat $PIDFILE`
  66. running_pid $pid $SUPERVISORD || return 1
  67. return 0
  68. }
  69.  
  70. start() {
  71. echo "Starting supervisord: "
  72.  
  73. if [ -e $PIDFILE ]; then
  74. echo "ALREADY STARTED"
  75. return 1
  76. fi
  77.  
  78. # start supervisord with options from sysconfig (stuff like -c)
  79. $SUPERVISORD $OPTIONS
  80.  
  81. # show initial startup status
  82. $SUPERVISORCTL $OPTIONS status
  83.  
  84. # only create the subsyslock if we created the PIDFILE
  85. [ -e $PIDFILE ] && touch $LOCKFILE
  86. }
  87.  
  88. stop() {
  89. echo -n "Stopping supervisord: "
  90. $SUPERVISORCTL $OPTIONS shutdown
  91. if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
  92. echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
  93. for sleep in 2 2 2 2 4 4 4 4 8 8 8 8 last; do
  94. if [ ! -e $PIDFILE ] ; then
  95. echo "Supervisord exited as expected in under $total_sleep seconds"
  96. break
  97. else
  98. if [[ $sleep -eq "last" ]] ; then
  99. echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
  100. return 1
  101. else
  102. sleep $sleep
  103. total_sleep=$(( $total_sleep + $sleep ))
  104. fi
  105.  
  106. fi
  107. done
  108. fi
  109.  
  110. # always remove the subsys. We might have waited a while, but just remove it at this point.
  111. rm -f $LOCKFILE
  112. }
  113.  
  114. restart() {
  115. stop
  116. start
  117. }
  118.  
  119. case "$1" in
  120. start)
  121. start
  122. RETVAL=$?
  123. ;;
  124. stop)
  125. stop
  126. RETVAL=$?
  127. ;;
  128. restart|force-reload)
  129. restart
  130. RETVAL=$?
  131. ;;
  132. reload)
  133. $SUPERVISORCTL $OPTIONS reload
  134. RETVAL=$?
  135. ;;
  136. condrestart)
  137. [ -f $LOCKFILE ] && restart
  138. RETVAL=$?
  139. ;;
  140. status)
  141. $SUPERVISORCTL $OPTIONS status
  142. if running ; then
  143. RETVAL=0
  144. else
  145. RETVAL=1
  146. fi
  147. ;;
  148. *)
  149. echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
  150. exit 1
  151. esac
  152.  
  153. exit $RETVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement