diff --git a/heartbeat/apache b/heartbeat/apache index ab7c43f9d..09d5ded49 100755 --- a/heartbeat/apache +++ b/heartbeat/apache @@ -1,655 +1,656 @@ #!/bin/sh # # High-Availability Apache/IBMhttp control script # # apache (aka IBMhttpd) # # Description: starts/stops apache web servers. # # Author: Alan Robertson # Sun Jiang Dong # # Support: linux-ha@lists.linux-ha.org # # License: GNU General Public License (GPL) # # Copyright: (C) 2002-2005 International Business Machines # # # An example usage in /etc/ha.d/haresources: # node1 10.0.0.170 apache::/opt/IBMHTTPServer/conf/httpd.conf # node1 10.0.0.170 IBMhttpd # # Our parsing of the Apache config files is very rudimentary. # It'll work with lots of different configurations - but not every # possible configuration. # # Patches are being accepted ;-) # # OCF parameters: # OCF_RESKEY_configfile # OCF_RESKEY_httpd # OCF_RESKEY_port # OCF_RESKEY_statusurl # OCF_RESKEY_options # OCF_RESKEY_testregex # OCF_RESKEY_client # OCF_RESKEY_testurl # OCF_RESKEY_testregex10 # OCF_RESKEY_testconffile # OCF_RESKEY_testname # OCF_RESKEY_envfiles : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs . ${OCF_FUNCTIONS_DIR}/apache-conf.sh . ${OCF_FUNCTIONS_DIR}/http-mon.sh HA_VARRUNDIR=${HA_VARRUN} ####################################################################### # # Configuration options - usually you don't need to change these # ####################################################################### # IBMHTTPD=/opt/IBMHTTPServer/bin/httpd HTTPDLIST="/sbin/httpd2 /usr/sbin/httpd2 /usr/sbin/apache2 /sbin/httpd /usr/sbin/httpd /usr/sbin/apache $IBMHTTPD" MPM=/usr/share/apache2/find_mpm if [ -x $MPM ]; then HTTPDLIST="$HTTPDLIST `$MPM 2>/dev/null`" fi LOCALHOST="http://localhost" HTTPDOPTS="-DSTATUS" DEFAULT_IBMCONFIG=/opt/IBMHTTPServer/conf/httpd.conf DEFAULT_SUSECONFIG="/etc/apache2/httpd.conf" DEFAULT_RHELCONFIG="/etc/httpd/conf/httpd.conf" # # You can also set # HTTPD # PORT # STATUSURL # CONFIGFILE # in this section if what we're doing doesn't work for you... # # End of Configuration options ####################################################################### CMD=`basename $0` # The config-file-pathname is the pathname to the configuration # file for this web server. Various appropriate defaults are # assumed if no config file is specified. If this command is # invoked as *IBM*, then the default config file name is # $DEFAULT_IBMCONFIG, otherwise the default config file # will be either $DEFAULT_RHELCONFIG or $DEFAULT_SUSECONFIG depending # on which is detected. usage() { cat <<-END usage: $0 action action: start start the web server stop stop the web server status return the status of web server, run or down monitor return TRUE if the web server appears to be working. For this to be supported you must configure mod_status and give it a server-status URL. You have to have installed either curl or wget for this to work. meta-data show meta data message validate-all validate the instance parameters END } get_pid() { if [ -f $PidFile ]; then cat $PidFile else false fi } # # return TRUE if a process with given PID is running # ProcessRunning() { local pid=$1 # Use /proc if it looks like it's here... if [ -d /proc -a -d /proc/1 ]; then [ -d /proc/$pid ] else # This assumes we're running as root... kill -s 0 "$pid" >/dev/null 2>&1 fi } silent_status() { local pid pid=`get_pid` if [ -n "$pid" ]; then ProcessRunning $pid else : No pid file false fi } # May be useful to add other distros in future validate_default_config() { if [ -e /etc/SuSE-release ]; then validate_default_suse_config else return 0 fi } # When using the default /etc/apache2/httpd.conf on SUSE, the file # /etc/apache2/sysconfig.d/include.conf is required to be present, # but this is only generated if you run the apache init script # (with contents derived from /etc/sysconfig/apache2). So, here, # if we're using the default system config file and it requires # that include, we run "/etc/init.d/apache2 configtest" to ensure # the relevant config is generated and valid. We're also taking # this opportunity to enable mod_status if it's not present. validate_default_suse_config() { if [ "$CONFIGFILE" = "$DEFAULT_SUSECONFIG" ] && \ grep -Eq '^Include[[:space:]]+/etc/apache2/sysconfig.d/include.conf' "$CONFIGFILE" then [ -x "/usr/sbin/a2enmod" ] && ocf_run -q /usr/sbin/a2enmod status # init script style, for crusty old SUSE if [ -e "/etc/init.d/apache2" ]; then ocf_run -q /etc/init.d/apache2 configtest || return 1 # systemd style, for shiny new SUSE elif [ -e "/usr/sbin/start_apache2" ]; then ocf_run -q /usr/sbin/start_apache2 -t || return 1 fi fi return 0 } apache_start() { if silent_status then ocf_log info "$CMD already running (pid `get_pid`)" return $OCF_SUCCESS fi validate_default_config || return $OCF_ERR_CONFIGURED # https://bugs.launchpad.net/ubuntu/+source/apache2/+bug/603211 [ -d /var/run/apache2 ] || mkdir /var/run/apache2 if [ -z $PIDFILE_DIRECTIVE ]; then ocf_run $HTTPD $HTTPDOPTS $OPTIONS -f $CONFIGFILE else ocf_run $HTTPD $HTTPDOPTS $OPTIONS -f $CONFIGFILE -c "PidFile $PidFile" fi tries=0 while : # wait until the user set timeout do apache_monitor ec=$? if [ $ec -eq $OCF_NOT_RUNNING ] then tries=`expr $tries + 1` ocf_log info "waiting for apache $CONFIGFILE to come up" sleep 1 else break fi done if [ $ec -ne 0 ] && silent_status; then apache_stop fi return $ec } signal_children() { for sig in SIGTERM SIGHUP SIGKILL ; do if pgrep -f $HTTPD.*$CONFIGFILE >/dev/null ; then pkill -$sig -f $HTTPD.*$CONFIGFILE >/dev/null ocf_log info "signal $sig sent to apache children" sleep 1 else break fi done } graceful_stop() { local tries=10 local pid=$1 # Try graceful stop for half timeout period if timeout period is present if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then tries=$((($OCF_RESKEY_CRM_meta_timeout/1000) / 2)) fi ocf_log info "Attempting graceful stop of apache PID $pid" kill -WINCH $pid >/dev/null while ProcessRunning $pid && [ $tries -gt 0 ] do sleep 1 tries=`expr $tries - 1` done if [ $tries -eq 0 ]; then # graceful stop didn't work, process still up. return 1 fi return 0 } kill_stop() { local tries=0 local pid=$1 ocf_log info "Killing apache PID $pid" while ProcessRunning $pid && [ $tries -lt 10 ] do if [ $tries -ne 0 ]; then # don't sleep on the first try sleep 1 fi kill $pid >/dev/null tries=`expr $tries + 1` done } apache_stop() { local ret=$OCF_SUCCESS local pid if ! silent_status; then ocf_log info "$CMD is not running." signal_children return $ret fi pid=`get_pid` graceful_stop $pid if [ $? -ne 0 ]; then kill_stop $pid if ProcessRunning $pid; then ocf_exit_reason "$CMD still running ($pid). Killing pid failed." ret=$OCF_ERR_GENERIC fi fi if [ $ret -eq 0 ]; then ocf_log info "$CMD stopped." fi signal_children return $ret } apache_monitor_10() { if [ "$TESTCONFFILE" ]; then readtestconf < $TESTCONFFILE else test_url="$TESTURL" test_regex="$TESTREGEX10" fi whattorun=`gethttpclient` fixtesturl is_testconf_sane || return $OCF_ERR_CONFIGURED if $whattorun "$test_url" | grep -Ei "$test_regex" > /dev/null then return $OCF_SUCCESS else if ! ocf_is_probe; then ocf_exit_reason "Failed to access httpd status page." fi return $OCF_ERR_GENERIC fi } # If the user has not provided any basic monitoring # information, allow the agent to verify the server is # healthy and capable of processing requests by requesting # the http header of website's index attempt_index_monitor_request() { local indexpage="" if [ -n "$OCF_RESKEY_testregex" ]; then return 1; fi if [ -n "$OCF_RESKEY_testregex10" ]; then return 1; fi if [ -n "$OCF_RESKEY_testurl" ]; then return 1; fi if [ -n "$OCF_RESKEY_statusurl" ]; then return 1; fi if [ -n "$OCF_RESKEY_testconffile" ]; then return 1; fi indexpage=$(buildlocalurl) request_url_header $indexpage if [ $? -ne 0 ]; then return $OCF_ERR_GENERIC fi ocf_log info "Successfully retrieved http header at $indexpage" return 0 } apache_monitor_basic() { if ${ourhttpclient}_func "$STATUSURL" | grep -Ei "$TESTREGEX" > /dev/null then return $OCF_SUCCESS fi attempt_index_monitor_request if [ $? -eq 0 ]; then return $OCF_SUCCESS fi if ! ocf_is_probe; then ocf_exit_reason "Failed to access httpd status page." fi return $OCF_ERR_GENERIC } apache_monitor() { silent_status if [ $? -ne 0 ]; then ocf_log info "$CMD not running" return $OCF_NOT_RUNNING fi ourhttpclient=`findhttpclient` # we'll need one if [ -z "$ourhttpclient" ]; then ocf_exit_reason "could not find a http client; make sure that either wget or curl is available" return $OCF_ERR_INSTALLED fi case `ocf_check_level 10` in 0) apache_monitor_basic;; 10) apache_monitor_10;; esac } detect_default_config() { if [ -f $DEFAULT_SUSECONFIG ]; then echo $DEFAULT_SUSECONFIG else echo $DEFAULT_RHELCONFIG fi } apache_meta_data(){ cat < 1.0 This is the resource agent for the Apache Web server. This resource agent operates both version 1.x and version 2.x Apache servers. The start operation ends with a loop in which monitor is repeatedly called to make sure that the server started and that it is operational. Hence, if the monitor operation does not succeed within the start operation timeout, the apache resource will end with an error status. The monitor operation by default loads the server status page which depends on the mod_status module and the corresponding configuration file (usually /etc/apache2/mod_status.conf). Make sure that the server status page works and that the access is allowed *only* from localhost (address 127.0.0.1). See the statusurl and testregex attributes for more details. See also http://httpd.apache.org/ Manages an Apache Web server instance The full pathname of the Apache configuration file. This file is parsed to provide defaults for various other resource agent parameters. configuration file path The full pathname of the httpd binary (optional). httpd binary path A port number that we can probe for status information using the statusurl. This will default to the port number found in the configuration file, or 80, if none can be found in the configuration file. httpd port The URL to monitor (the apache server status page by default). If left unspecified, it will be inferred from the apache configuration file. If you set this, make sure that it succeeds *only* from the localhost (127.0.0.1). Otherwise, it may happen that the cluster complains about the resource being active on multiple nodes. url name Regular expression to match in the output of statusurl. Case insensitive. monitor regular expression Client to use to query to Apache. If not specified, the RA will try to find one on the system. Currently, wget and curl are supported. For example, you can set this parameter to "curl" if you prefer that to wget. http client URL to test. If it does not start with "http", then it's considered to be relative to the Listen address. test url Regular expression to match in the output of testurl. Case insensitive. extended monitor regular expression A file which contains test configuration. Could be useful if you have to check more than one web application or in case sensitive info should be passed as arguments (passwords). Furthermore, using a config file is the only way to specify certain parameters. Please see README.webapps for examples and file description. test configuration file Name of the test within the test configuration file. test name Extra options to apply when starting apache. See man httpd(8). command line options Files (one or more) which contain extra environment variables. If you want to prevent script from reading the default file, set this parameter to empty string. environment settings files We will try to detect if the URL (for monitor) is IPv6, but if that doesn't work set this to true to enforce IPv6. use ipv6 with http clients END return $OCF_SUCCESS } apache_validate_all() { if [ -z "$HTTPD" ]; then ocf_exit_reason "apache httpd program not found" return $OCF_ERR_INSTALLED fi if [ ! -x "$HTTPD" ]; then ocf_exit_reason "HTTPD $HTTPD not found or is not an executable!" return $OCF_ERR_INSTALLED fi if [ ! -f $CONFIGFILE ]; then ocf_exit_reason "Configuration file $CONFIGFILE not found!" return $OCF_ERR_INSTALLED fi + ocf_mkstatedir root 755 `dirname $PidFile` || return $OCF_ERR_INSTALLED return $OCF_SUCCESS } find_httpd_prog() { case $0 in *IBM*) HTTPD=$IBMHTTPD DefaultConfig=$DEFAULT_IBMCONFIG;; *) HTTPD= for h in $HTTPDLIST do if [ -f $h -a -x $h ]; then HTTPD=$h break fi done # Let the user know that the $HTTPD used is not the one (s)he specified via $OCF_RESKEY_httpd if [ "X$OCF_RESKEY_httpd" != X -a "X$HTTPD" != X ]; then ocf_log info "Using $HTTPD as HTTPD" fi DefaultConfig=$(detect_default_config) ;; esac } apache_getconfig() { # these variables are global HTTPD="$OCF_RESKEY_httpd" PORT="$OCF_RESKEY_port" STATUSURL="$OCF_RESKEY_statusurl" CONFIGFILE="$OCF_RESKEY_configfile" OPTIONS="$OCF_RESKEY_options" CLIENT=${OCF_RESKEY_client} TESTREGEX=${OCF_RESKEY_testregex:-''} TESTURL="$OCF_RESKEY_testurl" TESTREGEX10=${OCF_RESKEY_testregex10} TESTCONFFILE="$OCF_RESKEY_testconffile" TESTNAME="$OCF_RESKEY_testname" : ${OCF_RESKEY_envfiles="/etc/apache2/envvars"} source_envfiles $OCF_RESKEY_envfiles if [ "X$HTTPD" = X -o ! -f "$HTTPD" -o ! -x "$HTTPD" ]; then find_httpd_prog fi CONFIGFILE=${CONFIGFILE:-$DefaultConfig} if [ -n "$HTTPD" ]; then httpd_basename=`basename $HTTPD` case $httpd_basename in *-*) httpd_basename=`echo "$httpd_basename" | sed -e 's%\-.*%%'`;; esac fi GetParams $CONFIGFILE } OCF_REQUIRED_PARAMS="" OCF_REQUIRED_BINARIES="" ocf_rarun $* diff --git a/heartbeat/named b/heartbeat/named index 2c34a15c2..2118e0c4d 100755 --- a/heartbeat/named +++ b/heartbeat/named @@ -1,489 +1,494 @@ #!/bin/sh # # Description: Manages a named (Bind) server as an OCF High-Availability # resource # # Authors: Serge Dubrouski (sergeyfd@gmail.com) # # Copyright: 2011 Serge Dubrouski # # License: GNU General Public License (GPL) # ############################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs #Defaults OCF_RESKEY_named_default="/usr/sbin/named" OCF_RESKEY_rndc_default="/usr/sbin/rndc" OCF_RESKEY_host_default="/usr/bin/host" OCF_RESKEY_named_user_default=named OCF_RESKEY_named_config_default="" OCF_RESKEY_named_pidfile_default="/var/run/named/named.pid" OCF_RESKEY_named_rootdir_default="" OCF_RESKEY_named_options_default="" OCF_RESKEY_named_keytab_file_default="" OCF_RESKEY_monitor_request_default="localhost" OCF_RESKEY_monitor_response_default="127.0.0.1" OCF_RESKEY_monitor_ip_default="127.0.0.1" : ${OCF_RESKEY_named=${OCF_RESKEY_named_default}} : ${OCF_RESKEY_rndc=${OCF_RESKEY_rndc_default}} : ${OCF_RESKEY_host=${OCF_RESKEY_host_default}} : ${OCF_RESKEY_named_user=${OCF_RESKEY_named_user_default}} : ${OCF_RESKEY_named_config=${OCF_RESKEY_named_config_default}} : ${OCF_RESKEY_named_pidfile=${OCF_RESKEY_named_pidfile_default}} : ${OCF_RESKEY_named_rootdir=${OCF_RESKEY_named_rootdir_default}} : ${OCF_RESKEY_named_options=${OCF_RESKEY_named_options_default}} : ${OCF_RESKEY_named_keytab_file=${OCF_RESKEY_named_keytab_file_default}} : ${OCF_RESKEY_monitor_request=${OCF_RESKEY_monitor_request_default}} : ${OCF_RESKEY_monitor_response=${OCF_RESKEY_monitor_response_default}} : ${OCF_RESKEY_monitor_ip=${OCF_RESKEY_monitor_ip_default}} usage() { cat < 1.0 Resource script for named (Bind) server. It manages named as an HA resource. Manages a named server Path to the named command. named Path to the rndc command. rndc Path to the host command. host User that should own named process. named_user Configuration file for named. named_config PIDFILE file for named. named_pidfile Directory that named should use for chroot if any. named_rootdir Options for named process if any. named_options named service keytab file (for GSS-TSIG). named_keytab_file Request that shall be sent to named for monitoring. Usually an A record in DNS. monitor_request Expected response from named server. monitor_response IP Address where named listens. monitor_ip EOF } # # methods: What methods/operations do we support? # named_methods() { cat </dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_exit_reason "User $OCF_RESKEY_named_user doesn't exist"; return $OCF_ERR_INSTALLED; fi if [ -z "$OCF_RESKEY_monitor_request" -o \ -z "$OCF_RESKEY_monitor_response" -o \ -z "$OCF_RESKEY_monitor_ip" ]; then ocf_exit_reason "None of monitor_request, monitor_response, and monitor_ip can be empty" return $OCF_ERR_CONFIGURED fi + # make sure that the pidfile directory exists + ocf_mkstatedir $OCF_RESKEY_named_user 755 `dirname $OCF_RESKEY_named_pidfile` || return $OCF_ERR_INSTALLED + return $OCF_SUCCESS } ## # Attempt to generate a /etc/rndc.key if one is not present ## rndc_key_generator() { local rndc_options="-a -r /dev/urandom -u $OCF_RESKEY_named_user" if [ -s /etc/rndc.key ]; then # file already exists return fi if ! have_binary "rndc-confgen"; then # can't autogen key... Report this, but not as a warning or error. # It is possible that the user configured the key in named.conf ocf_log info "rndc-confgen tool not present, unable to autogen /etc/rndc.key." return fi if [ -n "$OCF_RESKEY_rootdir" ]; then rndc_options="$rndc_options -t $OCF_RESKEY_rootdir" fi rndc-confgen $rndc_options > /dev/null 2>&1; if [ $? -eq 0 ]; then if have_binary "restorecon"; then restorecon /etc/rndc.key fi else ocf_log info "failed to auto-generate /etc/rndc.key file." fi } # # named_getpid. Get pid of named process with a given parameters. # named_getpid () { local pattern="$OCF_RESKEY_named" if [ -n "$OCF_RESKEY_named_rootdir" -a "x${OCF_RESKEY_named_rootdir}" != "x/" ]; then pattern="$pattern.*-t $OCF_RESKEY_named_rootdir" fi if [ -n "$OCF_RESKEY_named_config" ]; then pattern="$pattern.*-c $OCF_RESKEY_named_config" fi pid=`pgrep -f "$pattern"` echo $pid } # # named_status. Simple check of the status of named process by pidfile. # named_status () { ocf_pidfile_status ${OCF_RESKEY_named_pidfile} >/dev/null 2>&1 } # # named_monitor. Send a request to named and check response. # named_monitor() { local output if ! named_status then ocf_log info "named is down" return $OCF_NOT_RUNNING fi output=`$OCF_RESKEY_host $OCF_RESKEY_monitor_request $OCF_RESKEY_monitor_ip` if [ $? -ne 0 ] || ! echo $output | grep -q '.* has .*address '"$OCF_RESKEY_monitor_response" then ocf_exit_reason "named didn't answer properly for $OCF_RESKEY_monitor_request." ocf_log err "Expected: $OCF_RESKEY_monitor_response." ocf_log err "Got: $output" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } # # Reload # named_reload() { $OCF_RESKEY_rndc reload >/dev/null || return $OCF_ERR_GENERIC return $OCF_SUCCESS } # # Start # named_start() { local root_dir_opt local pid root_dir_opt="" named_status && return $OCF_SUCCESS # Remove pidfile if exists rm -f ${OCF_RESKEY_named_pidfile} if [ -n "${OCF_RESKEY_named_rootdir}" -a "x${OCF_RESKEY_named_rootdir}" != "x/" ] then root_dir_opt="-t ${OCF_RESKEY_named_rootdir}" [ -s /etc/localtime ] && cp -fp /etc/localtime ${OCF_RESKEY_named_rootdir}/etc/localtime fi if [ -n "$OCF_RESKEY_named_config" ]; then OCF_RESKEY_named_options="-c $OCF_RESKEY_named_config $OCF_RESKEY_named_options" fi rndc_key_generator if ! ${OCF_RESKEY_named} -u ${OCF_RESKEY_named_user} $root_dir_opt ${OCF_RESKEY_named_options} then ocf_exit_reason "named failed to start." return $OCF_ERR_GENERIC fi pid=`named_getpid` if [ -n "$pid" ]; then if [ ! -e ${OCF_RESKEY_named_pidfile} ]; then echo $pid > ${OCF_RESKEY_named_pidfile} fi else ocf_exit_reason "named failed to start. Probably error in configuration." return $OCF_ERR_GENERIC fi while : do named_monitor && break sleep 1 ocf_log debug "named hasn't started yet." done ocf_log info "named has started." return $OCF_SUCCESS } # # Stop # named_stop () { local timeout local timewait named_status || return $OCF_SUCCESS $OCF_RESKEY_rndc stop >/dev/null if [ $? -ne 0 ]; then ocf_log info "rndc stop failed. Killing named." kill `cat ${OCF_RESKEY_named_pidfile}` fi if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then # Allow 2/3 of the action timeout for the orderly shutdown # (The origin unit is ms, hence the conversion) timewait=$((OCF_RESKEY_CRM_meta_timeout/1500)) else timewait=20 fi sleep 1; timeout=0 # Sleep here for 1 sec to let rndc finish. while named_status ; do if [ $timeout -ge $timewait ]; then break else sleep 1 timeout=`expr $timeout + 1` ocf_log debug "named appears to hung, waiting ..." fi done #If still up if named_status 2>&1; then ocf_exit_reason "named is still up! Killing" kill -9 `cat ${OCF_RESKEY_named_pidfile}` fi rm -f ${OCF_RESKEY_named_pidfile} return $OCF_SUCCESS } # Main part if [ $# -ne 1 ]; then usage exit $OCF_ERR_GENERIC fi case "$1" in methods) named_methods exit $?;; meta-data) named_meta_data exit $OCF_SUCCESS;; esac named_validate_all rc=$? [ "$1" = "validate-all" ] && exit $rc if [ $rc -ne 0 ] then case "$1" in stop) exit $OCF_SUCCESS;; monitor) exit $OCF_NOT_RUNNING;; status) exit $OCF_NOT_RUNNING;; *) exit $rc;; esac fi if [ `id -u` -ne 0 ]; then ocf_exit_reason "$0 must be run as root" exit $OCF_ERR_GENERIC fi case "$1" in status) if named_status then ocf_log info "named is up" exit $OCF_SUCCESS else ocf_log info "named is down" exit $OCF_NOT_RUNNING fi;; monitor) named_monitor exit $?;; start) named_start exit $?;; stop) named_stop exit $?;; reload) named_reload exit $?;; *) exit $OCF_ERR_UNIMPLEMENTED;; esac + +# vim:ts=4:sw=4:et: diff --git a/heartbeat/zabbixserver b/heartbeat/zabbixserver index fe7266ec5..4513141e6 100755 --- a/heartbeat/zabbixserver +++ b/heartbeat/zabbixserver @@ -1,336 +1,315 @@ #!/bin/sh # # # zabbixserver OCF RA for zabbix_server daemon # # Copyright (c) 2012 Krzysztof Gajdemski # All Rights Reserved. # # 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_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs ####################################################################### # # Defaults # OCF_RESKEY_binary_default="zabbix_server" OCF_RESKEY_pid_default="/var/run/zabbix-server/zabbix_server.pid" OCF_RESKEY_config_default="" : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} : ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} : ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} # sleep interval when waiting for threads cleanup sleepint=1 # # Functions # zabbixserver_meta_data() { cat < 0.0.1 This is a Zabbix server Resource Agent for zabbix_server monitoring daemon. See: http://www.zabbix.com/ Zabbix server resource agent Location of the zabbix_server binary. Zabbix server binary Path to zabbix_server pidfile. As it's created by daemon itself it must be the same as specified in the Zabbix configuration file with parameter 'PidFile='. Path to pidfile Path to zabbix_server configuration file. Assumed server default if not specified. Path to configuration file END } ####################################################################### zabbixserver_usage() { cat < /dev/null 1>&2 } # # start the agent # zabbixserver_start() { local rc # check the resource status zabbixserver_monitor rc=$? case "$rc" in $OCF_SUCCESS) ocf_log info "Resource is already running" return $OCF_SUCCESS ;; $OCF_NOT_RUNNING) ;; *) exit $OCF_ERR_GENERIC ;; esac # remove stale pidfile if it exists if [ -f $OCF_RESKEY_pid ]; then ocf_log info "Removing stale pidfile" rm $OCF_RESKEY_pid fi startserver if [ $? -ne 0 ]; then ocf_log err "Can't start Zabbix server" return $OCF_ERR_GENERIC fi # wait if it starts really while ! zabbixserver_monitor; do ocf_log debug "Resource has not started yet, waiting" sleep $sleepint done return $OCF_SUCCESS } # # stop the agent # zabbixserver_stop() { local pid local rc # check the resource status zabbixserver_monitor rc=$? case "$rc" in $OCF_SUCCESS) ;; $OCF_NOT_RUNNING) ocf_log info "Resource is already stopped" return $OCF_SUCCESS ;; *) exit $OCF_ERR_GENERIC ;; esac pid=`getpid $OCF_RESKEY_pid` if [ $? -ne 0 ]; then ocf_log err "Can't find process PID" return $OCF_ERR_GENERIC fi # kill the process ocf_run -q kill $pid if [ $? -ne 0 ]; then ocf_log err "Can't stop process (PID $pid)" return $OCF_ERR_GENERIC fi # Wait until the parent process terminates. # NOTE: The parent may be still waiting for its children. A regular monitor # function will not detect this condition because the pidfile may be # removed just now. while process_status $pid; do ocf_log debug "Waiting for process to terminate..." sleep $sleepint done # wait if it stops really while zabbixserver_monitor; do ocf_log debug "Resource has not stopped yet, waiting" sleep $sleepint done # remove stale pidfile if it exists if [ -f $OCF_RESKEY_pid ]; then ocf_log debug "Pidfile still exists, removing" rm $OCF_RESKEY_pid fi return $OCF_SUCCESS } # # resource monitor # zabbixserver_monitor() { local pid pid=`getpid $OCF_RESKEY_pid` if [ $? -eq 0 ]; then process_status $pid if [ $? -eq 0 ]; then ocf_log debug "Resource is running" return $OCF_SUCCESS fi fi ocf_log info "Resource is not running" return $OCF_NOT_RUNNING } # # validate configuration # zabbixserver_validate_all() { - check_piddir || return $OCF_ERR_INSTALLED check_config $OCF_RESKEY_config || return $OCF_ERR_INSTALLED - + ocf_mkstatedir root 755 `dirname $OCF_RESKEY_pid` || return $OCF_ERR_INSTALLED return $OCF_SUCCESS } # # main # OCF_REQUIRED_PARAMS="" OCF_REQUIRED_BINARIES="$OCF_RESKEY_binary" ocf_rarun $*