#!/sbin/openrc-run extra_commands="failover" depend() { need net } chkconfig() { [ -z "${ROLES}" ] && { eerror "No role defined !"; return 1;} if [ "${FAILOVER}" -eq "1" ]; then [ -z "${FAILOVER_IP}" ] && { eerror "No failover ip defined !"; return 1;} [ -z "${IFACE}" ] && { eerror "No interface defined !"; return 1;} [ "${AUTORESTORE}" -ne "1" ] && { eerror "Autorestore must be enabled !"; return 1;} fi for ROLE in ${ROLES}; do if [ ! -f /etc/mfs/${ROLE}.cfg ]; then eerror "Missing configuration file for role ${ROLE} !" return 1 fi done return 0 } autorestore() { einfo "AUTORESTORE set, trying to restore metadata files" mfsmetarestore -a &>/dev/null return $? } start_role() { local ROLE=$1 local RETURN=0 ebegin "${ROLE}" start-stop-daemon -q --start --exec "${ROLE}" -- start >/dev/null RETURN=$? eend ${RETURN} return ${RETURN} } start_roles() { local RETURN=0 eindent for ROLE in ${ROLES}; do start_role ${ROLE} || RETURN=$? eend ${RETURN} if [ "${RETURN}" != "0" ] && [ "${ROLE}" == "mfsmaster" ] && [ ${AUTORESTORE} -eq 1 ]; then eindent autorestore && start_role ${ROLE} RETURN=$? eoutdent fi [ "${RETURN}" != "0" ] && break done eoutdent return ${RETURN} } start() { ebegin "Starting mfs node" chkconfig && start_roles eend $? } stop() { local RETURN=0 ebegin "Stopping mfs node" eindent local REVERSE=$(echo ${ROLES} | tac -s' ') for ROLE in ${REVERSE}; do ebegin "${ROLE}" start-stop-daemon -q --stop -n ${ROLE} || RETURN=$? eend ${RETURN} done eoutdent eend ${RETURN} } failover() { ebegin "Starting master migration" if ! ip addr | grep ${FAILOVER_IP} > /dev/null then ip addr add ${FAILOVER_IP}'/32' dev ${IFACE} fi start-stop-daemon -q --stop -n mfsmetalogger || RETURN=$? autorestore && start_role mfsmaster eend $? }