#!/bin/sh # # High-Availability pgagent OCF resource agent # # Description: Starts/stops pgagent # Author: Oleg Selin # License: GNU General Public License (GPL) # # OCF parameters: # OCF_RESKEY_connection_string # OCF_RESKEY_user # OCF_RESKEY_options # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs OCF_RESKEY_executable_default="`which pgagent`" OCF_RESKEY_connection_string_default="user=postgres host=/var/run/postgresql" OCF_RESKEY_user_default="postgres" OCF_RESKEY_options_default="-r 1 -t 1" : ${OCF_RESKEY_executable="${OCF_RESKEY_executable_default}"} : ${OCF_RESKEY_connection_string="${OCF_RESKEY_connection_string_default}"} : ${OCF_RESKEY_user="${OCF_RESKEY_user_default}"} : ${OCF_RESKEY_options="${OCF_RESKEY_options_default}"} pgagent_validate_all() { check_binary pgagent ocf_log debug "executable: '$OCF_RESKEY_executable'" ocf_log debug "connection string: '$OCF_RESKEY_connection_string'" ocf_log debug "user: '$OCF_RESKEY_user'" ocf_log debug "options: '$OCF_RESKEY_options'" if [ -z "$OCF_RESKEY_connection_string" ]; then ocf_log err "Connection string is not configured!" exit $OCF_ERR_CONFIGURED fi if [ -z "$OCF_RESKEY_user" ]; then ocf_log err "User is not configured!" exit $OCF_ERR_CONFIGURED fi getent passwd $OCF_RESKEY_user >/dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_log err "User $OCF_RESKEY_user doesn't exist"; return $OCF_ERR_CONFIGURED; fi return $OCF_SUCCESS } pgagent_start() { pgagent_validate_all nohup su - $OCF_RESKEY_user -c "'$OCF_RESKEY_executable' $OCF_RESKEY_options '$OCF_RESKEY_connection_string'" > /dev/null 2>&1 & sleep 1 if pgagent_monitor; then return $OCF_SUCCESS fi return $OCF_ERR_GENERIC } pgagent_stop() { pgagent_validate_all pid=`pgrep -f -x -U $OCF_RESKEY_user "$OCF_RESKEY_executable $OCF_RESKEY_options $OCF_RESKEY_connection_string"` if [ -n "$pid" ]; then ocf_run kill $pid || return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } pgagent_monitor() { if [ -z "$OCF_RESKEY_executable" ]; then return $OCF_ERR_INSTALLED fi ocf_run pgrep -f -x -U "$OCF_RESKEY_user" "$OCF_RESKEY_executable $OCF_RESKEY_options $OCF_RESKEY_connection_string" || return $OCF_NOT_RUNNING return $OCF_SUCCESS } meta_data() { cat < 1.0 This is a pgagent Resource Agent. Controls pgagent Connection string for pgagent. pgagent connection string User to run pgagent as. User to run pgagent Options for pgagent. pgagent run options, see pgagent --help for details END } pgagent_usage() { cat <