Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 8e2ed2e8

History | View | Annotate | Download (2.7 kB)

1
#!/bin/sh
2
# ganeti daemons init script
3
# based on skeleton from Debian GNU/Linux
4
### BEGIN INIT INFO
5
# Provides:          ganeti
6
# Required-Start:    $syslog $remote_fs
7
# Required-Stop:     $syslog $remote_fs
8
# Default-Start:     2 3 4 5
9
# Default-Stop:      0 1 6
10
# Short-Description: Ganeti Cluster Manager
11
# Description:       Ganeti Cluster Manager
12
### END INIT INFO
13

    
14
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
15
DESC="Ganeti cluster"
16

    
17
DAEMON_UTIL=@PKGLIBDIR@/daemon-util
18

    
19
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
20

    
21
test -f "$DAEMON_UTIL" || exit 0
22

    
23
. /lib/lsb/init-functions
24

    
25
check_exitcode() {
26
    RC=$1
27

    
28
    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
29
    then
30
        log_action_end_msg 0 "$errmsg"
31
    else
32
        log_action_end_msg 1 "$errmsg"
33
    fi
34
}
35

    
36
start_action() {
37
    # called as start_action daemon-name
38
    local daemon="$1"
39
    log_action_begin_msg "$daemon"
40
    $DAEMON_UTIL start "$@"
41
    check_exitcode $?
42
}
43

    
44
stop_action() {
45
    # called as stop_action daemon-name
46
    local daemon="$1"
47
    log_action_begin_msg "$daemon"
48
    $DAEMON_UTIL stop "$@"
49
    check_exitcode $?
50
}
51

    
52
maybe_do() {
53
    requested="$1"; shift
54
    action="$1"; shift
55
    target="$1"
56
    if [ -z "$requested" -o "$requested" = "$target" ]; then
57
        $action "$@"
58
    fi
59
}
60

    
61
start_all() {
62
    if ! $DAEMON_UTIL check-config; then
63
        log_warning_msg "Incomplete configuration, will not run."
64
        exit 0
65
    fi
66

    
67
    for i in $($DAEMON_UTIL list-start-daemons); do
68
        maybe_do "$1" start_action $i
69
    done
70
}
71

    
72
stop_all() {
73
    for i in $($DAEMON_UTIL list-stop-daemons); do
74
        maybe_do "$1" stop_action $i
75
    done
76
}
77

    
78
status_all() {
79
    local daemons="$1" status ret
80

    
81
    if [ -z "$daemons" ]; then
82
      daemons=$($DAEMON_UTIL list-start-daemons)
83
    fi
84

    
85
    status=0
86

    
87
    for i in $daemons; do
88
      if status_of_proc $($DAEMON_UTIL daemon-executable $i) $i; then
89
          ret=0
90
      else
91
          ret=$?
92
          # Use exit code from first failed call
93
          if [ "$status" -eq 0 ]; then
94
              status=$ret
95
          fi
96
      fi
97
    done
98

    
99
    exit $status
100
}
101

    
102
if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then
103
    log_failure_msg "$errmsg"
104
    exit 1
105
fi
106

    
107
case "$1" in
108
    start)
109
        log_daemon_msg "Starting $DESC" "$2"
110
        start_all "$2"
111
        ;;
112
    stop)
113
        log_daemon_msg "Stopping $DESC" "$2"
114
        stop_all "$2"
115
        ;;
116
    restart|force-reload)
117
        log_daemon_msg "Restarting $DESC" "$2"
118
        stop_all "$2"
119
        start_all "$2"
120
        ;;
121
    status)
122
        status_all "$2"
123
        ;;
124
    *)
125
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
126
        exit 1
127
        ;;
128
esac
129

    
130
exit 0