#!/bin/sh # # # Rsyslog # Description: Manages a Rsyslog service as a stateful Rsyslog OCF resource # Master -> Rsyslog runs as server and accepts syslog network packets # Slave -> Rsyslog runs as client # # # 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. # # Copyright (c) 2010 T-Systems GEI GmbH, Simon Jansen # All Rights Reserved. # ####################################################################### # # OCF Parameters: # OCF_RESKEY_binfile : Executable file # OCF_RESKEY_master_config : Configuration file for master # OCF_RESKEY_slave_config : Configuration file for slave # OCF_RESKEY_port : UDP port Rsyslog is listening on # OCF_RESKEY_pidfile : Process id file # OCF_RESKEY_further_params : Further parameters # OCF_RESKEY_nmap_binfile : Executable file of nmap # # Parameters with default values: OCF_RESKEY_binfile, # OCF_RESKEY_master_config, # OCF_RESKEY_slave_config, # OCF_RESKEY_port, # OCF_RESKEY_pidfile, # OCF_RESKEY_further_params, # OCF_RESKEY_nmap_binfile # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat} . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs CRM_MASTER="${HA_SBIN_DIR}/crm_master -l reboot" ####################################################################### #---------------------------------------------------------------------- # Definitions and default values #---------------------------------------------------------------------- # Define default values for parameters OCF_RESKEY_binfile_default="/usr/sbin/rsyslogd" OCF_RESKEY_master_config_default="/etc/rsyslog_master.conf" OCF_RESKEY_slave_config_default="/etc/rsyslog_slave.conf" OCF_RESKEY_port_default="514" OCF_RESKEY_pidfile_default="/var/run/rsyslogd.pid" OCF_RESKEY_nmap_binfile_default="/usr/bin/nmap" # Fill in defaults if no values are defined : ${OCF_RESKEY_binfile=${OCF_RESKEY_binfile_default}} : ${OCF_RESKEY_master_config=${OCF_RESKEY_master_config_default}} : ${OCF_RESKEY_slave_config=${OCF_RESKEY_slave_config_default}} : ${OCF_RESKEY_port=${OCF_RESKEY_port_default}} : ${OCF_RESKEY_pidfile=${OCF_RESKEY_pidfile_default}} : ${OCF_RESKEY_nmap_binfile=${OCF_RESKEY_nmap_binfile_default}} #---------------------------------------------------------------------- # Functions #---------------------------------------------------------------------- meta_data() { cat < 1.0 This is an OCF stateful resource agent to manage the Rsyslog service in a high-availability setup. In the master role the node starts the service with the master config and in the slave role with the slave config. The agent monitors the service in the master role via nmap by checking the status of the port Rsyslog is listening on. So you have to install nmap to use this RA. Manages a Rsyslog instance as a master/slave resource This parameter defines the executable file of the Rsyslog service. The default value is ${OCF_RESKEY_binfile_default}. Executable file This parameter defines the configuration file of the Rsyslog service in the master role. The default value is ${OCF_RESKEY_master_config_default}. Master configuration file This parameter defines the configuration file of the Rsyslog service in the slave role. The default value is ${OCF_RESKEY_slave_config_default}. Slave configuration file This parameter defines the UDP port Rsyslog is listening on. The port is defined in the configuration file. This value is only used to monitor the service via nmap. The default value is ${OCF_RESKEY_port_default}. UDP port Rsyslog is listening on This parameter defines the process id file of the Rsyslog service. The default value is ${OCF_RESKEY_pidfile_default}. Process id file This parameter defines additional parameters that are passed to the Rsyslog service during the startup. Further parameters This parameter defines the executable file of nmap. The default value is ${OCF_RESKEY_nmap_binfile_default}. Nmap executable file END } ####################################################################### Rsyslog_usage() { cat < /dev/null rc=$? if [ $rc != 0 ]; then ocf_log err "Rsyslog could not be stopped. Return value of /bin/kill: $rc." return $OCF_ERR_GENERIC fi rm -f ${OCF_RESKEY_pidfile} ocf_log info "Rsyslog service stopped." return $OCF_SUCCESS } Rsyslog_monitor() { # Check if Rsyslog is running # Check if process id file exists if [ ! -r ${OCF_RESKEY_pidfile} ]; then return $OCF_NOT_RUNNING fi # Check if process id in pidfile matches with output of ps if read pid < ${OCF_RESKEY_pidfile} && ps -p $pid > /dev/null 2>&1; then # Determine state with the output of ps PS_OUTPUT=`ps aux | grep rsyslogd` # Check if Rsyslog is running with master config if [ `expr match "$PS_OUTPUT" ".*$OCF_RESKEY_master_config.*"` != "0" ]; then # Check if Rsyslog is listening on port #NMAP_OUTPUT=`${OCF_RESKEY_nmap_binfile} -sU -p ${OCF_RESKEY_port} 127.0.0.1 | grep $OCF_RESKEY_port` #if [ `expr match "$NMAP_OUTPUT" ".*open.*"` != "0" ]; then return $OCF_RUNNING_MASTER #else # ocf_log err "Rsyslog seems to be running, but doesn't listen on UDP port ${OCF_RESKEY_port}." # return $OCF_ERR_GENERIC #fi else # Rsyslog is running as slave return $OCF_SUCCESS fi else ocf_log err "Rsyslog service is not running but the process id file exists." return $OCF_ERR_GENERIC fi return $OCF_NOT_RUNNING } Rsyslog_validate() { # Test if Rsyslog executable file exists and is executable if [ ! -x ${OCF_RESKEY_binfile} ]; then ocf_log err "Rsyslog binary $OCF_RESKEY_binfile does not exist or is not executable." return $OCF_ERR_INSTALLED fi # Test if configs exist if [ ! -f ${OCF_RESKEY_master_config} ]; then ocf_log err "Rsyslog master config file $OCF_RESKEY_master_config does not exist." return $OCF_ERR_CONFIGURED fi if [ ! -f ${OCF_RESKEY_slave_config} ]; then ocf_log err "Rsyslog slave config file $OCF_RESKEY_slave_config does not exist." return $OCF_ERR_CONFIGURED fi # Test if directory for pid file exists PID_DIR=`dirname ${OCF_RESKEY_pidfile}` if [ ! -d ${PID_DIR} ]; then ocf_log err "The directory to store the pid file does not exist." return $OCF_ERR_CONFIGURED fi # Test if portnumber is valid if ! ocf_is_decimal "$OCF_RESKEY_port" || [ $OCF_RESKEY_port -le 0 ]; then ocf_log err "Portnumber is invalid." return $OCF_ERR_CONFIGURED fi # Test if nmap executable file exists and is executable if [ ! -x ${OCF_RESKEY_nmap_binfile} ]; then ocf_log err "nmap binary $OCF_RESKEY_nmap_binfile does not exist or is not executable." return $OCF_ERR_INSTALLED fi return $OCF_SUCCESS } #---------------------------------------------------------------------- # Main script #---------------------------------------------------------------------- case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; usage|help) Rsyslog_usage exit $OCF_SUCCESS esac #Rsyslog_validate case $__OCF_ACTION in start) Rsyslog_start ;; promote) Rsyslog_promote ;; demote) Rsyslog_demote ;; stop) Rsyslog_stop ;; monitor) Rsyslog_monitor ;; validate-all) Rsyslog_validate ;; *) Rsyslog_usage exit $OCF_ERR_UNIMPLEMENTED;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc" exit $rc