#!/bin/sh # # Description: Manages a OpenDJ Server as an OCF High-Availability # resource under Heartbeat/LinuxHA control # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # # Copyright (c) 2011 Jamie L Sammons # ####################################################################### # OCF parameters: # OCF_RESKEY_opendj_name - The name of the resource. Default is opendj # OCF_RESKEY_opendj_stop_timeout - Time-out at the time of the stop. Default is 5 # OCF_RESKEY_opendj_user - A user name to start a resource. Default is root # OCF_RESKEY_opendj_port - URL for state confirmation. Default is 389 # OCF_RESKEY_opendj_home - Home directory of OpenDJ. Default is None # OCF_RESKEY_opendj_pid - A PID file name of OpenDJ. Default is OCF_RESKEY_opendj_home/logs/opendj.pid ############################################################################### : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat} . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs ############################################################################ # Usage usage() { cat <<-! usage: $0 action action: start start opendj stop stop the opendj status return the status of opendj, run or down monitor return TRUE if the opendj appears to be working. You have to have installed $WGETNAME for this to work. meta-data show meta data message validate-all validate the instance parameters ! } ############################################################################ # Check opendj service availability isrunning_opendj() { if ! have_binary $OPENDJ_HOME/bin/ldapsearch; then ocf_log err "Monitoring not supported by $OCF_RESOURCE_INSTANCE" return $OCF_ERR_CONFIGURED fi $OPENDJ_HOME/bin/ldapsearch --hostname localhost --port ${RESOURCE_opendj_port} --baseDN "" --searchScope base "(objectClass=*)" >/dev/null 2>&1 } ############################################################################ # isalive_opendj() { pgrep -f "opends" > /dev/null } ############################################################################ # Check opendj process and service availability monitor_opendj() { isalive_opendj || return $OCF_NOT_RUNNING isrunning_opendj || return $OCF_NOT_RUNNING return $OCF_SUCCESS } ############################################################################ # Start OpenDJ start_opendj() { cd "$OPENDJ_HOME/bin" monitor_opendj if [ $? = $OCF_SUCCESS ]; then return $OCF_SUCCESS fi echo "`date "+%Y/%m/%d %T"`: start ===========================" >> "$OPENDJ_CONSOLE" su - -s /bin/sh "$RESOURCE_OPENDJ_USER" \ -c "$OPENDJ_HOME/bin/start-ds" \ >> "$OPENDJ_CONSOLE" 2>&1 & while true; do monitor_opendj if [ $? = $OCF_SUCCESS ]; then break fi ocf_log debug "start_opendj[$OPENDJ_NAME]: retry monitor_opendj" sleep 3 done return $OCF_SUCCESS } ############################################################################ # Stop OpenDJ stop_opendj() { cd "$OPENDJ_HOME/bin" echo "`date "+%Y/%m/%d %T"`: stop ###########################" >> "$OPENDJ_CONSOLE" su - -s /bin/sh "$RESOURCE_OPENDJ_USER" \ -c "$OPENDJ_HOME/bin/stop-ds" \ >> "$OPENDJ_CONSOLE" 2>&1 lapse_sec=0 while isalive_opendj; do sleep 1 lapse_sec=`expr $lapse_sec + 1` ocf_log debug "stop_opendj[$OPENDJ_NAME]: stop NORM $lapse_sec/$OPENDJ_STOP_TIMEOUT" if [ $lapse_sec -ge $OPENDJ_STOP_TIMEOUT ]; then break fi done if isalive_opendj; then lapse_sec=0 while true; do sleep 1 lapse_sec=`expr $lapse_sec + 1` ocf_log debug "stop_opendj[$OPENDJ_NAME]: suspend opendj by SIGTERM ($lapse_sec/$OPENDJ_SUSPEND_TRIALCOUNT)" pkill -TERM -f "${SEARCH_STR}" if isalive_opendj; then ocf_log debug "stop_opendj[$OPENDJ_NAME]: suspend opendj by SIGQUIT ($lapse_sec/$OPENDJ_SUSPEND_TRIALCOUNT)" pkill -QUIT -f "${SEARCH_STR}" if isalive_opendj; then if [ $lapse_sec -ge $OPENDJ_SUSPEND_TRIALCOUNT ]; then break fi else break fi else break fi done fi lapse_sec=0 while isalive_opendj; do sleep 1 lapse_sec=`expr $lapse_sec + 1` ocf_log debug "stop_opendj[$OPENDJ_NAME]: suspend opendj by SIGKILL ($lapse_sec)" pkill -KILL -f "${SEARCH_STR}" done rm -f "$OPENDJ_PID" return $OCF_SUCCESS } status_opendj() { return $OCF_SUCCESS } metadata_opendj() { cat < 1.0 Resource script for opendj. It manages a OpenDJ instance as an HA resource. Manages a OpenDJ servlet environment instance The name of the resource The name of the resource Time-out at the time of the stop Time-out at the time of the stop A user name to start a resource A user name to start a resource ldap port for state confirmation ldap port for state confirmation Home directory of OpenDJ Home directory of OpenDJ A PID file name of OpenDJ A PID file name of OpenDJ END return $OCF_SUCCESS } validate_all_opendj() { ocf_log info "validate_all_opendj[$OPENDJ_NAME]" return $OCF_SUCCESS } # ### opendj RA environment variables # OPENDJ_NAME="${OCF_RESKEY_opendj_name-opendj}" OPENDJ_CONSOLE="${OCF_RESKEY_script_log-/var/log/$OPENDJ_NAME.log}" OPENDJ_STOP_TIMEOUT="${OCF_RESKEY_opendj_stop_timeout-5}" RESOURCE_OPENDJ_USER="${OCF_RESKEY_opendj_user-opendj}" RESOURCE_opendj_port="${OCF_RESKEY_opendj_port-389}" SEARCH_STR="\\""${OPENDJ_NAME}" OPENDJ_HOME="${OCF_RESKEY_opendj_home}" OPENDJ_PID="${OCF_RESKEY_opendj_pid-$OPENDJ_HOME/logs/server.pid}" export OPENDJ_HOME OPENDJ_PID OPENDJ_OPTS # # ------------------ # the main script # ------------------ # COMMAND=$1 case "$COMMAND" in start) ocf_log debug "[$OPENDJ_NAME] Enter opendj start" start_opendj func_status=$? ocf_log debug "[$OPENDJ_NAME] Leave opendj start $func_status" exit $func_status ;; stop) ocf_log debug "[$OPENDJ_NAME] Enter opendj stop" stop_opendj func_status=$? ocf_log debug "[$OPENDJ_NAME] Leave opendj stop $func_status" exit $func_status ;; status) status_opendj exit $? ;; monitor) #ocf_log debug "[$OPENDJ_NAME] Enter opendj monitor" monitor_opendj func_status=$? #ocf_log debug "[$OPENDJ_NAME] Leave opendj monitor $func_status" exit $func_status ;; meta-data) metadata_opendj exit $? ;; validate-all) validate_all_opendj exit $? ;; usage|help) usage exit $OCF_SUCCESS ;; *) usage exit $OCF_ERR_UNIMPLEMENTED ;; esac