4 # Copyright (C) 2009, 2011 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 a list of all daemons in the order in which they should be started
115 list_start_daemons() {
118 for name in "${DAEMONS[@]}"; do
123 # Prints a list of all daemons in the order in which they should be stopped
124 list_stop_daemons() {
125 list_start_daemons | tac
128 # Checks whether a daemon name is known
130 if [[ "$#" -lt 1 ]]; then
131 echo 'Missing daemon name.' >&2
135 local name="$1"; shift
137 for i in "${DAEMONS[@]}"; do
138 if [[ "$i" == "$name" ]]; then
143 echo "Unknown daemon name '$name'" >&2
147 # Checks whether daemon is running
149 if [[ "$#" -lt 1 ]]; then
150 echo 'Missing daemon name.' >&2
154 local name="$1"; shift
156 start-stop-daemon --stop --signal 0 --quiet \
157 --pidfile $(_daemon_pidfile $name)
162 if [[ "$#" -lt 1 ]]; then
163 echo 'Missing daemon name.' >&2
167 local name="$1"; shift
169 if [[ "$name" == ganeti-confd &&
170 "@CUSTOM_ENABLE_CONFD@" == False ]]; then
171 echo 'ganeti-confd disabled at build time' >&2
175 # Convert daemon name to uppercase after removing "ganeti-" prefix
176 local plain_name=${name#ganeti-}
177 local ucname=$(tr a-z A-Z <<<$plain_name)
179 # Read $<daemon>_ARGS and $EXTRA_<daemon>_ARGS
180 eval local args="\"\$${ucname}_ARGS \$EXTRA_${ucname}_ARGS\""
182 @PKGLIBDIR@/ensure-dirs
184 start-stop-daemon --start --quiet --oknodo \
185 --pidfile $(_daemon_pidfile $name) \
186 --startas $(_daemon_executable $name) \
187 --chuid $(_daemon_usergroup $plain_name) \
193 if [[ "$#" -lt 1 ]]; then
194 echo 'Missing daemon name.' >&2
198 local name="$1"; shift
200 start-stop-daemon --stop --quiet --oknodo --retry 30 \
201 --pidfile $(_daemon_pidfile $name)
204 # Starts a daemon if it's not yet running
208 if ! check $name; then
213 # Starts the master role
219 # Stops the master role
227 for i in $(list_start_daemons); do
230 # Try to start daemon
233 if ! errmsg=$(check_exitcode $rc); then
244 for i in $(list_stop_daemons); do
249 # Reloads the SSH keys
251 @RPL_SSH_INITD_SCRIPT@ restart
254 if [[ "$#" -lt 1 ]]; then
255 echo "Usage: $0 <action>" >&2
259 orig_action=$1; shift
261 if [[ "$orig_action" == *_* ]]; then
262 echo "Command must not contain underscores" >&2
266 # Replace all dashes (-) with underlines (_)
267 action=${orig_action//-/_}
269 # Is it a known function?
270 if ! declare -F "$action" >/dev/null 2>&1; then
271 echo "Unknown command: $orig_action" >&2
275 # Call handler function