summaryrefslogtreecommitdiff
path: root/system/supervisor/rc.supervisord
blob: 0bff1cca2748d3c609fa1d2ece31e95443e68646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
# /etc/rc.d/rc.supervisord
#
# AUTHOR: Josh Jaques <jjaques@gmail.com>
#
# Start/stop/restart supervisor in slackware.
#
# To make Supervisor start automatically at boot, make this
# file executable:  chmod 755 /etc/rc.d/rc.supervisord

# Time to wait between stop/start on a restart
SHUTDOWN_TIME=5

# Time to wait after a start before reporting success/fail
STARTUP_TIME=1

# Location of the pid file
PIDFILE=/var/run/supervisord.pid

# Config of supervisor
CONFIG=/etc/supervisord.conf

# Daemon to start
DAEMON=supervisord

supervisord_start()
{
    $DAEMON -c $CONFIG -j $PIDFILE
}


supervisord_status()
{
    if [ -f $PIDFILE ]
    then
        pgrep $DAEMON | grep -f $PIDFILE > /dev/null 2>/dev/null
        if [ $? -eq 0 ]
        then
            return 0
        else
            return 1
        fi
    else
        return 1
    fi
}


supervisord_stop()
{
    kill $(cat $PIDFILE)
}

case "$1" in
  'start')
      echo -n "Starting..."
      supervisord_start
      sleep $STARTUP_TIME
      supervisord_status && echo "DONE [PID: $(cat $PIDFILE)]" || echo "ERROR"
  ;;

  'status')
      supervisord_status && echo "RUNNING [PID: $(cat $PIDFILE)]" || echo "STOPPED"
  ;;


  'stop')
      supervisord_status && {
        echo -n "Stopping $(cat $PIDFILE)..."
        supervisord_stop
        sleep $SHUTDOWN_TIME
        supervisord_status && echo "Failed" || echo "Success"
      } || {
        echo "Not Running..."
        exit 1
    }
  ;;

  'restart')
      supervisord_status && {
        echo -n "Stopping $(cat $PIDFILE)..."
        supervisord_stop
        sleep $SHUTDOWN_TIME
        supervisord_status && {
            echo "Failed"
            exit 1
        } || {
            echo "Success"
        }
      } || {
        echo "Not Running..."
        exit 1
      }
      echo -n "Starting..."
      supervisord_start
      sleep $STARTUP_TIME
      supervisord_status && echo "DONE [PID: $(cat $PIDFILE)]" || echo "ERROR"
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
  ;;
esac