Statistics
| Branch: | Tag: | Revision:

root / snf-ganeti-tools / conf / init.d / snf-ganeti-eventd @ 98340727

History | View | Annotate | Download (3.5 kB)

1
#! /bin/sh
2

    
3
### BEGIN INIT INFO
4
# Provides:          snf-ganeti-eventd
5
# Required-Start:    $remote_fs $syslog ganeti
6
# Required-Stop:     $remote_fs $syslog 
7
# Default-Start:     2 3 4 5
8
# Default-Stop:      0 1 6
9
# X-Start-After:	 ganeti
10
# Short-Description: Synnefo ganeti-eventd daemon
11
# Description:       ganeti-eventd is a daemon 
12
### END INIT INFO
13

    
14
set -e
15

    
16
# /etc/init.d/snf-ganeti-eventd: start and stop the ganeti-eventd daemon
17
# script skeleton stolen from rsyncd
18

    
19

    
20
DAEMON=/usr/sbin/snf-ganeti-eventd
21
SNF_EVENTD_PID_FILE=/var/run/snf-ganeti-eventd.pid
22
SNF_EVENTD_DEFAULTS=/etc/default/snf-ganeti-eventd
23
SNF_EVENTD_OPTS=''
24
SNF_EVENTD_ENABLE=true
25
SNF_USER="root"
26

    
27
test -x $DAEMON || exit 0
28

    
29
. /lib/lsb/init-functions
30

    
31
if [ -s $SNF_EVENTD_DEFAULTS_FILE ]; then
32
    . $SNF_EVENTD_DEFAULTS_FILE
33
fi
34

    
35
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
36

    
37
eventd_start() {
38
    if start-stop-daemon --start --chuid $SNF_USER --pidfile $SNF_EVENTD_PID_FILE \
39
		--exec $DAEMON -- $SNF_EVENTD_OPTS
40
    then
41
        rc=0
42
        sleep 1
43
        if ! kill -0 $(cat $SNF_EVENTD_PID_FILE) >/dev/null 2>&1; then
44
            log_failure_msg "snf-ganeti-eventd daemon failed to start"
45
            rc=1
46
        fi
47
    else
48
        rc=1
49
    fi
50
    if [ $rc -eq 0 ]; then
51
        log_end_msg 0
52
    else
53
        log_end_msg 1
54
        rm -f $SNF_EVENTD_PID_FILE
55
    fi
56
} # eventd_start
57

    
58
MASTER=`/usr/sbin/gnt-cluster getmaster`
59
HOST=`/bin/hostname -f`
60

    
61
case "$1" in
62
  start)
63
	if [ "x$MASTER" != x$HOST ] ; then
64
	    log_warning_msg "snf-ganeti-eventd should run on the ganeti master only, aborting"
65
	    log_end_msg 0
66
	    exit 0
67
	fi
68

    
69
        if "$SNF_EVENTD_ENABLE"; then
70
            log_daemon_msg "Starting snf-ganeti-eventd daemon" "snf-ganeti-eventd"
71
            if [ -s $SNF_EVENTD_PID_FILE ] && kill -0 $(cat $SNF_EVENTD_PID_FILE) >/dev/null 2>&1; then
72
                log_progress_msg "apparently already running"
73
                log_end_msg 0
74
                exit 0
75
            fi
76
            eventd_start
77
        else
78
            if [ -s "$SNF_EVENTD_CONFIG_FILE" ]; then
79
                [ "$VERBOSE" != no ] && log_warning_msg "snf-ganeti-eventd daemon not enabled in $SNF_EVENTD_DEFAULTS_FILE, not starting..."
80
            fi
81
        fi
82
        ;;
83
  stop)
84
        log_daemon_msg "Stopping snf-ganeti-eventd daemon" "snf-ganeti-eventd"
85
        start-stop-daemon --stop --quiet --oknodo --pidfile $SNF_EVENTD_PID_FILE
86
        log_end_msg $?
87
        rm -f $SNF_EVENTD_PID_FILE
88
        ;;
89
  restart)
90
        set +e
91
        if $SNF_EVENTD_ENABLE; then
92
            log_daemon_msg "Restarting snf-ganeti-eventd daemon" "snf-ganeti-eventd"
93
            if [ -s $SNF_EVENTD_PID_FILE ] && kill -0 $(cat $SNF_EVENTD_PID_FILE) >/dev/null 2>&1; then
94
                start-stop-daemon --stop --quiet --oknodo --pidfile $SNF_EVENTD_PID_FILE || true
95
                sleep 1
96
            else
97
                log_warning_msg "snf-ganeti-eventd daemon not running, attempting to start."
98
                rm -f $SNF_EVENTD_PID_FILE
99
            fi
100
            eventd_start
101
        else
102
            if [ -s "$SNF_EVENTD_CONFIG_FILE" ]; then
103
                [ "$VERBOSE" != no ] && log_warning_msg "snf-ganeti-eventd daemon not enabled in $SNF_EVENTD_DEFAULTS_FILE, not starting..."
104
            fi
105
        fi
106
        ;;
107

    
108
  status)
109
        status_of_proc -p $SNF_EVENTD_PID_FILE "$DAEMON" ganeti-eventd
110
        exit $? # notreached due to set -e
111
        ;;
112
  *)
113
        echo "Usage: /etc/init.d/snf-ganeti-eventd {start|stop|restart|status}"
114
        exit 1
115
esac
116

    
117
exit 0