diff --git a/src/sbd.service b/src/sbd.service new file mode 100644 index 0000000..450ceee --- /dev/null +++ b/src/sbd.service @@ -0,0 +1,24 @@ +[Unit] +Description=Shared-storage based fencing daemon +Before=pacemaker.service +After=corosync.service +PartOf=pacemaker.service +RefuseManualStop=true +RefuseManualStart=true + +[Service] +Type=forking +ExecStart=/usr/share/sbd/sbd.sh start +ExecStop=/usr/share/sbd/sbd.sh stop +PIDFile=/var/run/sbd.pid +Restart=no +# Could this benefit from exit codes for restart? +# Does this need to be set to msgwait * 1.2? +# TimeoutSec= +# If SBD crashes, it'll very likely suicide immediately due to the +# hardware watchdog. But one can always try. +Restart=on-abort + +[Install] +RequiredBy=pacemaker.service + diff --git a/src/sbd.sh b/src/sbd.sh new file mode 100644 index 0000000..eb7d81e --- /dev/null +++ b/src/sbd.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# +# Copyright (C) 2013 Lars Marowsky-Bree +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +SBD_CONFIG=/etc/sysconfig/sbd +SBD_BIN="/usr/sbin/sbd" + +test -x $SBD_BIN || exit 1 +test -f $SBD_CONFIG || exit 1 + +. $SBD_CONFIG + +unset LC_ALL; export LC_ALL +unset LANGUAGE; export LANGUAGE + +: ${OCF_ROOT:=/usr/lib/ocf} +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs + +# Construct commandline for some common options +if [ -z "$SBD_DEVICE" ]; then + echo "No sbd devices defined" + exit 1 +fi +SBD_DEVS=${SBD_DEVICE%;} +SBD_DEVICE=${SBD_DEVS//;/ -d } + +: ${SBD_PIDFILE:=/var/run/sbd.pid} +SBD_OPTS+=" -p $SBD_PIDFILE" +: ${SBD_PACEMAKER:="true"} +if ocf_is_true "$SBD_PACEMAKER" ; then + SBD_OPTS+=" -P" +fi +: ${SBD_WATCHDOG:="true"} +if ocf_is_true "$SBD_WATCHDOG" ; then + SBD_OPTS+=" -W" +fi +if [ -n "$SBD_WATCHDOG_DEV" ]; then + SBD_OPTS+="-w $SBD_WATCHDOG_DEV" +fi +: ${SBD_STARTMODE:="always"} +case "$SBD_STARTMODE" in +always) SBD_OPTS+=" -S 0" ;; +clean) SBD_OPTS+=" -S 1" ;; +esac + +start() { + if ! pidofproc -p $SBD_PIDFILE $SBD_BIN >/dev/null 2>&1 ; then + if ! $SBD_BIN -d $SBD_DEVICE $SBD_OPTS watch ; then + echo "SBD failed to start; aborting." + exit 1 + fi + else + return 0 + fi +} + +stop() { + if ! $SBD_BIN -d $SBD_DEVICE -D $SBD_OPTS message LOCAL exit ; then + echo "SBD failed to stop; aborting." + exit 1 + fi + while pidofproc -p $SBD_PIDFILE $SBD_BIN >/dev/null 2>&1 ; do + sleep 1 + done +} + +case "$1" in +start|stop) + $1 ;; +*) + echo "Usage: $0 (start|stop)" + exit 1 + ;; +esac + +# TODO: +# - Make openais init script call out to this script too +# - How to handle the former "force-start" option? +# force-start) +# SBD_OPTS="$SBD_OPTS -S 0" +# start +# ;; +