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"
53 # Checks whether the local machine is part of a cluster
55 local server_pem=@LOCALSTATEDIR@/lib/ganeti/server.pem
58 for fname in $server_pem; do
59 if [[ ! -f $fname ]]; then
60 echo "Missing configuration file $fname" >&2
68 # Checks the exit code of a daemon
70 if [[ "$#" -lt 1 ]]; then
71 echo 'Missing exit code.' >&2
91 # Prints a list of all daemons in the order in which they should be started
92 list_start_daemons() {
95 for name in "${DAEMONS[@]}"; do
100 # Prints a list of all daemons in the order in which they should be stopped
101 list_stop_daemons() {
102 list_start_daemons | tac
105 # Checks whether a daemon name is known
107 if [[ "$#" -lt 1 ]]; then
108 echo 'Missing daemon name.' >&2
112 local name="$1"; shift
114 for i in "${DAEMONS[@]}"; do
115 if [[ "$i" == "$name" ]]; then
120 echo "Unknown daemon name '$name'" >&2
124 # Checks whether daemon is running
126 if [[ "$#" -lt 1 ]]; then
127 echo 'Missing daemon name.' >&2
131 local name="$1"; shift
133 start-stop-daemon --stop --signal 0 --quiet \
134 --pidfile $(_daemon_pidfile $name)
139 if [[ "$#" -lt 1 ]]; then
140 echo 'Missing daemon name.' >&2
144 local name="$1"; shift
146 # Convert daemon name to uppercase after removing "ganeti-" prefix
147 local ucname=$(echo ${name#ganeti-} | tr a-z A-Z)
149 # Read $<daemon>_ARGS and $EXTRA_<daemon>_ARGS
150 eval local args="\"\$${ucname}_ARGS \$EXTRA_${ucname}_ARGS\""
152 @PKGLIBDIR@/ensure-dirs
154 start-stop-daemon --start --quiet --oknodo \
155 --pidfile $(_daemon_pidfile $name) \
156 --startas $(_daemon_executable $name) \
162 if [[ "$#" -lt 1 ]]; then
163 echo 'Missing daemon name.' >&2
167 local name="$1"; shift
169 start-stop-daemon --stop --quiet --oknodo --retry 30 \
170 --pidfile $(_daemon_pidfile $name)
173 # Starts a daemon if it's not yet running
177 if ! check $name; then
182 # Starts the master role
188 # Stops the master role
196 for i in $(list_start_daemons); do
199 # Try to start daemon
202 if ! errmsg=$(check_exitcode $rc); then
213 for i in $(list_stop_daemons); do
218 # Reloads the SSH keys
220 @RPL_SSH_INITD_SCRIPT@ restart
223 if [[ "$#" -lt 1 ]]; then
224 echo "Usage: $0 <action>" >&2
228 orig_action=$1; shift
230 if [[ "$orig_action" == *_* ]]; then
231 echo "Command must not contain underscores" >&2
235 # Replace all dashes (-) with underlines (_)
236 action=${orig_action//-/_}
238 # Is it a known function?
239 if ! declare -F "$action" >/dev/null 2>&1; then
240 echo "Unknown command: $orig_action" >&2
244 # Call handler function