diff --git a/heartbeat/nfsserver b/heartbeat/nfsserver index 52d9bb22f..bac5bbbbf 100755 --- a/heartbeat/nfsserver +++ b/heartbeat/nfsserver @@ -1,863 +1,863 @@ #!/bin/sh # nfsserver # # Description: Manages nfs server as OCF resource # by hxinwei@gmail.com # License: GNU General Public License v2 (GPLv2) and later if [ -n "$OCF_DEBUG_LIBRARY" ]; then . $OCF_DEBUG_LIBRARY else : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs fi if is_redhat_based; then . ${OCF_FUNCTIONS_DIR}/nfsserver-redhat.sh fi DEFAULT_INIT_SCRIPT_LIST="/etc/init.d/nfsserver /etc/init.d/nfs /etc/init.d/nfs-kernel-server" DEFAULT_INIT_SCRIPT="/etc/init.d/nfsserver" for script in $DEFAULT_INIT_SCRIPT_LIST do if [ -f $script -a -x $script ]; then DEFAULT_INIT_SCRIPT=$script break fi done DEFAULT_NOTIFY_CMD=`which sm-notify` DEFAULT_NOTIFY_CMD=${DEFAULT_NOTIFY_CMD:-"/sbin/sm-notify"} DEFAULT_NOTIFY_FOREGROUND="false" DEFAULT_RPCPIPEFS_DIR="/var/lib/nfs/rpc_pipefs" EXEC_MODE=0 SELINUX_ENABLED=-1 STATD_PATH="/var/lib/nfs" STATD_DIR="" nfsserver_meta_data() { cat < 1.0 -Nfsserver helps to manage the Linux nfs server as a failover-able resource in Linux-HA. +Nfsserver helps one to manage the Linux nfs server as a failover-able resource in Linux-HA. It depends on Linux specific NFS implementation details, so is considered not portable to other platforms yet. Manages an NFS server The default init script shipped with the Linux distro. The nfsserver resource agent offloads the start/stop/monitor work to the init script because the procedure to start/stop/monitor nfsserver varies on different Linux distro. In the event that this option is not set, this agent will attempt to use an init script at this location, ${DEFAULT_INIT_SCRIPT}, or detect a systemd unit-file to use in the event that no init script is detected. Init script for nfsserver Do not send reboot notifications to NFSv3 clients during server startup. Disable NFSv3 server reboot notifications Keeps the sm-notify attached to its controlling terminal and running in the foreground. Keeps the notify tool running in the foreground. Specifies the length of sm-notify retry time, in minutes, to continue retrying notifications to unresponsive hosts. If this option is not specified, sm-notify attempts to send notifications for 15 minutes. Specifying a value of 0 causes sm-notify to continue sending notifications to unresponsive peers until it is manually killed. Specifies the length of sm-notify retry time (minutes). Comma separated list of floating IP addresses used to access the nfs service IP addresses. The nfsserver resource agent will save nfs related information in this specific directory. And this directory must be able to fail-over before nfsserver itself. Directory to store nfs server related information. The mount point for the sunrpc file system. Default is $DEFAULT_RPCPIPEFS_DIR. This script will mount (bind) nfs_shared_infodir on /var/lib/nfs/ (cannot be changed), and this script will mount the sunrpc file system on $DEFAULT_RPCPIPEFS_DIR (default, can be changed by this parameter). If you want to move only rpc_pipefs/ (e.g. to keep rpc_pipefs/ local) from default, please set this value. The mount point for the sunrpc file system. $( is_redhat_based && nfsserver_redhat_meta_data ) END return $OCF_SUCCESS } nfsserver_usage() { cat < /dev/null 2>&1 && selinuxenabled SELINUX_ENABLED=$? if [ $SELINUX_ENABLED -eq 0 ]; then export SELINUX_LABEL="$(ls -ldZ $STATD_PATH | cut -f4 -d' ')" fi ## # EXEC_MODE values # 1 user init script or default init script # 2 systemd (with nfs-lock.service) # 3 systemd (with rpc-statd.service) # # On error, this function will terminate the process # with error code $OCF_ERR_INSTALLED ## set_exec_mode() { ## # If EXEC_MODE is already set, we don't need to run this function again. ## if [ $EXEC_MODE -ne 0 ]; then return 0; fi ## # If the user defined an init script, It must exist for us to continue ## if [ -n "$OCF_RESKEY_nfs_init_script" ]; then # check_binary will exit the process if init script does not exist check_binary ${OCF_RESKEY_nfs_init_script} EXEC_MODE=1 return 0 fi ## # Check to see if the default init script exists, if so we'll use that. ## if which $DEFAULT_INIT_SCRIPT > /dev/null 2>&1; then OCF_RESKEY_nfs_init_script=$DEFAULT_INIT_SCRIPT EXEC_MODE=1 return 0 fi ## # Attempt systemd (with nfs-lock.service). ## if which systemctl > /dev/null 2>&1; then if systemctl list-unit-files | grep nfs-server > /dev/null && systemctl list-unit-files | grep nfs-lock > /dev/null; then EXEC_MODE=2 # when using systemd, the nfs-lock service file handles nfsv3 locking daemons for us. return 0 fi fi ## # Attempt systemd (with rpc-statd.service). ## if which systemctl > /dev/null 2>&1; then if systemctl list-unit-files | grep nfs-server > /dev/null && systemctl list-unit-files | grep rpc-statd > /dev/null; then EXEC_MODE=3 return 0 fi fi ocf_exit_reason "No init script or systemd unit file detected for nfs server" exit $OCF_ERR_INSTALLED } ## # wrapper for init script and systemd calls. ## nfs_exec() { local cmd=$1 local svc=$2 set_exec_mode case $EXEC_MODE in 1) ${OCF_RESKEY_nfs_init_script} $cmd;; 2) if ! echo $svc | grep -q "\."; then svc="${svc}.service" fi systemctl $cmd $svc ;; 3) if ! echo $svc | grep -q "\."; then svc="${svc}.service" fi systemctl $cmd $svc ;; esac } v3locking_exec() { local cmd=$1 set_exec_mode if [ $EXEC_MODE -eq 2 ]; then nfs_exec $cmd nfs-lock.service elif [ $EXEC_MODE -eq 3 ]; then nfs_exec $cmd rpc-statd.service else case $cmd in start) locking_start;; stop) locking_stop;; status) locking_status;; esac fi } nfsserver_systemd_monitor() { local threads_num local rc local fn ocf_log debug "Status: rpcbind" rpcinfo > /dev/null 2>&1 rc=$? if [ "$rc" -ne "0" ]; then ocf_exit_reason "rpcbind is not running" return $OCF_NOT_RUNNING fi ocf_log debug "Status: nfs-mountd" rpcinfo -t localhost 100005 > /dev/null 2>&1 rc=$? if [ "$rc" -ne "0" ]; then ocf_exit_reason "nfs-mountd is not running" return $OCF_NOT_RUNNING fi ocf_log debug "Status: nfs-idmapd" fn=`mktemp` nfs_exec status nfs-idmapd > $fn 2>&1 rc=$? ocf_log debug "$(cat $fn)" rm -f $fn if [ "$rc" -ne "0" ]; then ocf_exit_reason "nfs-idmapd is not running" return $OCF_NOT_RUNNING fi ocf_log debug "Status: rpc-statd" rpcinfo -t localhost 100024 > /dev/null 2>&1 rc=$? if [ "$rc" -ne "0" ]; then ocf_exit_reason "rpc-statd is not running" return $OCF_NOT_RUNNING fi nfs_exec is-active nfs-server rc=$? # Now systemctl is-active can't detect the failure of kernel process like nfsd. # So, if the return value of systemctl is-active is 0, check the threads number # to make sure the process is running really. # /proc/fs/nfsd/threads has the numbers of the nfsd threads. if [ $rc -eq 0 ]; then threads_num=`cat /proc/fs/nfsd/threads 2>/dev/null` if [ $? -eq 0 ]; then if [ $threads_num -gt 0 ]; then return $OCF_SUCCESS else return 3 fi else return $OCF_ERR_GENERIC fi fi return $rc } nfsserver_monitor () { local fn set_exec_mode fn=`mktemp` case $EXEC_MODE in 1) nfs_exec status nfs-server > $fn 2>&1;; [23]) nfsserver_systemd_monitor > $fn 2>&1;; esac rc=$? ocf_log debug "$(cat $fn)" rm -f $fn #Adapte LSB status code to OCF return code if [ $rc -eq 0 ]; then # don't report success if nfs servers are up # without locking daemons. v3locking_exec "status" rc=$? if [ $rc -ne 0 ]; then ocf_exit_reason "NFS server is up, but the locking daemons are down" rc=$OCF_ERR_GENERIC fi return $rc elif [ $rc -eq 3 ] || [ $rc -eq $OCF_NOT_RUNNING ]; then return $OCF_NOT_RUNNING else return $OCF_ERR_GENERIC fi } prepare_directory () { if [ -z "$fp" ]; then return fi [ -d "$fp" ] || mkdir -p $fp [ -d "$rpcpipefs_make_dir" ] || mkdir -p $rpcpipefs_make_dir [ -d "$fp/v4recovery" ] || mkdir -p $fp/v4recovery [ -d "$fp/$STATD_DIR" ] || mkdir -p "$fp/$STATD_DIR" [ -d "$fp/$STATD_DIR/sm" ] || mkdir -p "$fp/$STATD_DIR/sm" [ -d "$fp/$STATD_DIR/sm.ha" ] || mkdir -p "$fp/$STATD_DIR/sm.ha" [ -d "$fp/$STATD_DIR/sm.bak" ] || mkdir -p "$fp/$STATD_DIR/sm.bak" [ -n "`id -u rpcuser 2>/dev/null`" -a "`id -g rpcuser 2>/dev/null`" ] && chown -R rpcuser.rpcuser "$fp/$STATD_DIR" [ -f "$fp/etab" ] || touch "$fp/etab" [ -f "$fp/xtab" ] || touch "$fp/xtab" [ -f "$fp/rmtab" ] || touch "$fp/rmtab" dd if=/dev/urandom of=$fp/$STATD_DIR/state bs=1 count=4 >/dev/null 2>&1 [ -n "`id -u rpcuser 2>/dev/null`" -a "`id -g rpcuser 2>/dev/null`" ] && chown rpcuser.rpcuser "$fp/$STATD_DIR/state" [ $SELINUX_ENABLED -eq 0 ] && chcon -R "$SELINUX_LABEL" "$fp" } is_bound () { if mount | grep -q "on $1 type"; then return 0 fi return 1 } bind_tree () { if [ -z "$fp" ]; then return fi if is_bound /var/lib/nfs; then ocf_log debug "$fp is already bound to /var/lib/nfs" return 0 fi mount --bind $fp /var/lib/nfs [ $SELINUX_ENABLED -eq 0 ] && restorecon /var/lib/nfs } unbind_tree () { if `mount | grep -q " on $rpcpipefs_umount_dir"`; then umount -t rpc_pipefs $rpcpipefs_umount_dir fi if is_bound /var/lib/nfs; then umount /var/lib/nfs fi } binary_status() { local binary=$1 local pid pid=$(pgrep ${binary}) case $? in 0) echo "$pid" return $OCF_SUCCESS;; 1) return $OCF_NOT_RUNNING;; *) return $OCF_ERR_GENERIC;; esac } locking_status() { binary_status "rpc.statd" > /dev/null 2>&1 } locking_start() { local ret=$OCF_SUCCESS ocf_log info "Starting rpc.statd." rpc.statd $STATDARG ret=$? if [ $ret -ne 0 ]; then ocf_log err "Failed to start rpc.statd" return $ret fi [ -d /var/lock/subsys ] && touch /var/lock/subsys/nfslock return $ret } terminate() { local pids local i=0 while : ; do pids=$(binary_status $1) [ -z "$pids" ] && return 0 kill $pids sleep 1 i=$((i + 1)) [ $i -gt 3 ] && return 1 done } killkill() { local pids local i=0 while : ; do pids=$(binary_status $1) [ -z "$pids" ] && return 0 kill -9 $pids sleep 1 i=$((i + 1)) [ $i -gt 3 ] && return 1 done } stop_process() { local process=$1 ocf_log info "Stopping $process" if terminate $process; then ocf_log debug "$process is stopped" else if killkill $process; then ocf_log debug "$process is stopped" else ocf_log debug "Failed to stop $process" return 1 fi fi return 0 } locking_stop() { ret=0 # sm-notify can prevent umount of /var/lib/nfs/statd if # it is still trying to notify unresponsive clients. stop_process sm-notify if [ $? -ne 0 ]; then ret=$OCF_ERR_GENERIC fi stop_process rpc.statd if [ $? -ne 0 ]; then ret=$OCF_ERR_GENERIC fi return $ret } notify_locks() { if ocf_is_true "$OCF_RESKEY_nfs_no_notify"; then # we've been asked not to notify clients return; fi # run in foreground, if requested if ocf_is_true "$OCF_RESKEY_nfs_notify_foreground"; then opts="-d" fi if [ -n "$OCF_RESKEY_nfs_smnotify_retry_time" ]; then opts="$opts -m $OCF_RESKEY_nfs_smnotify_retry_time" fi if [ -n "$OCF_RESKEY_statd_outgoing_port" ]; then opts="$opts -p $OCF_RESKEY_statd_outgoing_port" fi # forces re-notificaiton regardless if notifies have already gone out opts="$opts -f" ocf_log info "executing sm-notify" if [ -n "$OCF_RESKEY_nfs_ip" ]; then for ip in `echo ${OCF_RESKEY_nfs_ip} | sed 's/,/ /g'`; do cp -rpfn $STATD_PATH/sm.ha/* $STATD_PATH/ > /dev/null 2>&1 sm-notify $opts -v $ip done else sm-notify $opts fi } nfsserver_start () { local rc; local fn if nfsserver_monitor; then ocf_log debug "NFS server is already started" return $OCF_SUCCESS fi is_redhat_based && set_env_args prepare_directory bind_tree # remove the sm-notify pid so sm-notify will be allowed to run again without requiring a reboot. rm -f /var/run/sm-notify.pid # # Synchronize these before starting statd # cp -rpfn $STATD_PATH/sm.ha/* $STATD_PATH/ > /dev/null 2>&1 rm -rf $STATD_PATH/sm.ha/* > /dev/null 2>&1 cp -rpf $STATD_PATH/sm $STATD_PATH/sm.bak /var/lib/nfs/state $STATD_PATH/sm.ha > /dev/null 2>&1 ocf_log info "Starting NFS server ..." # mounts /proc/fs/nfsd for us lsmod | grep -q nfsd if [ $? -ne 0 ]; then modprobe nfsd fi # systemd case $EXEC_MODE in [23]) nfs_exec start rpcbind local i=1 while : ; do ocf_log info "Start: rpcbind i: $i" rpcinfo > /dev/null 2>&1 rc=$? if [ "$rc" -eq "0" ]; then break; fi sleep 1 i=$((i + 1)) done ;; esac # check to see if we need to start rpc.statd v3locking_exec "status" if [ $? -ne $OCF_SUCCESS ]; then v3locking_exec "start" rc=$? if [ $rc -ne 0 ]; then ocf_exit_reason "Failed to start NFS server locking daemons" return $rc fi else ocf_log info "rpc.statd already up" fi # systemd case $EXEC_MODE in [23]) nfs_exec start nfs-mountd local i=1 while : ; do ocf_log info "Start: nfs-mountd i: $i" rpcinfo -t localhost 100005 > /dev/null 2>&1 rc=$? if [ "$rc" -eq "0" ]; then break; fi sleep 1 i=$((i + 1)) done nfs_exec start nfs-idmapd local i=1 while : ; do ocf_log info "Start: nfs-idmapd i: $i" fn=`mktemp` nfs_exec status nfs-idmapd > $fn 2>&1 rc=$? ocf_log debug "$(cat $fn)" rm -f $fn if [ "$rc" -eq "0" ]; then break; fi sleep 1 i=$((i + 1)) done nfs_exec start rpc-statd local i=1 while : ; do ocf_log info "Start: rpc-statd i: $i" rpcinfo -t localhost 100024 > /dev/null 2>&1 rc=$? if [ "$rc" -eq "0" ]; then break; fi sleep 1 i=$((i + 1)) done esac fn=`mktemp` nfs_exec start nfs-server > $fn 2>&1 rc=$? ocf_log debug "$(cat $fn)" rm -f $fn if [ $rc -ne 0 ]; then ocf_exit_reason "Failed to start NFS server" return $rc fi tfn="/proc/fs/nfsd/threads" if [ ! -f "$tfn" ] || [ "$(cat $tfn)" -le "0" ]; then ocf_exit_reason "Failed to start NFS server: /proc/fs/nfsd/threads" return $OCF_ERR_GENERIC fi notify_locks ocf_log info "NFS server started" return $OCF_SUCCESS } nfsserver_stop () { local fn ocf_log info "Stopping NFS server ..." # backup the current sm state information to the ha folder before stopping. # the ha folder will be synced after startup, restoring the statd client state rm -rf $STATD_PATH/sm.ha/* > /dev/null 2>&1 cp -rpf $STATD_PATH/sm $STATD_PATH/sm.bak /var/lib/nfs/state $STATD_PATH/sm.ha > /dev/null 2>&1 fn=`mktemp` nfs_exec stop nfs-server > $fn 2>&1 rc=$? ocf_log debug "$(cat $fn)" rm -f $fn if [ $rc -ne 0 ]; then ocf_exit_reason "Failed to stop NFS server" return $rc fi # systemd case $EXEC_MODE in [23]) ocf_log info "Stop: threads" tfn="/proc/fs/nfsd/threads" if [ -f "$tfn" ] && [ "$(cat $tfn)" -gt "0" ]; then ocf_exit_reason "NFS server failed to stop: /proc/fs/nfsd/threads" return $OCF_ERR_GENERIC fi nfs_exec stop rpc-statd > /dev/null 2>&1 ocf_log info "Stop: rpc-statd" rpcinfo -t localhost 100024 > /dev/null 2>&1 rc=$? if [ "$rc" -eq "0" ]; then ocf_exit_reason "Failed to stop rpc-statd" return $OCF_ERR_GENERIC fi nfs_exec stop nfs-idmapd > /dev/null 2>&1 ocf_log info "Stop: nfs-idmapd" fn=`mktemp` nfs_exec status nfs-idmapd > $fn 2>&1 rc=$? ocf_log debug "$(cat $fn)" rm -f $fn if [ "$rc" -eq "0" ]; then ocf_exit_reason "Failed to stop nfs-idmapd" return $OCF_ERR_GENERIC fi nfs_exec stop nfs-mountd > /dev/null 2>&1 ocf_log info "Stop: nfs-mountd" rpcinfo -t localhost 100005 > /dev/null 2>&1 rc=$? if [ "$rc" -eq "0" ]; then ocf_exit_reason "Failed to stop nfs-mountd" return $OCF_ERR_GENERIC fi esac v3locking_exec "stop" if [ $? -ne 0 ]; then ocf_exit_reason "Failed to stop NFS locking daemons" rc=$OCF_ERR_GENERIC fi # systemd case $EXEC_MODE in [23]) nfs_exec stop rpc-gssd > /dev/null 2>&1 ocf_log info "Stop: rpc-gssd" esac unbind_tree ocf_log info "NFS server stopped" return 0 } nfsserver_validate () { ## # set_exec_mode will exit if nfs server is not installed ## set_exec_mode check_binary ${OCF_RESKEY_nfs_notify_cmd} if [ -n "$OCF_RESKEY_CRM_meta_clone" ] && [ -n "$OCF_RESKEY_nfs_shared_infodir" ]; then ocf_exit_reason "This RA does not support clone mode when a shared info directory is in use." exit $OCF_ERR_CONFIGURED fi if [ -n "$OCF_RESKEY_nfs_smnotify_retry_time" ]; then if ! ocf_is_decimal "$OCF_RESKEY_nfs_smnotify_retry_time"; then ocf_exit_reason "Invalid nfs_smnotify_retry_time [$OCF_RESKEY_nfs_smnotify_retry_time]" exit $OCF_ERR_CONFIGURED fi fi case ${OCF_RESKEY_nfs_notify_cmd##*/} in sm-notify|rpc.statd) ;; *) ocf_exit_reason "Invalid nfs_notify_cmd [$OCF_RESKEY_nfs_notify_cmd]" exit $OCF_ERR_CONFIGURED ;; esac return $OCF_SUCCESS } nfsserver_validate case $__OCF_ACTION in start) nfsserver_start ;; stop) nfsserver_stop ;; monitor) nfsserver_monitor ;; validate-all) exit $OCF_SUCCESS ;; *) nfsserver_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac diff --git a/heartbeat/nginx b/heartbeat/nginx index d28c5a108..eed666533 100755 --- a/heartbeat/nginx +++ b/heartbeat/nginx @@ -1,947 +1,947 @@ #!/bin/sh # # High-Availability nginx OCF resource agent # # nginx # # Description: starts/stops nginx servers. # # Author: Alan Robertson # Dejan Muhamedagic # This code is based significantly on the apache resource agent # # Support: users@clusterlabs.org # # License: GNU General Public License (GPL) # # Copyright: (C) 2002-2010 International Business Machines # # # Our parsing of the nginx 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_nginx # OCF_RESKEY_port # OCF_RESKEY_options # OCF_RESKEY_status10regex # OCF_RESKEY_status10url # OCF_RESKEY_client # OCF_RESKEY_test20url # OCF_RESKEY_test20regex # OCF_RESKEY_test20conffile # OCF_RESKEY_test20name # OCF_RESKEY_external_monitor30_cmd # # # TO DO: # More extensive tests of extended monitor actions # Look at the --with-http_stub_status_module for validating # the configuration? (or is that automatically done?) # Checking could certainly result in better error # messages. # Allow for the fact that the config file and so on might all be # on shared disks - this affects the validate-all option. : ${OCF_FUNCTIONS_DIR=$OCF_ROOT/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs HA_VARRUNDIR=${HA_VARRUN} ####################################################################### # # Configuration options - usually you don't need to change these # ####################################################################### # NGINXDLIST="/usr/sbin/nginx /usr/local/sbin/nginx" # default options for http clients # NB: We _always_ test a local resource, so it should be # safe to connect from the local interface. WGETOPTS="-O- -q -L --no-proxy --bind-address=127.0.0.1" CURLOPTS="-o - -Ss -L --interface lo" LOCALHOST="http://localhost" NGINXDOPTS="" # # # 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. usage() { cat <<-EOF usage: $0 action action: start start nginx stop stop nginx reload reload the nginx configuration status return the status of web server, running or stopped 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 - or configure what URL you wish to be monitored. 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 EOF exit $1 } # # run the http client # curl_func() { cl_opts="$CURLOPTS $test_httpclient_opts" if [ x != "x$test_user" ] then echo "-u $test_user:$test_password" | curl -K - $cl_opts "$1" else curl $cl_opts "$1" fi } wget_func() { auth="" cl_opts="$WGETOPTS $test_httpclient_opts" [ x != "x$test_user" ] && auth="--http-user=$test_user --http-passwd=$test_password" wget $auth $cl_opts "$1" } # # rely on whatever the user provided userdefined() { $test_httpclient $test_httpclient_opts "$1" } # # find a good http client # findhttpclient() { # prefer curl if present... if [ "x$CLIENT" != x ] then echo "$CLIENT" elif which curl >/dev/null 2>&1 then echo "curl" elif which wget >/dev/null 2>&1 then echo "wget" else return 1 fi } gethttpclient() { [ -z "$test_httpclient" ] && test_httpclient=$ourhttpclient case "$test_httpclient" in curl|wget) echo ${test_httpclient}_func;; #these are supported *) echo userdefined;; esac } # test configuration good? is_testconf_sane() { if [ "x$test_regex" = x -o "x$test_url" = x ] then ocf_log err "test regular expression or test url empty" return 1 fi if [ "x$test_user$test_password" != x -a \( "x$test_user" = x -o "x$test_password" = x \) ] then ocf_log err "bad user authentication for extended test" return 1 fi return 0 } # # read the test definition from the config # readtestconf() { test_name="$1" # we look for this one or the first one if empty lcnt=0 readdef="" test_url="" test_regex="" test_user="" test_password="" test_httpclient="" test_httpclient_opts="" while read key value do lcnt=$((lcnt+1)) if [ "$readdef" ] then case "$key" in "url") test_url="$value" ;; "user") test_user="$value" ;; "password") test_password="$value" ;; "client") test_httpclient="$value" ;; "client_opts") test_httpclient_opts="$value" ;; "match") test_regex="$value" ;; "end") break ;; "#"*|"") ;; *) ocf_log err "$lcnt: $key: unknown keyword"; return 1 ;; esac else [ "$key" = "test" ] && [ -z "$test_name" -o "$test_name" = "$value" ] && readdef=1 fi done } nginxcat() { awk ' function procline() { split($0,a); if( a[1]~/^[Ii]nclude$/ ) { procinclude(a[2]); } else { if( a[1]=="root" ) { rootdir=a[2]; gsub("\"","",rootdir); } print; } } function printfile(infile, a) { while( (getline 0 ) { procline(); } close(infile); } function allfiles(dir, cmd,f) { cmd="find -L "dir" -type f"; while( ( cmd | getline f ) > 0 ) { printfile(f); } close(cmd); } function listfiles(pattern, cmd,f) { cmd="ls "pattern" 2>/dev/null"; while( ( cmd | getline f ) > 0 ) { printfile(f); } close(cmd); } function procinclude(spec) { if( rootdir!="" && spec!~/^\// ) { spec=rootdir"/"spec; } if( isdir(spec) ) { allfiles(spec); # read all files in a directory (and subdirs) } else { listfiles(spec); # there could be jokers } } function isdir(s) { return !system("test -d \""s"\""); } { procline(); } ' $1 | sed 's/#.*//;s/[[:blank:]]*$//;s/^[[:blank:]]*//' | grep -v '^$' } # # set parameters (as shell vars) from our nginx config file # get_nginx_params() { configfile=$1 shift 1 vars=`echo "$@" | sed 's/ /,/g'` eval ` nginxcat $configfile | awk -v vars="$vars" ' BEGIN{ split(vars,v,","); for( i in v ) vl[i]=tolower(v[i]); } { for( i in v ) if( tolower($1)==vl[i] ) { print v[i]"="$2 delete vl[i] break } } '` } # # Return the location(s) that are handled by the given handler # FindLocationForHandler() { PerlScript='while (<>) { /^\s*location\s+([^ \s{]+)\s*{/i && ($loc=$1); /^\s*stub_status\s+on\s*;$2/i && print "$loc\n"; }' nginxcat $1 | perl -e "$PerlScript" } # # Check if the port is valid # CheckPort() { lclport="$1" case "$lclport" in *:[0-9]*) lclport=`echo "$lclport" | sed 's%^[^:][^:]*:%%'` esac ocf_is_decimal "$lclport" && [ $lclport -gt 0 -a $lclport -lt 65537 ] } buildlocalurl() { [ "x$listen" != "x" ] && echo "http://${listen}" || echo "${LOCALHOST}:${PORT}" } # # Get all the parameters we need from the Nginx config file # GetParams() { ConfigFile=$1 DEFAULT_PID=`echo "$NGINX_CONFIGURATION" | sed -e 's%.*--pid-path=%%' -e 's% *--.*%%'` if [ ! -f $ConfigFile ] then return 1 fi get_nginx_params $ConfigFile root pid listen PidFile="$pid" case $PidFile in "") PidFile=$DEFAULT_PID ;; *) ;; esac for p in "$PORT" "$listen" 80 do if CheckPort "$p" then PORT="$p" break fi done echo $listen | grep ':' >/dev/null || # Listen could be just port spec listen="localhost:$listen" # # It's difficult to figure out whether the server supports # the status operation. # (we start our server with -DSTATUS - just in case :-)) # # Typically (but not necessarily) the status URL is /nginx_status # # For us to think status will work, we have to have the following things: # # - The server-status handler has to be mapped to some URL somewhere # # We assume that: # # - the "main" web server at $PORT will also support it if we can find it # somewhere in the file # - it will be supported at the same URL as the one we find in the file # # If this doesn't work for you, then set the status10url attribute. # if [ "X$STATUSURL" = "X" ] then StatusURL=`FindLocationForHandler $1 nginx_status | tail -1` STATUSURL="`buildlocalurl`$StatusURL" fi test ! -z "$PidFile" } # # return TRUE if a process with given PID is running # ProcessRunning() { NginxPID=$1 # Use /proc if it looks like it's here... if [ -d /proc -a -d /proc/1 ] then [ -d /proc/$NginxPID ] else # This assumes we're running as root... kill -0 "$NginxPID" >/dev/null 2>&1 fi } silent_status() { if [ -f $PidFile -a -s $PidFile ] && ocf_is_decimal "`cat $PidFile`" then ProcessRunning `cat $PidFile` else : No pid file false fi } start_nginx() { if silent_status then ocf_log info "$CMD already running (pid $NginxPID)" return $OCF_SUCCESS fi if ocf_run $NGINXD $OPTIONS -t -c $CONFIGFILE then : Configuration file $CONFIGFILE looks OK else return $OCF_ERR_CONFIGURED fi NGINX_VERSION=`$NGINXD -v 2>&1` ocf_log info "Starting $NGINXD - $NGINX_VERSION" ocf_log info "$NGINXD build configuration: $NGINX_CONFIGURATION" if ocf_run $NGINXD $NGINXDOPTS $OPTIONS -c $CONFIGFILE then : $NGINXD started without errors! else return $OCF_ERR_GENERIC fi tries=0 # This looks like a potential infinite loop - but it's not in practice # The LRM will time us out and kill us if nginx never starts working. while monitor_nginx ec=$? if [ $ec -eq $OCF_NOT_RUNNING ] then tries=`expr $tries + 1` ocf_log info "Waiting for $NGINXD $OPTIONS -c $CONFIGFILE to come up (try $tries)" true else false fi do sleep 1 done return $ec } stop_nginx() { if silent_status then if kill $NginxPID then tries=0 while ProcessRunning $NginxPID && [ $tries -lt 10 ] do sleep 1 kill $NginxPID >/dev/null ocf_log info "Killing nginx PID $NginxPID" tries=`expr $tries + 1` done else ocf_log warn "Killing nginx PID $NginxPID FAILED." fi if ProcessRunning $NginxPID then ocf_log info "$CMD still running ($NginxPID)." false else ocf_log info "$CMD stopped." fi else ocf_log info "$CMD is not running." fi # # I'm not convinced this is a wonderful idea (AlanR) # for sig in SIGTERM SIGHUP SIGKILL do if pgrep -f "$NGINXD.*$CONFIGFILE" >/dev/null then pkill -$sig -f $NGINXD.*$CONFIGFILE >/dev/null ocf_log info "nginxd children were signalled ($sig)" sleep 1 else break fi done } reload_nginx() { if silent_status then if kill -1 $NginxPID then : $NGINX reload signal to $NginxPID succeeded return $OCF_SUCCESS fi return $OCF_ERR_GENERIC fi start_nginx } status_nginx() { silent_status rc=$? if [ $rc -eq 0 ] then ocf_log info "$CMD is running (pid $NginxPID)." return $OCF_SUCCESS else ocf_log info "$CMD is stopped." return $OCF_NOT_RUNNING fi } fixtesturl() { echo $test_url | grep -qs "^http" && return test_url="`buildlocalurl`$test_url" } monitor_nginx_external() { if [ -z "$EXTMONITOR" ] then ocf_log err "$External level 30 Monitor Command not configured." return $OCF_ERR_CONFIGURED fi extbase=`echo $EXTMONITOR | sed 's% .*%%'` if case "$extbase" in /*) test -f "$extbase" -a -x "$extbase";; *) which "$extbase" >/dev/null 2>&1 esac then : OK - $extbase seems to be there... else ocf_log err "$External monitor command [$extbase] is not installed." return $OCF_ERR_CONFIGURED fi if $extbase then : OK - $extbase succeeded else ocf_log err "$extbase reported failure [rc=$?]" return $OCF_NOT_RUNNING fi return $OCF_SUCCESS } monitor_nginx_extended() { if [ -f "$TESTCONFFILE" -a -r "$TESTCONFFILE" ] then readtestconf < $TESTCONFFILE else test_url="$TESTURL" test_regex="$TESTREGEX20" fi whattorun=`gethttpclient` fixtesturl is_testconf_sane || return $OCF_ERR_CONFIGURED $whattorun "$test_url" | grep -Ei "$test_regex" > /dev/null } monitor_nginx_basic() { if [ -z "$STATUSURL" ] then ocf_log err "status10url parameter empty" return $OCF_ERR_CONFIGURED elif [ -z "$ourhttpclient" ] then ocf_log err "could not find a http client; make sure that either wget or curl is available" return $OCF_ERR_CONFIGURED fi ${ourhttpclient}_func "$STATUSURL" | grep -Ei "$TESTREGEX" > /dev/null } monitor_nginx() { silent_status if [ $? -ne 0 ] then ocf_log info "$CMD not running" return $OCF_NOT_RUNNING fi if [ -z "$OCF_CHECK_LEVEL" ] || [ "$OCF_CHECK_LEVEL" -lt 10 ] then return 0 fi ourhttpclient=`findhttpclient` # we'll need one if [ "$OCF_CHECK_LEVEL" -lt 20 ] then monitor_nginx_basic elif [ "$OCF_CHECK_LEVEL" -lt 30 ] then monitor_nginx_extended else monitor_nginx_external fi } metadata_nginx(){ cat < 1.0 This is the resource agent for the Nginx web/proxy server. This resource agent does not monitor POP or IMAP servers, as we don't know how to determine meaningful status for them. 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 nginx resource will end with an error status. The default monitor operation will verify that nginx is running. The level 10 monitor operation by default will try and fetch the /nginx_status page - which is commented out in sample nginx configurations. Make sure that the /nginx_status page works and that the access is restricted to localhost (address 127.0.0.1) plus whatever places _outside the cluster_ you want to monitor the server from. See the status10url and status10regex attributes for more details. The level 20 monitor operation will perform a more complex set of tests from a configuration file. The level 30 monitor operation will run an external command to perform an arbitrary monitoring operation. Manages an Nginx web/proxy server instance The full pathname of the Nginx 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 nginx server status page by default) when given a level 10 monitor operation. If left unspecified, it will be inferred from the nginx configuration file, or defaulted to /nginx_status. If you set this, make sure that it succeeds *only* from the localhost (127.0.0.1) and no other cluster nodes. Otherwise, the cluster software may complain about it being active on multiple nodes. url name Regular expression to match in the output of status10url. Case insensitive. monitor regular expression Client to use to query to Nginx for level 10 and level 20 tests. If not specified, the RA will try to find one on the system. Currently, wget and curl are supported, with curl being preferred. -For example, you can set this paramter to "wget" if you prefer that to curl. +For example, you can set this parameter to "wget" if you prefer that to curl. http client URL to test. If it does not start with "http", then it's considered to be relative to the document root address. Level 20 monitor url Regular expression to match in the output of test20url. Case insensitive. Level 20 monitor regular expression A file which contains a more complex 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. Level 20 test configuration file Name of the test within the test configuration file. Level 20 test name Command string to run which implements level 30 monitoring. Level 30 test string Extra options to apply when starting nginx. nginx start options END exit $OCF_SUCCESS } validate_all_nginx() { if CheckPort $PORT # We are sure to succeed here, since we forced $PORT to be valid in GetParams() then : OK else ocf_log err "Port number $PORT is invalid!" exit $OCF_ERR_ARGS fi if [ -z $STATUSURL ] then : OK to be empty else case $STATUSURL in http://*/*) ;; *) ocf_log err "Invalid STATUSURL $STATUSURL" exit $OCF_ERR_ARGS ;; esac fi if [ ! -x $NGINXD ] then ocf_log err "NGINXD $NGINXD not found or is not an executable!" exit $OCF_ERR_ARGS fi if [ ! -f $CONFIGFILE ] then # We are sure to succeed here, since we have parsed $CONFIGFILE before getting here ocf_log err "Configuration file $CONFIGFILE not found!" exit $OCF_ERR_CONFIGURED fi if ocf_run $NGINXD $OPTIONS -t -c $CONFIGFILE then : Cool $NGINXD likes $CONFIGFILE else ocf_log err "$NGINXD $OPTIONS -t -c $CONFIGFILE reported a configuration error." return $OCF_ERR_CONFIGURED fi return $OCF_SUCCESS } if [ $# -eq 1 ] then COMMAND=$1 NGINXD="$OCF_RESKEY_httpd" PORT="$OCF_RESKEY_port" STATUSURL="$OCF_RESKEY_status10url" CONFIGFILE="$OCF_RESKEY_configfile" OPTIONS="$OCF_RESKEY_options" CLIENT=${OCF_RESKEY_client} TESTREGEX=${OCF_RESKEY_status10regex:-'Reading: [0-9]+ Writing: [0-9]+ Waiting: [0-9]+'} TESTURL="$OCF_RESKEY_test20url" TESTREGEX20=${OCF_RESKEY_test20regex} TESTCONFFILE="$OCF_RESKEY_test20conffile" TESTNAME="$OCF_RESKEY_test20name" EXTMONITOR="$OCF_RESKEY_external_monitor30_cmd" else usage $OCF_ERR_ARGS fi LSB_STATUS_STOPPED=3 if [ "X$NGINXD" = X -o ! -f "$NGINXD" -o ! -x "$NGINXD" ] then NGINXD= for h in $NGINXDLIST do if [ -f "$h" -a -x "$h" ] then NGINXD="$h" break fi done # It is possible that we still do not have a valid httpd at this stage if [ -z "$NGINXD" ] then case $COMMAND in stop) exit $OCF_SUCCESS;; monitor) exit $OCF_NOT_RUNNING;; status) exit $LSB_STATUS_STOPPED;; meta-data) metadata_nginx;; esac ocf_log err "nginx binary not found! Please verify you've installed it" exit $OCF_ERR_INSTALLED fi # Let the user know that the $NGINXD used is the one (s)he specified via $OCF_RESKEY_httpd if [ ! -z "$OCF_RESKEY_httpd" ] then ocf_log info "Using $NGINXD as nginx" fi fi httpd_basename=`basename $NGINXD` case $httpd_basename in *-*) httpd_basename=`echo "$httpd_basename" | sed -e 's%\-.*%%'`;; esac NGINX_CONFIGURATION=`$NGINXD -V 2>&1 |grep 'configure arguments:'` DEFAULT_CONFIG=`echo "$NGINX_CONFIGURATION" | sed -e 's%.*--conf-path=%%' -e 's% *--.*%%'` case "$CONFIGFILE" in "") CONFIGFILE=$DEFAULT_CONFIG;; *) ;; esac if [ ! -f "$CONFIGFILE" ] then case $COMMAND in stop) ocf_log warn "$CONFIGFILE not found - nginx considered stopped" exit $OCF_SUCCESS;; monitor) exit $OCF_NOT_RUNNING;; status) exit $LSB_STATUS_STOPPED;; esac fi if [ "X$COMMAND" = Xmeta-data ] || GetParams $CONFIGFILE then : OK else ocf_log err "Cannot parse config file [$CONFIGFILE]" exit $OCF_ERR_CONFIGURED fi case $COMMAND in start) start_nginx;; stop) stop_nginx;; reload) reload_nginx;; status) status_nginx;; monitor) monitor_nginx;; meta-data) metadata_nginx;; validate-all) validate_all_nginx;; *) usage $OCF_ERR_UNIMPLEMENTED;; esac diff --git a/heartbeat/scsi2reservation b/heartbeat/scsi2reservation index be0c53a80..01b067e26 100755 --- a/heartbeat/scsi2reservation +++ b/heartbeat/scsi2reservation @@ -1,170 +1,170 @@ #!/bin/sh # by hxinwei@gmail.com # License: GNU General Public License 2 (GPL2) if [ -n "$OCF_DEBUG_LIBRARY" ]; then . $OCF_DEBUG_LIBRARY else : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs fi : ${OCF_RESKEY_scsi_reserve="/usr/sbin/scsi_reserve"} : ${OCF_RESKEY_sharedisk="/dev/sdb"} : ${OCF_RESKEY_start_loop=10} scsi2reserve_meta_data() { cat < 1.0 The scsi-2-reserve resource agent is a place holder for SCSI-2 reservation. A healthy instance of scsi-2-reserve resource, indicates the own of the specified SCSI device. This resource agent depends on the scsi_reserve from scsires package, which is Linux specific. scsi-2 reservation The scsi_reserve is a command from scsires package. -It helps to issue SCSI-2 reservation on SCSI devices. +It helps one to issue SCSI-2 reservation on SCSI devices. Manages exclusive access to shared storage media thrugh SCSI-2 reservations The shared disk that can be reserved. Shared disk. We are going to try several times before giving up. Start_loop indicates how many times we are going to re-try. Times to re-try before giving up. END return $OCF_SUCCESS } scsi2reserve_usage() { cat <