public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE3 - cman init: major cleanup
@ 2009-03-27 19:07 Fabio M. Di Nitto
0 siblings, 0 replies; only message in thread
From: Fabio M. Di Nitto @ 2009-03-27 19:07 UTC (permalink / raw)
To: cluster-cvs-relay
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=bac9a4aa90acea30ce8e265103c315b1b25a451e
Commit: bac9a4aa90acea30ce8e265103c315b1b25a451e
Parent: 6001f5f767c30e0b24a45f9ad5f22a9ba5281a40
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate: Wed Mar 25 10:16:29 2009 +0100
Committer: Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Fri Mar 27 20:05:45 2009 +0100
cman init: major cleanup
Merge if/then/else checks with command executions where it makes sense.
Move ulimit setting as first thing in the start process.
Stop using pidof in favour of status.
Use pkill insteand of kill.
Simplify some args invokations (stop_cman and stop).
Simplify start / stop cases and LOCK_FILE handling.
Simplify restart case to invoke directly internal functions instaed
of reforking cman init script 2 times.
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
cman/init.d/cman.in | 200 ++++++++++++++++++++------------------------------
1 files changed, 80 insertions(+), 120 deletions(-)
diff --git a/cman/init.d/cman.in b/cman/init.d/cman.in
index 1414a9e..79059b3 100644
--- a/cman/init.d/cman.in
+++ b/cman/init.d/cman.in
@@ -161,8 +161,7 @@ start_configfs()
start_cman()
{
# cman
- @SBINDIR@/cman_tool status > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! @SBINDIR@/cman_tool status > /dev/null 2>&1; then
case "$CONFIG_LOADER" in
ldapconfig)
if [ -n "$LDAP_URL" ] || [ -n "$LDAP_BASEDN" ]; then
@@ -218,8 +217,7 @@ unfence_self()
start_qdiskd()
{
- status qdiskd > /dev/null 2>&1
- if [ $? -ne 0 ] && \
+ if ! status qdiskd > /dev/null 2>&1 && \
ccs_tool query /cluster/quorumd >/dev/null 2>&1; then
errmsg=$( @SBINDIR@/qdiskd -Q 2>&1 ) || return 1
fi
@@ -229,25 +227,20 @@ start_qdiskd()
start_daemons()
{
- status groupd > /dev/null 2>&1
- if [ $? -ne 0 ] && \
+ if ! status groupd > /dev/null 2>&1 && \
[ "$(ccs_tool query /cluster/group/@groupd_compat 2>/dev/null || true)" != "0" ]; then
errmsg=$( @SBINDIR@/groupd 2>&1 ) || return 1
fi
- status fenced > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! status fenced > /dev/null 2>&1 ; then
errmsg=$( @SBINDIR@/fenced 2>&1 ) || return 1
fi
- status dlm_controld > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! status dlm_controld > /dev/null 2>&1; then
errmsg=$( @SBINDIR@/dlm_controld 2>&1 ) || return 1
fi
- status gfs_controld > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! status gfs_controld > /dev/null 2>&1; then
errmsg=$( @SBINDIR@/gfs_controld 2>&1 ) || return 1
fi
- status cmannotifyd > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! status cmannotifyd > /dev/null 2>&1; then
case "$CMAN_NOTIFYD_START" in
yes)
errmsg=$(@SBINDIR@/cmannotifyd 2>&1 ) || return 1
@@ -271,8 +264,7 @@ start_daemons()
start_fence()
{
- @SBINDIR@/cman_tool status | grep Flags | grep 2node > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! @SBINDIR@/cman_tool status | grep Flags | grep 2node > /dev/null 2>&1; then
errmsg=$( @SBINDIR@/fence_tool join -w $FENCE_JOIN_TIMEOUT \
> /dev/null 2>&1 ) || return 1
else
@@ -285,8 +277,7 @@ start_fence()
start_fence_xvmd()
{
- status fence_xvmd > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! status fence_xvmd > /dev/null 2>&1; then
errmsg=$( @SBINDIR@/fence_xvmd $FENCE_XVMD_OPTS 2>&1 ) || return 1
fi
return 0
@@ -302,8 +293,7 @@ xend_bridged_net_enabled() {
return 1
fi
- chkconfig --levels "$current_runlevel" xend 2>/dev/null
- if [ $? -ne 0 ]; then
+ if ! chkconfig --levels "$current_runlevel" xend 2>/dev/null; then
# xend doesn't start at this runlevel.
return 1
fi
@@ -313,8 +303,7 @@ xend_bridged_net_enabled() {
return 1
fi
- egrep "^[[:blank:]]*\([[:blank:]]*network-script[[:blank:]]+(')?[[:blank:]]*${NETWORK_BRIDGE_SCRIPT}([[:blank:]]*\)|[[:blank:]]+)" /etc/xen/xend-config.sxp >&/dev/null
- if [ $? -ne 0 ]; then
+ if ! egrep "^[[:blank:]]*\([[:blank:]]*network-script[[:blank:]]+(')?[[:blank:]]*${NETWORK_BRIDGE_SCRIPT}([[:blank:]]*\)|[[:blank:]]+)" /etc/xen/xend-config.sxp >&/dev/null; then
# xend isn't configured to use bridged networking.
return 1
fi
@@ -359,8 +348,7 @@ fence_xvmd_enabled()
# (If -X is specified, it doesn't matter if it's in cluster.conf;
# we'll start it anyway since ccsd is not required)
#
- @SBINDIR@/cman_tool status > /dev/null 2>&1
- if [ $? -eq 0 ]; then
+ if @SBINDIR@/cman_tool status > /dev/null 2>&1; then
if [ "$FENCE_XVMD_OPTS" = "${FENCE_XVMD_OPTS/-X/}" ]; then
@SBINDIR@/ccs_tool query /cluster/fence_xvmd || return 1
fi
@@ -405,14 +393,15 @@ start()
{
echo "Starting cluster: "
+ ## global bits
+ # guarantee enough limits
+ ulimit -c unlimited
# required for distributions that use tmpfs for /var/run
mkdir -p /var/run/cluster
- xend_bridged_net_enabled
- if [ $? -eq 0 ]; then
+ if xend_bridged_net_enabled; then
echo -n " Enabling workaround for Xend bridged networking... "
- xend_bridged_net_start
- if [ $? -eq 0 ]; then
+ if xend_bridged_net_start; then
echo "done"
else
echo "failed: $errmsg"
@@ -421,9 +410,7 @@ start()
fi
echo -n " Loading modules... "
- ulimit -c unlimited
- load_modules
- if [ $? -eq 0 ]; then
+ if load_modules; then
echo "done"
else
echo "failed"
@@ -431,8 +418,7 @@ start()
fi
echo -n " Mounting configfs... "
- start_configfs
- if [ $? -eq 0 ]; then
+ if start_configfs; then
echo "done"
else
echo "failed"
@@ -441,7 +427,7 @@ start()
echo -n " Setting network parameters... "
set_networking_params
- if [ $? -eq 0 ]; then
+ if set_networking_params; then
echo "done"
else
echo "failed"
@@ -450,21 +436,17 @@ start()
echo -n " Starting cman... "
start_cman
- if [ $? -eq 0 ]; then
+ if start_cman; then
echo "done"
else
echo "failed"
return 1
fi
- unfence_self
- if [ $? -eq 1 ]; then
- return 1
- fi
+ unfence_self || return 1
echo -n " Starting qdiskd... "
- start_qdiskd
- if [ $? -eq 0 ]; then
+ if start_qdiskd; then
echo "done"
else
echo "failed"
@@ -472,8 +454,7 @@ start()
fi
echo -n " Starting daemons... "
- start_daemons
- if [ $? -eq 0 ]; then
+ if start_daemons; then
echo "done"
else
echo "failed"
@@ -482,8 +463,7 @@ start()
if fence_join_enabled; then
echo -n " Starting fencing... "
- start_fence
- if [ $? -eq 0 ]; then
+ if start_fence; then
echo "done"
else
echo "failed"
@@ -493,8 +473,7 @@ start()
if fence_xvmd_enabled; then
echo -n " Starting virtual machine fencing host... "
- start_fence_xvmd
- if [ $? -eq 0 ]; then
+ if start_fence_xvmd; then
echo "done"
else
echo "failed"
@@ -520,8 +499,7 @@ stop_configfs()
stop_cman()
{
- @SBINDIR@/cman_tool status > /dev/null 2>&1
- if [ $? -eq 0 ]; then
+ if @SBINDIR@/cman_tool status > /dev/null 2>&1; then
errmsg=$( @SBINDIR@/cman_tool -t $CMAN_SHUTDOWN_TIMEOUT \
-w leave $1 2>&1 ) || return 1
fi
@@ -530,25 +508,25 @@ stop_cman()
stop_daemons()
{
- if pid=$(pidof gfs_controld 2>&1); then
- errmsg=$(kill $pid 2>&1) || return 1
+ if status gfs_controld > /dev/null 2>&1; then
+ errmsg=$(pkill -TERM gfs_controld) || return 1
fi
- if pid=$(pidof dlm_controld 2>&1); then
- errmsg=$(kill $pid 2>&1) || return 1
+ if status dlm_controld > /dev/null 2>&1; then
+ errmsg=$(pkill -TERM dlm_controld) || return 1
fi
- if pid=$(pidof fenced 2>&1); then
- errmsg=$(kill $pid 2>&1) || return 1
+ if status fenced > /dev/null 2>&1; then
+ errmsg=$(pkill -TERM fenced) || return 1
fi
- if pid=$(pidof groupd 2>&1); then
- errmsg=$(kill $pid 2>&1) || return 1
+ if status groupd > /dev/null 2>&1; then
+ errmsg=$(pkill -TERM groupd) || return 1
fi
return 0 # all ok
}
stop_cmannotifyd()
{
- if pid=$(pidof cmannotifyd 2>&1); then
- errmsg=$(kill $pid 2>&1) || return 1
+ if status cmannotifyd > /dev/null 2>&1; then
+ errmsg=$(pkill -TERM cmannotifyd) || return 1
fi
return 0
}
@@ -557,38 +535,34 @@ stop_qdiskd()
{
retries=0
- pid="$(pidof qdiskd)"
- while [ -n "$pid" ] && [ $retries -lt 5 ]; do
- kill $pid 2>&1
+ while status qdiskd > /dev/null 2>&1 && [ $retries -lt 5 ]; do
+ errmsg=$(pkill -TERM qdiskd) || return 1
sleep 1
((retries++))
- pid="$(pidof qdiskd)"
done
- if [ -z "$(pidof qdiskd)" ]; then
- return 0
- else
+ if status qdiskd > /dev/null 2>&1; then
return 1
fi
+ return 0
}
stop_fence()
{
- if pidof fenced > /dev/null 2>&1; then
+ if status fenced > /dev/null 2>&1; then
@SBINDIR@/fence_tool leave -w 10 > /dev/null 2>&1
- rtrn=$?
- return $rtrn
+ return $?
fi
return 0 # all ok
}
stop_fence_xvmd()
{
- if pidof fence_xvmd > /dev/null 2>&1; then
- pkill -TERM fence_xvmd
+ if status fence_xvmd > /dev/null 2>&1; then
+ errmsg=$(pkill -TERM fence_xvmd) || return 1
sleep 1 # A bit of time for fenced to exit
fi
- [ -z "$(pidof fence_xvmd)" ]
+ status fence_xvmd
return $?
}
@@ -598,8 +572,7 @@ stop()
if fence_xvmd_enabled; then
echo -n " Stopping virtual machine fencing host... "
- stop_fence_xvmd
- if [ $? -eq 0 ]; then
+ if stop_fence_xvmd; then
echo "done"
else
echo "failed"
@@ -609,8 +582,7 @@ stop()
if fence_join_enabled; then
echo -n " Stopping fencing... "
- stop_fence
- if [ $? -eq 0 ]; then
+ if stop_fence; then
echo "done"
else
echo "failed"
@@ -619,8 +591,7 @@ stop()
fi
echo -n " Stopping daemons... "
- stop_daemons
- if [ $? -eq 0 ]; then
+ if stop_daemons; then
echo "done"
else
echo "failed"
@@ -628,8 +599,7 @@ stop()
fi
echo -n " Stopping the Quorum Disk Daemon: "
- stop_qdiskd
- if [ $? -eq 0 ]; then
+ if stop_qdiskd; then
echo "done"
else
echo "failed"
@@ -637,12 +607,7 @@ stop()
fi
echo -n " Stopping cman... "
- if [ $1 ]; then
- stop_cman $1
- else
- stop_cman
- fi
- if [ $? -eq 0 ]; then
+ if stop_cman "$1"; then
echo "done"
else
echo "failed"
@@ -650,8 +615,7 @@ stop()
fi
echo -n " Stopping cmannotifyd... "
- stop_cmannotifyd
- if [ $? -eq 0 ]; then
+ if stop_cmannotifyd; then
echo "done"
else
echo "failed"
@@ -659,8 +623,7 @@ stop()
fi
echo -n " Unmounting configfs... "
- stop_configfs
- if [ $? -eq 0 ]; then
+ if stop_configfs; then
echo "done"
else
echo "failed"
@@ -711,51 +674,48 @@ rtrn=1
# See how we were called.
case "$1" in
start)
- start
- rtrn=$?
- [ $rtrn = 0 ] && touch $LOCK_FILE
- if [ $rtrn -ne 0 ]; then
- echo $errmsg
- failure "failed to start cman"
- echo
+ if start; then
+ touch $LOCK_FILE
+ success
+ rtrn=0
else
- success "start"
- echo
+ echo $errmsg
+ failure
fi
+ echo
;;
stop)
- if [ $2 ]; then
- stop
+ if stop; then
+ success
+ rm -f $LOCK_FILE
+ rtrn=0
else
- stop remove
- fi
- rtrn=$?
- [ $rtrn = 0 ] && rm -f $LOCK_FILE
- if [ $rtrn -ne 0 ]; then
echo $errmsg
- failure "failed to stop cman"
- echo
- else
- success "shutdown"
- echo
+ failure
fi
+ echo
;;
restart|reload)
- $0 stop restart
- $0 start
- rtrn=$?
+ echo -n "Restarting cluster: "
+ if stop remove > /dev/null 2>&1 && \
+ start > /dev/null 2>&1; then
+ success
+ rtrn=0
+ else
+ failure
+ fi
+ echo
;;
status)
- cmanstatus
- rtrn=$?
- if [ $rtrn -ne 0 ]; then
- echo $errmsg
- else
+ if cmanstatus; then
echo "cman is running."
+ rtrn=0
+ else
+ echo $errmsg
fi
;;
*)
- echo $"Usage: $0 {start|stop|reload|restart|status}"
+ echo "Usage: $0 {start|stop|reload|restart|status}"
;;
esac
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-03-27 19:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-27 19:07 cluster: STABLE3 - cman init: major cleanup Fabio M. Di Nitto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).