This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ganeti
executable file
·152 lines (130 loc) · 3.16 KB
/
ganeti
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# ganeti daemons init script
#
# chkconfig: 2345 99 01
# description: Ganeti Cluster Manager
### BEGIN INIT INFO
# Provides: ganeti
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ganeti Cluster Manager
# Description: Ganeti Cluster Manager
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
DESC="Ganeti cluster"
DAEMON_UTIL=/usr/lib/ganeti/daemon-util
SCRIPTNAME="/etc/init.d/ganeti"
## Quit if the daemon utils are not there
test -f "$DAEMON_UTIL" || exit 0
## Check if we are under corosync
## otherwise we handle all the daemons
if [ -f /etc/default/corosync ]
then
DAEMONS="ganeti-noded ganeti-confd"
else
DAEMONS=$($DAEMON_UTIL list-start-daemons)
fi
if [ -r /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
elif [ -r /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo "Unable to find init functions"
exit 1
fi
check_exitcode() {
RC=$1
if errmsg=$($DAEMON_UTIL check-exitcode $RC)
then
log_action_end_msg 0 "$errmsg"
else
log_action_end_msg 1 "$errmsg"
fi
}
start_action() {
# called as start_action daemon-name
local daemon="$1"
log_action_begin_msg "$daemon"
$DAEMON_UTIL start "$@"
check_exitcode $?
}
stop_action() {
# called as stop_action daemon-name
local daemon="$1"
log_action_begin_msg "$daemon"
$DAEMON_UTIL stop "$@"
check_exitcode $?
}
maybe_do() {
requested="$1"; shift
action="$1"; shift
target="$1"
if [ -z "$requested" -o "$requested" = "$target" ]; then
$action "$@"
fi
}
start_all() {
if ! $DAEMON_UTIL check-config; then
log_warning_msg "Incomplete configuration, will not run."
exit 0
fi
#for i in $($DAEMON_UTIL list-start-daemons); do
for i in $DAEMONS; do
maybe_do "$1" start_action $i
done
}
stop_all() {
#for i in $($DAEMON_UTIL list-stop-daemons); do
for i in $DAEMONS; do
maybe_do "$1" stop_action $i
done
}
status_all() {
local daemons="$1" status ret
if [ -z "$daemons" ]; then
#daemons=$($DAEMON_UTIL list-start-daemons)
daemons=$DAEMONS
fi
status=0
for i in $daemons; do
if status_of_proc $($DAEMON_UTIL daemon-executable $i) $i; then
ret=0
else
ret=$?
# Use exit code from first failed call
if [ "$status" -eq 0 ]; then
status=$ret
fi
fi
done
exit $status
}
if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then
log_failure_msg "$errmsg"
exit 1
fi
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$2"
start_all "$2"
;;
stop)
log_daemon_msg "Stopping $DESC" "$2"
stop_all "$2"
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$2"
stop_all "$2"
start_all "$2"
;;
status)
status_all "$2"
;;
*)
log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
exit 1
;;
esac
exit 0