Ubuntu supervisor 启动脚本

2016年11月8日

此脚本主要是针对 pip   python 或者 easy_install  安装 的supervisor    ,  apt-get 安装的不需要会自动生成  ,其实这个就是apt-get 安装生成的。   不过注意一件事  pip   python 或者 easy_install  安装 的supervisor  在 /usr/local/bin  为了适应此脚本需要做一个软连接到  /usr/bin/

  1. root@167646:/etc/init.d# ln -s /usr/local/bin/supervisord /usr/bin/
  2. root@167646:/etc/init.d# ln -s /usr/local/bin/supervisorctl /usr/bin/

cat  /etc/init.d/supervisor

  1. #! /bin/sh
  2. #
  3. # skeleton      example file to build /etc/init.d/ scripts.
  4. #               This file should be used to construct scripts for /etc/init.d.
  5. #
  6. #               Written by Miquel van Smoorenburg <[email protected]>.
  7. #               Modified for Debian
  8. #               by Ian Murdock <[email protected]>.
  9. #               Further changes by Javier Fernandez-Sanguino <[email protected]>
  10. #
  11. # Version:      @(#)skeleton  1.9  26-Feb-2001  [email protected]
  12. #
  13. ### BEGIN INIT INFO
  14. # Provides:          supervisor
  15. # Required-Start:    $remote_fs $network $named
  16. # Required-Stop:     $remote_fs $network $named
  17. # Default-Start:     2 3 4 5
  18. # Default-Stop:      0 1 6
  19. # Short-Description: Start/stop supervisor
  20. # Description:       Start/stop supervisor daemon and its configured
  21. #                    subprocesses.
  22. ### END INIT INFO
  23. . /lib/lsb/init-functions
  24. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  25. DAEMON=/usr/bin/supervisord
  26. NAME=supervisord
  27. DESC=supervisor
  28. test -x $DAEMON || exit 0
  29. LOGDIR=/var/log/supervisor
  30. PIDFILE=/var/run/$NAME.pid
  31. DODTIME=5                   # Time to wait for the server to die, in seconds
  32.                             # If this value is set too low you might not
  33.                             # let some servers to die gracefully and
  34.                             # 'restart' will not work
  35. # Include supervisor defaults if available
  36. if [ -f /etc/default/supervisor ] ; then
  37.         . /etc/default/supervisor
  38. fi
  39. DAEMON_OPTS="-c /etc/supervisor/supervisord.conf $DAEMON_OPTS"
  40. set -e
  41. running_pid()
  42. {
  43.     # Check if a given process pid's cmdline matches a given name
  44.     pid=$1
  45.     name=$2
  46.     [ -z "$pid" ] && return 1
  47.     [ ! -d /proc/$pid ] &&  return 1
  48.     (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
  49.     return 0
  50. }
  51. running()
  52. {
  53. # Check if the process is running looking at /proc
  54. # (works for all users)
  55.     # No pidfile, probably no daemon present
  56.     [ ! -f "$PIDFILE" ] && return 1
  57.     # Obtain the pid and check it against the binary name
  58.     pid=`cat $PIDFILE`
  59.     running_pid $pid $DAEMON || return 1
  60.     return 0
  61. }
  62. force_stop() {
  63. # Forcefully kill the process
  64.     [ ! -f "$PIDFILE" ] && return
  65.     if running ; then
  66.         kill -15 $pid
  67.         # Is it really dead?
  68.         [ -n "$DODTIME" ] && sleep "$DODTIME"s
  69.         if running ; then
  70.             kill -9 $pid
  71.             [ -n "$DODTIME" ] && sleep "$DODTIME"s
  72.             if running ; then
  73.                 echo "Cannot kill $NAME (pid=$pid)!"
  74.                 exit 1
  75.             fi
  76.         fi
  77.     fi
  78.     rm -f $PIDFILE
  79.     return 0
  80. }
  81. case "$1" in
  82.   start)
  83.         echo -n "Starting $DESC: "
  84.         start-stop-daemon --start --quiet --pidfile $PIDFILE \
  85.                 --startas $DAEMON -- $DAEMON_OPTS
  86.         test -f $PIDFILE || sleep 1
  87.         if running ; then
  88.             echo "$NAME."
  89.         else
  90.             echo " ERROR."
  91.         fi
  92.         ;;
  93.   stop)
  94.         echo -n "Stopping $DESC: "
  95.         start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
  96.         echo "$NAME."
  97.         ;;
  98.   force-stop)
  99.         echo -n "Forcefully stopping $DESC: "
  100.         force_stop
  101.         if ! running ; then
  102.             echo "$NAME."
  103.         else
  104.             echo " ERROR."
  105.         fi
  106.         ;;
  107.   #reload)
  108.         #
  109.         #       If the daemon can reload its config files on the fly
  110.         #       for example by sending it SIGHUP, do it here.
  111.         #
  112.         #       If the daemon responds to changes in its config file
  113.         #       directly anyway, make this a do-nothing entry.
  114.         #
  115.         # echo "Reloading $DESC configuration files."
  116.         # start-stop-daemon --stop --signal 1 --quiet --pidfile \
  117.         #       /var/run/$NAME.pid --exec $DAEMON
  118.   #;;
  119.   force-reload)
  120.         #
  121.         #       If the "reload" option is implemented, move the "force-reload"
  122.         #       option to the "reload" entry above. If not, "force-reload" is
  123.         #       just the same as "restart" except that it does nothing if the
  124.         #   daemon isn't already running.
  125.         # check wether $DAEMON is running. If so, restart
  126.         start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
  127.         --startas $DAEMON \
  128.         && $0 restart \
  129.         || exit 0
  130.         ;;
  131.   restart)
  132.     echo -n "Restarting $DESC: "
  133.     start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
  134.         [ -n "$DODTIME" ] && sleep $DODTIME
  135.         start-stop-daemon --start --quiet --pidfile $PIDFILE \
  136.                 --startas $DAEMON -- $DAEMON_OPTS
  137.         echo "$NAME."
  138.         ;;
  139.   status)
  140.     echo -n "$NAME is "
  141.     if running ;  then
  142.         echo "running"
  143.     else
  144.         echo " not running."
  145.         exit 1
  146.     fi
  147.     ;;
  148.   *)
  149.         N=/etc/init.d/$NAME
  150.         # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  151.         echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
  152.         exit 1
  153.         ;;
  154. esac
  155. exit 0

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注