📄 heartbeat.in
字号:
#!/bin/sh## $Id: heartbeat.in,v 1.36 2004/05/17 15:12:08 lars Exp $## heartbeat Start high-availability services## Author: Alan Robertson <alanr@unix.sh>## This script works correctly under SuSE, Debian,# Conectiva, Red Hat and a few others. Please let me know if it# doesn't work under your distribution, and we'll fix it.# We don't hate anyone, and like for everyone to use# our software, no matter what OS or distribution you're using.## chkconfig: 2345 @HB_INITSTARTPRI@ @HB_INITSTOPPRI@# description: Startup script high-availability services.# processname: heartbeat# pidfile: @localstatedir@/run/heartbeat.pid# config: @sysconfdir@/ha.d/ha.cf#### BEGIN INIT INFO# Description: @HB_PKG@ is a basic high-availability subsystem.# It will start services at initialization, and when machines go up# or down. This version will also perform IP address takeover using# gratuitous ARPs. It works correctly for a 2-node configuration,# and is extensible to larger configurations.# # It implements the following kinds of heartbeats:# - Bidirectional Serial Rings ("raw" serial ports)# - UDP/IP broadcast (ethernet, etc)# - UDP/IP multicast (ethernet, etc)# - Unicast heartbeats# - "ping" heartbeats (for routers, switches, etc.)# (to be used for breaking ties in 2-node systems# and monitoring networking availability)## Short-Description: High-availability services.# Required-Start: $network $time $syslog# Required-Stop: $network $time $syslog# Default-Start: 3 5# Default-Stop: 0 6### END INIT INFOHA_DIR=@sysconfdir@/ha.d; export HA_DIRCONFIG=$HA_DIR/ha.cf. $HA_DIR/shellfuncsLOCKDIR=@localstatedir@/lock/subsysRUNDIR=@localstatedir@/runif [ -r /etc/SuSE-release ]then # rc.status is new since SuSE 7.0 [ -r /etc/rc.status ] && . /etc/rc.status [ -r /etc/rc.config ] && . /etc/rc.config # Determine the base and follow a runlevel link name. base=${0##*/} link=${base#*[SK][0-9][0-9]}fiif [ -z "$rc_done" ]then rc_done="Done." rc_failed="Failed." rc_skipped="Skipped."fi# exec 2>>/var/log/ha-debug# This should probably be it's own autoconf parameter# because RH has moved it from time to time...# and I suspect Conectiva and Mandrake also supply it.DISTFUNCS=/etc/rc.d/init.d/functionsPROC_HA=$HA_BIN/ha.oSUBSYS=heartbeatINSMOD=/sbin/insmodUS=`uname -n`# Set this to a 1 if you want to automatically load kernel modulesUSE_MODULES=@USE_MODULES@[ -x $HA_BIN/heartbeat ] || exit 0## Some environments like it if we use their functions...#if [ ! -x $DISTFUNCS ]then # Provide our own versions of these functions status() { $HA_BIN/heartbeat -s } echo_failure() { EchoEsc " Heartbeat failure [rc=$1]. $rc_failed" return $1 } echo_success() { : Cool! It started! EchoEsc "$rc_done" }else . $DISTFUNCSfi## See if they've configured things yet...#if [ ! -f $CONFIG ]then EchoNoNl "Heartbeat not configured: $CONFIG not found." echo_failure 1 exit 0fiinit_watchdog() { if [ -f /proc/devices -a -x $INSMOD ] then init_watchdog_linux fi}## Install the softdog module if we need to#init_watchdog_linux() {## We need to install it if watchdog is specified in $CONFIG, and# /dev/watchdog refers to a softdog device, or it /dev/watchdog# doesn't exist at all.## If we need /dev/watchdog, then we'll make it if necessary.## Whatever the user says we should use for watchdog device, that's# what we'll check for, use and create if necessary. If they misspell# it, or don't put it under /dev, so will we.# Hope they do it right :-)## insmod=no # What do they think /dev/watchdog is named? MISCDEV=`grep ' misc$' /proc/devices | cut -c1-4` MISCDEV=`Echo $MISCDEV` WATCHDEV=`ha_parameter watchdog` WATCHDEV=`Echo $WATCHDEV` if [ "X$WATCHDEV" != X ] then : Watchdog requested by $CONFIG file # # We try and insmod the module if there's no dev or the dev exists # and points to the softdog major device. # if [ ! -c "$WATCHDEV" ] then insmod=yes else case `ls -l "$WATCHDEV" 2>/dev/null` in *$MISCDEV,*) insmod=yes;; *) : "$WATCHDEV isn't a softdog device (wrong major)" ;; esac fi else : No watchdog device specified in $CONFIG file. fi case $insmod in yes) if grep softdog /proc/modules >/dev/null 2>&1 then : softdog already loaded else $INSMOD softdog nowayout=0 >/dev/null 2>&1 fi;; esac if [ "X$WATCHDEV" != X -a ! -c "$WATCHDEV" -a $insmod = yes ] then minor=`cat /proc/misc | grep watchdog | cut -c1-4` mknod -m 600 $WATCHDEV c $MISCDEV $minor fi} # init_watchdog_linux()## Start the heartbeat daemon...#start_heartbeat() { if ERROR=`$HA_BIN/heartbeat 2>&1` then : OK else return $? fi}## Start Linux-HA#StartHA() { EchoNoNl "Starting High-Availability services: " $HA_BIN/ResourceManager verifyallidle if [ $USE_MODULES = 1 ] then # Create /dev/watchdog and load module if we should init_watchdog fi rm -f $RUNDIR/ppp.d/* if [ -f $HA_DIR/ipresources -a ! -f $HA_DIR/haresources ] then mv $HA_DIR/ipresources $HA_DIR/haresources fi # Start heartbeat daemon if start_heartbeat then echo_success return 0 else RC=$? echo_failure $RC if [ ! -z "$ERROR" ]; then Echo Echo "$ERROR" fi return $RC fi}## Ask heartbeat to stop. It will give up its resources...#StopHA() { EchoNoNl "Stopping High-Availability services: " if $HA_BIN/heartbeat -k &> /dev/null # Kill it then echo_success return 0 else RC=$? echo_failure $RC return $RC fi}StatusHA() { $HA_BIN/heartbeat -s}StandbyHA() { auto_failback=`ha_parameter auto_failback | tr 'A-Z' 'a-z'` nice_failback=`ha_parameter nice_failback | tr 'A-Z' 'a-z'` case "$auto_failback" in *legacy*) echo "auto_failback is set to legacy. Cannot enter standby." exit 1;; esac case "$nice_failback" in *off*) echo "nice_failback is disabled. Cannot enter standby." exit 1;; esac case "${auto_failback}${nice_failback}" in "") echo "auto_failback defaulted to legacy. Cannot enter standby." exit 1;; esac echo "auto_failback: $auto_failback" if StatusHA >/dev/null 2>&1 then EchoNoNl "Attempting to enter standby mode" if $HA_BIN/hb_standby then # It's impossible to tell how long this will take. echo_success else echo_failure $? fi else Echo "Heartbeat is not currently running." exit 1 fi}## Ask heartbeat to restart. It will *keep* its resources#ReloadHA() { EchoNoNl "Reloading High-Availability services: " if $HA_BIN/heartbeat -r # Restart, and keep your resources then echo_success return 0 else RC=$? echo_failure $RC return $RC fi}RunStartStop() { # Run pre-startup script if it exists if [ -f $HA_DIR/resource.d/startstop ] then $HA_DIR/resource.d/startstop "$@" fi}RC=0# See how we were called.case "$1" in start) RunStartStop pre-start StartHA RC=$? Echo if [ $RC -eq 0 ] then [ ! -d $LOCKDIR ] && mkdir -p $LOCKDIR touch $LOCKDIR/$SUBSYS fi RunStartStop post-start $RC ;; standby) StandbyHA RC=$?;; status) StatusHA RC=$?;; stop) RunStartStop "pre-stop" StopHA RC=$? Echo if [ $RC -eq 0 ] then rm -f $LOCKDIR/$SUBSYS fi RunStartStop post-stop $RC ;; restart) sleeptime=`ha_parameter deadtime` StopHA Echo EchoNoNl Waiting to allow resource takeover to complete: sleep $sleeptime sleep 10 # allow resource takeover to complete (hopefully). echo_success Echo StartHA Echo ;; force-reload|reload) ReloadHA Echo RC=$? ;; *) Echo "Usage: $0 {start|stop|status|restart|reload|force-reload}" exit 1esacexit $RC### $Log: heartbeat.in,v $# Revision 1.36 2004/05/17 15:12:08 lars# Reverting over-eager approach to disabling old resource manager code.## Revision 1.35 2004/05/15 09:28:09 andrew# Disable ALL legacy resource management iff configured with --enable-crm# Possibly I have been a little over-zealous but likely the feature(s)# would need to be re-written to use the new design anyway.## Revision 1.34 2004/03/19 16:32:18 alan# Put in a fix which causes us to always load the watchdog timer module with nowayout=0## Revision 1.33 2004/02/08 09:32:30 alan# Fixed the standby option in the init script to handle the switch to# auto_failback correctly.## Revision 1.32 2004/01/20 15:35:09 alan# Removed some old SuSE-isms from the init script.## Revision 1.31 2003/08/13 04:36:56 alan# Put in a minor change from Tuomo Soini.## Revision 1.30 2003/06/16 03:50:48 alan# Fixed up the default start/stop levels for heartbeat## Revision 1.29 2003/05/08 19:46:32 alan# Fixed an init script incompatibility with current SuSE releases pointed out by# Markus Markert <mma@suchtreffer.de>.## Revision 1.28 2003/04/30 19:24:49 alan# Fixed a spelling error pointed out by Ozan Eren Bilgen <mavi@gsu.linux.org.tr>## Revision 1.27 2003/02/21 13:41:01 alan# Minor comment changes to the heartbeat init script.## Revision 1.26 2003/02/20 01:26:42 horms# Fixed problem with Description: feild.# Tuomo Soini reported an undisclosed problem with the current format# on an undisclosed version of Redhat. The change appears not to# go against LSB 1.3.0[*] which Alan modified this file to conform with the# other day.## [*] http://www2.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/initscrcomconv.html## Revision 1.25 2003/02/19 17:50:20 alan# Fixed a minor comment bug pointed out by LMB.## Revision 1.24 2003/02/18 04:32:09 alan# Added some comments to the heartbeat init script necessary for LSB# compatibility.## Revision 1.23 2002/10/21 10:17:18 horms# hb api clients may now be built outside of the heartbeat tree## Revision 1.22 2002/10/15 13:41:31 alan# Switched heartbeat over to use the GSource library functions.# Added the standby capability to the heartbeat init script# Changed the proctrack library code to use cl_log() instead of g_log().# Removed a few unused header files.## Revision 1.21 2002/10/11 03:13:09 horms# Minor cleanup of output from a "restart"## Revision 1.20 2002/10/09 18:37:07 msoffen# Left call directly to startstop script instead of the wrapper function.## Revision 1.19 2002/10/09 18:35:54 msoffen# Created pre-start, pre-stop, post-stop, and pre-stop constructs in startstop and# moved startstop to documents (to not override).## Revision 1.18 2002/09/20 02:13:20 horms# Tidied up the output for the restart and reload targets.# This follows what is done for start and stop.# Works fine on RedHat 7.2. Hopefully it won't break anything/much else.## Revision 1.17 2002/09/10 15:54:57 msoffen# Added call on startup (if startstop scrip exists) to startstop script (not# resource based - heartbeat startup/shutdown based).## Revision 1.16 2002/08/12 14:37:53 msoffen# Replaced the last echononl with EchoNoNl.## Revision 1.15 2002/04/03 20:02:21 alan# Made the init starting and stopping priorities into autoconf variables.# They default to 75 and 5 respectively. They should probably be overridden for# SuSE in the ConfigureMe script.## Revision 1.14 2002/04/02 19:40:36 alan# Failover was completely broken because of a typo in the configure.in file# Changed the run level priorities so that heartbeat starts after# drbd by default.# Changed it so that heartbeat by default runs in init level 5 too...## Fixed a problem which happened when both nodes started about simultaneously.# The result was that hb_standby wouldn't work afterwards.## Raised the debug level of some reasonably verbose messages so that you can# turn on debug 1 and not be flooded with log messages.## Changed the code so that in the case of nice_failback there is no waiting for# the other side to give up resources, because we negotiate this in advance.# It gets this information through and environment variable.## Revision 1.13 2002/03/21 02:03:00 alan# Added locking to the assignment of interfaces in IPaddr.## Revision 1.12 2002/03/05 21:13:06 alan# Put in fix suggested by Jo鉶 Miguel P. S
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -