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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
#!@BASHPATH@
# Authors:
# Andrew Beekhof <abeekhof@redhat.com>
# Fabio M. Di Nitto <fdinitto@redhat.com>
#
# License: Revised BSD
# chkconfig: - 20 80
# description: Corosync Cluster Engine
# processname: corosync
#
### BEGIN INIT INFO
# Provides: corosync
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Short-Description: Starts and stops Corosync Cluster Engine.
# Description: Starts and stops Corosync Cluster Engine.
### END INIT INFO
desc="Corosync Cluster Engine"
prog="corosync"
prog_pid_file="@LOCALSTATEDIR@/run/$prog.pid"
# set secure PATH
PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@"
success()
{
echo -ne "[ OK ]\r"
}
failure()
{
echo -ne "[FAILED]\r"
}
warning()
{
echo -ne "[WARNING]\r"
}
# pid_var_run pid_file
# Echo pid from given pid_file.
# Returns LSB exit code for the 'status' action.
pid_var_run()
{
local pid_file="$1"
local pid
if [ -f "$pid_file" ]; then
[ ! -r "$pid_file" ] && return 4
pid=$(cat "$pid_file")
[ -z "$pid" ] && return 1
[ -n "${pid//[0-9]/}" ] && return 1
if kill -n 0 "$pid" 2>/dev/null;then
echo "$pid"
return 0
else
return 1
fi
fi
return 3
}
# status [-p pid_file] {program}
status()
{
local pid_file
if [ "$1" = "-p" ]; then
pid_file=$2
shift 2
fi
pid=$(pid_var_run "$pid_file" 2>/dev/null)
res=$?
if [ $res -ne 0 -a -z "$pid_file" ]; then
pid=$(__pids_pidof "$1")
[ -n "$pid" ]
res=$?
fi
if [ $res -ne 0 ]; then
echo "$1 is stopped"
else
echo "$1 (pid $pid) is running..."
fi
return $res
}
[ -f @INITCONFIGDIR@/$prog ] && . @INITCONFIGDIR@/$prog
case '@INITCONFIGDIR@' in
*/sysconfig) # rpm based distros
[ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
[ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog";;
*/default) # deb based distros
[ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog";;
esac
# The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
# This means it matches scripts, including this one.
# Redefine it here so that status (from the same file) works.
# Otherwise simultaneous calls to stop() will loop forever
__pids_pidof() {
pidof -c -o $$ -o $PPID -o %PPID "$1" || \
pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
}
cluster_disabled_at_boot()
{
if grep -q nocluster /proc/cmdline && \
[ "$(tty)" = "/dev/console" ]; then
echo -e "not configured to run at boot"
failure
return 1
fi
return 0
}
wait_for_ipc()
{
try=0
max_try=$((COROSYNC_INIT_TIMEOUT*2-1))
[ "$max_try" -le "0" ] && max_try=120
while [ "$try" -le "$max_try" ]; do
if corosync-cpgtool > /dev/null 2>&1; then
return 0
fi
sleep 0.5
try=$((try + 1))
done
return 1
}
start()
{
echo -n "Starting $desc ($prog): "
! cluster_disabled_at_boot && return
# most recent distributions use tmpfs for @LOCALSTATEDIR@/run
# to avoid to clean it up on every boot.
# they also assume that init scripts will create
# required subdirectories for proper operations
mkdir -p @LOCALSTATEDIR@/run
if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then
success
else
$prog $COROSYNC_OPTIONS > /dev/null 2>&1
if [ "$?" != 0 ] || ! wait_for_ipc; then
failure
rtrn=1
else
touch $LOCK_FILE
if corosync-cfgtool -s > /dev/null 2>&1; then
success
else
warning
fi
fi
fi
echo
}
stop()
{
! status -p "$prog_pid_file" "$prog" > /dev/null 2>&1 && return
echo -n "Signaling $desc ($prog) to terminate: "
# Call cfgtool to trigger shutdown callbacks
corosync-cfgtool -H --force > /dev/null 2>&1
# Send TERM signal (if cfgtool -H failed)
kill -TERM "$(pid_var_run $prog_pid_file)" > /dev/null 2>&1
success
echo
echo -n "Waiting for $prog services to unload:"
while status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; do
sleep 1
echo -n "."
done
rm -f $LOCK_FILE
success
echo
}
restart()
{
stop
start
}
rtrn=0
case "$1" in
start)
start
;;
restart|reload|force-reload)
restart
;;
condrestart|try-restart)
if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then
restart
fi
;;
status)
status -p "$prog_pid_file" "$prog"
rtrn=$?
;;
stop)
stop
;;
*)
echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
rtrn=2
;;
esac
exit $rtrn
|