aboutsummaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-support/salt/files/salt-master
blob: b534b363282d924905d034703e867486945b1e47 (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
104
105
106
107
108
109
110
111
#!/bin/sh
### BEGIN INIT INFO
# Provides:          salt-master
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: salt master control daemon
# Description:       This is a daemon that controls the salt minions
### END INIT INFO

# Author: Michael Prokop <mika@debian.org>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="salt master control daemon"
NAME=salt-master
DAEMON=/usr/bin/salt-master
DAEMON_ARGS="-d"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Source function library.
. /etc/init.d/functions

do_start() {
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    pid=$(pidof -x  $DAEMON)
    if [ -n "$pid" ] ; then
        return 1
    fi

    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
            $DAEMON_ARGS \
            || return 2
}

do_stop() {
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    rm -f $PIDFILE
    return "$RETVAL"
}

case "$1" in
    start)
        [ "$VERBOSE" != no ] && echo "Starting $DESC" "$NAME"
        do_start
        case "$?" in
            0|1) [ "$VERBOSE" != no ] && echo OK ;;
              2) [ "$VERBOSE" != no ] && echo FAILED ;;
        esac
        ;;
    stop)
        [ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
            0|1) [ "$VERBOSE" != no ] && echo OK ;;
              2) [ "$VERBOSE" != no ] && echo FAILED ;;
        esac
        ;;
    status)
        pid=`pidof -x $DAEMON`
        if [ -n "$pid" ]; then
	    echo "$NAME (pid $pid) is running ..."
	else
	    echo "$NAME is stopped"
	fi
        ;;
    #reload)
        # not implemented
        #;;
    restart|force-reload)
        echo "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
              do_start
              case "$?" in
                  0) echo OK ;;
                  1) echo FAILED ;; # Old process is still running
                  *) echo FAILED ;; # Failed to start
              esac
              ;;
          *)
              # Failed to stop
              echo FAILED
              ;;
        esac
        ;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
        exit 3
        ;;
esac

exit 0