#!/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_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 $*