4 # Copyright (C) 2009 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 defaults_file=@SYSCONFDIR@/default/ganeti
25 # This is a list of all daemons and the order in which they're started. The
26 # order is important as there are dependencies between them. On shutdown,
27 # they're stopped in reverse order.
40 # Read defaults file if it exists
41 if [[ -s $defaults_file ]]; then
46 echo "@LOCALSTATEDIR@/run/ganeti/$1.pid"
49 _daemon_executable() {
50 echo "@PREFIX@/sbin/$1"
56 echo "@GNTMASTERUSER@:@GNTMASTERDGROUP@"
59 echo "@GNTCONFDUSER@:@GNTCONFDGROUP@"
62 echo "@GNTRAPIUSER@:@GNTRAPIGROUP@"
65 echo "@GNTNODEDUSER@:@GNTDAEMONSGROUP@"
68 echo "root:@GNTDAEMONSGROUP@"
73 # Checks whether the local machine is part of a cluster
75 local server_pem=@LOCALSTATEDIR@/lib/ganeti/server.pem
78 for fname in $server_pem; do
79 if [[ ! -f $fname ]]; then
80 echo "Missing configuration file $fname" >&2
88 # Checks the exit code of a daemon
90 if [[ "$#" -lt 1 ]]; then
91 echo 'Missing exit code.' >&2
111 # Prints a list of all daemons in the order in which they should be started
112 list_start_daemons() {
115 for name in "${DAEMONS[@]}"; do
120 # Prints a list of all daemons in the order in which they should be stopped
121 list_stop_daemons() {
122 list_start_daemons | tac
125 # Checks whether a daemon name is known
127 if [[ "$#" -lt 1 ]]; then
128 echo 'Missing daemon name.' >&2
132 local name="$1"; shift
134 for i in "${DAEMONS[@]}"; do
135 if [[ "$i" == "$name" ]]; then
140 echo "Unknown daemon name '$name'" >&2
144 # Checks whether daemon is running
146 if [[ "$#" -lt 1 ]]; then
147 echo 'Missing daemon name.' >&2
151 local name="$1"; shift
153 start-stop-daemon --stop --signal 0 --quiet \
154 --pidfile $(_daemon_pidfile $name)
159 if [[ "$#" -lt 1 ]]; then
160 echo 'Missing daemon name.' >&2
164 local name="$1"; shift
166 # Convert daemon name to uppercase after removing "ganeti-" prefix
167 local plain_name=${name#ganeti-}
168 local ucname=$(tr a-z A-Z <<<$plain_name)
170 # Read $<daemon>_ARGS and $EXTRA_<daemon>_ARGS
171 eval local args="\"\$${ucname}_ARGS \$EXTRA_${ucname}_ARGS\""
173 @PKGLIBDIR@/ensure-dirs
175 start-stop-daemon --start --quiet --oknodo \
176 --pidfile $(_daemon_pidfile $name) \
177 --startas $(_daemon_executable $name) \
178 --chuid $(_daemon_usergroup $plain_name) \
184 if [[ "$#" -lt 1 ]]; then
185 echo 'Missing daemon name.' >&2
189 local name="$1"; shift
191 start-stop-daemon --stop --quiet --oknodo --retry 30 \
192 --pidfile $(_daemon_pidfile $name)
195 # Starts a daemon if it's not yet running
199 if ! check $name; then
204 # Starts the master role
210 # Stops the master role
218 for i in $(list_start_daemons); do
221 # Try to start daemon
224 if ! errmsg=$(check_exitcode $rc); then
235 for i in $(list_stop_daemons); do
240 # Reloads the SSH keys
242 @RPL_SSH_INITD_SCRIPT@ restart
245 if [[ "$#" -lt 1 ]]; then
246 echo "Usage: $0 <action>" >&2
250 orig_action=$1; shift
252 if [[ "$orig_action" == *_* ]]; then
253 echo "Command must not contain underscores" >&2
257 # Replace all dashes (-) with underlines (_)
258 action=${orig_action//-/_}
260 # Is it a known function?
261 if ! declare -F "$action" >/dev/null 2>&1; then
262 echo "Unknown command: $orig_action" >&2
266 # Call handler function