#!/bin/sh ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs if [ ! -z $OCF_RESKEY_binfile ]; then basename=`basename ${OCF_RESKEY_binfile} .pl` OCF_RESKEY_pidfile_default=/var/run/${basename}.pid OCF_RESKEY_logfile_default=/var/log/${basename}.log fi OCF_RESKEY_external_pidfile_default=0 OCF_RESKEY_core_dump_default=0 : ${OCF_RESKEY_pidfile=$OCF_RESKEY_pidfile_default} : ${OCF_RESKEY_logfile=$OCF_RESKEY_logfile_default} : ${OCF_RESKEY_external_pidfile=$OCF_RESKEY_external_pidfile_default} : ${OCF_RESKEY_core_dump=$OCF_RESKEY_core_dump_default} ####################################################################### generic_usage() { cat < 1.0 Resource agent for any script Resource agent for any script The full name of the binary to be executed. Full path name of the binary to be executed Command line options to pass to the binary Command line options Path to pidfile. Default is: /var/run/\${basename}.pid Path to pidfile Path to logfile. Default is: /var/log/\${basename}.log Path to logfile Write pidfile by ocf-agent, not running script. Who writes pidfile Set core file size limit to unlimited. Write core dump or not END } generic_start() { generic_validate || return $? generic_monitor && return $? if ocf_is_true $OCF_RESKEY_core_dump; then ulimit -c unlimited || return $OCF_ERR_GENERIC fi local cmd="$OCF_RESKEY_binfile $OCF_RESKEY_options" ocf_log debug "Running $cmd" $cmd >>$OCF_RESKEY_logfile 2>>$OCF_RESKEY_logfile $OCF_RESKEY_pidfile fi while ! generic_monitor; do if kill -0 $pid 2>/dev/null; then sleep 1 else return $OCF_ERR_GENERIC fi done return $OCF_SUCCESS } generic_stop() { generic_monitor if [ $? == $OCF_NOT_RUNNING ]; then return $OCF_SUCCESS fi local pid=`cat $OCF_RESKEY_pidfile` kill -TERM $pid while kill -0 $pid 2>/dev/null; do sleep 1 done generic_monitor >/dev/null if [ $? == $OCF_NOT_RUNNING ]; then return $OCF_SUCCESS else return $OCF_ERR_GENERIC fi } generic_monitor_light() { ocf_pidfile_status $OCF_RESKEY_pidfile case $? in 0) return $OCF_SUCCESS;; 1) if ! ocf_is_true $OCF_RESKEY_external_pidfile; then ocf_log warn "Process exited without cleaning up its pidfile, maybe it died" fi rm -f $OCF_RESKEY_pidfile return $OCF_NOT_RUNNING ;; 2) return $OCF_NOT_RUNNING;; *) return $OCF_ERR_GENERIC;; esac } generic_monitor_medium() { generic_monitor_light || return $? local pid=`cat $OCF_RESKEY_pidfile` local lines=$(stat -c %N /proc/$pid/fd/[12] | grep "\`$OCF_RESKEY_logfile'" | wc -l) if [ $lines != 2 ]; then ocf_log warn "stdin or stdout file descriptor is not pointing to logfile, sending HUP" kill -HUP $pid fi if echo ping | nc localhost ${OCF_RESKEY_admin_console_port} | grep Ok >/dev/null; then return $OCF_SUCCESS else ocf_log err "admin_console_port ping failed" return $OCF_ERR_GENERIC fi } generic_monitor() { if [ $OCF_CHECK_LEVEL -lt 10 ]; then generic_monitor_light else generic_monitor_medium fi return $? } generic_validate() { check_binary $OCF_RESKEY_binfile return $OCF_SUCCESS } case $__OCF_ACTION in meta-data) generic_meta exit $OCF_SUCCESS ;; start) generic_start;; stop) generic_stop;; monitor) generic_monitor;; validate-all) generic_validate;; usage|help) generic_usage exit $OCF_SUCCESS ;; *) generic_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc" exit $rc