4 # Copyright (C) 2009, 2011, 2012 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.
34 if [[ "@CUSTOM_ENABLE_CONFD@" == True ]]; then
35 DAEMONS+=( ganeti-confd )
43 # Read defaults file if it exists
44 if [[ -s $defaults_file ]]; then
49 echo "@LOCALSTATEDIR@/run/ganeti/$1.pid"
52 _daemon_executable() {
53 echo "@PREFIX@/sbin/$1"
59 echo "@GNTMASTERUSER@:@GNTMASTERDGROUP@"
62 echo "@GNTCONFDUSER@:@GNTCONFDGROUP@"
65 echo "@GNTRAPIUSER@:@GNTRAPIGROUP@"
68 echo "@GNTNODEDUSER@:@GNTDAEMONSGROUP@"
71 echo "root:@GNTDAEMONSGROUP@"
76 # Checks whether the local machine is part of a cluster
78 local server_pem=@LOCALSTATEDIR@/lib/ganeti/server.pem
81 for fname in $server_pem; do
82 if [[ ! -f $fname ]]; then
83 echo "Missing configuration file $fname" >&2
91 # Checks the exit code of a daemon
93 if [[ "$#" -lt 1 ]]; then
94 echo 'Missing exit code.' >&2
114 # Prints path to PID file for a daemon.
116 if [[ "$#" -lt 1 ]]; then
117 echo 'Missing daemon name.' >&2
121 local name="$1"; shift
123 _daemon_pidfile $name
126 # Prints path to daemon executable.
127 daemon_executable() {
128 if [[ "$#" -lt 1 ]]; then
129 echo 'Missing daemon name.' >&2
133 local name="$1"; shift
135 _daemon_executable $name
138 # Prints a list of all daemons in the order in which they should be started
139 list_start_daemons() {
142 for name in "${DAEMONS[@]}"; do
147 # Prints a list of all daemons in the order in which they should be stopped
148 list_stop_daemons() {
149 list_start_daemons | tac
152 # Checks whether a daemon name is known
154 if [[ "$#" -lt 1 ]]; then
155 echo 'Missing daemon name.' >&2
159 local name="$1"; shift
161 for i in "${DAEMONS[@]}"; do
162 if [[ "$i" == "$name" ]]; then
167 echo "Unknown daemon name '$name'" >&2
171 # Checks whether daemon is running
173 if [[ "$#" -lt 1 ]]; then
174 echo 'Missing daemon name.' >&2
178 local name="$1"; shift
180 start-stop-daemon --stop --signal 0 --quiet \
181 --pidfile $(_daemon_pidfile $name)
186 if [[ "$#" -lt 1 ]]; then
187 echo 'Missing daemon name.' >&2
191 local name="$1"; shift
193 if [[ "$name" == ganeti-confd &&
194 "@CUSTOM_ENABLE_CONFD@" == False ]]; then
195 echo 'ganeti-confd disabled at build time' >&2
199 # Convert daemon name to uppercase after removing "ganeti-" prefix
200 local plain_name=${name#ganeti-}
201 local ucname=$(tr a-z A-Z <<<$plain_name)
203 # Read $<daemon>_ARGS and $EXTRA_<daemon>_ARGS
204 eval local args="\"\$${ucname}_ARGS \$EXTRA_${ucname}_ARGS\""
206 @PKGLIBDIR@/ensure-dirs
208 start-stop-daemon --start --quiet --oknodo \
209 --pidfile $(_daemon_pidfile $name) \
210 --startas $(_daemon_executable $name) \
211 --chuid $(_daemon_usergroup $plain_name) \
217 if [[ "$#" -lt 1 ]]; then
218 echo 'Missing daemon name.' >&2
222 local name="$1"; shift
224 start-stop-daemon --stop --quiet --oknodo --retry 30 \
225 --pidfile $(_daemon_pidfile $name)
228 # Starts a daemon if it's not yet running
232 if ! check $name; then
237 # Starts the master role
243 # Stops the master role
251 for i in $(list_start_daemons); do
254 # Try to start daemon
257 if ! errmsg=$(check_exitcode $rc); then
268 for i in $(list_stop_daemons); do
273 # Reloads the SSH keys
275 @RPL_SSH_INITD_SCRIPT@ restart
278 if [[ "$#" -lt 1 ]]; then
279 echo "Usage: $0 <action>" >&2
283 orig_action=$1; shift
285 if [[ "$orig_action" == *_* ]]; then
286 echo "Command must not contain underscores" >&2
290 # Replace all dashes (-) with underlines (_)
291 action=${orig_action//-/_}
293 # Is it a known function?
294 if ! declare -F "$action" >/dev/null 2>&1; then
295 echo "Unknown command: $orig_action" >&2
299 # Call handler function