Advertisement
Guest User

Untitled

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