#!/bin/sh # Keepalived resource agent. # # Copyright (c) 2011 University of Manchester # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs ####################################################################### meta_data() { cat < 1.0 This resource agent manages a keepalived process. manages keepalived END } ####################################################################### # don't exit on TERM, to test that lrmd makes sure that we do exit trap sigterm_handler TERM sigterm_handler() { ocf_log info "They use TERM to bring us down. No such luck." return } keepalive_usage() { cat </dev/null 2>&1 sleep 5 keepalive_monitor if [ $? = $OCF_SUCCESS ]; then return $OCF_SUCCESS fi return $OCF_NOT_RUNNING } keepalive_stop() { keepalive_monitor if [ $? = $OCF_SUCCESS ]; then /etc/init.d/keepalived stop >/dev/null 2>&1 fi sleep 5 keepalive_monitor if [ $? = $OCF_SUCCESS ]; then return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } keepalive_monitor() { # Monitor _MUST!_ differentiate correctly between running # (SUCCESS), failed (ERROR) or _cleanly_ stopped (NOT RUNNING). # That is THREE states, not just yes/no. if [ ! -r /var/run/keepalived.pid ] then return $OCF_NOT_RUNNING fi if ps -c -p `cat /var/run/keepalived.pid `|grep keepalived >/dev/null 2>&1 then return $OCF_SUCCESS fi return $OCF_NOT_RUNNING } keepalive_validate() { return $OCF_SUCCESS } case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) keepalive_start exit $?;; stop) keepalive_stop exit $?;; monitor) keepalive_monitor exit $?;; migrate_to) ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrate_target}." keepalive_stop exit $?;; migrate_from) ocf_log info "Migrating ${OCF_RESOURCE_INSTANCE} to ${OCF_RESKEY_CRM_meta_migrate_source}." keepalive_start exit $?;; reload) ocf_log err "Reloading..." keepalive_stop keepalive_start exit $?;; validate-all) keepalive_validate exit $?;; usage|help) keepalive_usage exit $OCF_SUCCESS ;; *) keepalive_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc" exit $rc