-ctdb_reconfigure_take_lock ()
-{
- _ctdb_service_reconfigure_common
- _lock="${_d}/reconfigure_lock"
- mkdir -p "${_lock%/*}" # dirname
- touch "$_lock"
-
- (
- flock 0
- # This is overkill but will work if we need to extend this to
- # allow certain events to run multiple times in parallel
- # (e.g. takeip) and write multiple PIDs to the file.
- read _locker_event
- if [ -n "$_locker_event" ] ; then
- while read _pid ; do
- if [ -n "$_pid" -a "$_pid" != $$ ] && \
- kill -0 "$_pid" 2>/dev/null ; then
- exit 1
- fi
- done
- fi
-
- printf "%s\n%s\n" "$event_name" $$ >"$_lock"
- exit 0
- ) <"$_lock"
-}
-
-ctdb_reconfigure_release_lock ()
-{
- _ctdb_service_reconfigure_common
- _lock="${_d}/reconfigure_lock"
-
- rm -f "$_lock"
-}
-
-ctdb_replay_monitor_status ()
-{
- echo "Replaying previous status for this script due to reconfigure..."
- # Leading separator ('|') is missing in some versions...
- _out=$(ctdb scriptstatus -X | grep -E "^\|?monitor\|${script_name}\|")
- # Output looks like this:
- # |monitor|60.nfs|1|ERROR|1314764004.030861|1314764004.035514|foo bar|
- # This is the cheapest way of getting fields in the middle.
- set -- $(IFS="|" ; echo $_out)
- _code="$3"
- _status="$4"
- # The error output field can include colons so we'll try to
- # preserve them. The weak checking at the beginning tries to make
- # this work for both broken (no leading '|') and fixed output.
- _out="${_out%|}"
- _err_out="${_out#*monitor|${script_name}|*|*|*|*|}"
- case "$_status" in
- OK) : ;; # Do nothing special.
- TIMEDOUT)
- # Recast this as an error, since we can't exit with the
- # correct negative number.
- _code=1
- _err_out="[Replay of TIMEDOUT scriptstatus - note incorrect return code.] ${_err_out}"
- ;;
- DISABLED)
- # Recast this as an OK, since we can't exit with the
- # correct negative number.
- _code=0
- _err_out="[Replay of DISABLED scriptstatus - note incorrect return code.] ${_err_out}"
- ;;
- *) : ;; # Must be ERROR, do nothing special.
- esac
- if [ -n "$_err_out" ] ; then
- echo "$_err_out"
- fi
- exit $_code
-}
-
-ctdb_service_check_reconfigure ()
-{
- assert_service_name
-
- # We only care about some events in this function. For others we
- # return now.
- case "$event_name" in
- monitor|ipreallocated|reconfigure) : ;;
- *) return 0 ;;
- esac
-
- if ctdb_reconfigure_take_lock ; then
- # No events covered by this function are running, so proceed
- # with gay abandon.
- case "$event_name" in
- reconfigure)
- (ctdb_service_reconfigure)
- exit $?
- ;;
- ipreallocated)
- if ctdb_service_needs_reconfigure ; then
- ctdb_service_reconfigure
- fi
- ;;
- esac
-
- ctdb_reconfigure_release_lock
- else
- # Somebody else is running an event we don't want to collide
- # with. We proceed with caution.
- case "$event_name" in
- reconfigure)
- # Tell whoever called us to retry.
- exit 2
- ;;
- ipreallocated)
- # Defer any scheduled reconfigure and just run the
- # rest of the ipreallocated event, as per the
- # eventscript. There's an assumption here that the
- # event doesn't depend on any scheduled reconfigure.
- # This is true in the current code.
- return 0
- ;;
- monitor)
- # There is most likely a reconfigure in progress so
- # the service is possibly unstable. As above, we
- # defer any scheduled reconfigured. We also replay
- # the previous monitor status since that's the best
- # information we have.
- ctdb_replay_monitor_status
- ;;
- esac
- fi
-}
-
-##################################################################
-# Does CTDB manage this service? - and associated auto-start/stop
-
-ctdb_compat_managed_service ()
-{
- if [ "$1" = "yes" -a "$2" = "$service_name" ] ; then
- CTDB_MANAGED_SERVICES="$CTDB_MANAGED_SERVICES $2"
- fi
-}
-
-is_ctdb_managed_service ()
-{
- assert_service_name
-
- # $t is used just for readability and to allow better accurate
- # matching via leading/trailing spaces
- t=" $CTDB_MANAGED_SERVICES "
-
- # Return 0 if "<space>$service_name<space>" appears in $t
- if [ "${t#* ${service_name} }" != "${t}" ] ; then
- return 0
- fi
-
- # If above didn't match then update $CTDB_MANAGED_SERVICES for
- # backward compatibility and try again.
- ctdb_compat_managed_service "$CTDB_MANAGES_VSFTPD" "vsftpd"
- ctdb_compat_managed_service "$CTDB_MANAGES_SAMBA" "samba"
- ctdb_compat_managed_service "$CTDB_MANAGES_WINBIND" "winbind"
- ctdb_compat_managed_service "$CTDB_MANAGES_HTTPD" "apache2"
- ctdb_compat_managed_service "$CTDB_MANAGES_HTTPD" "httpd"
- ctdb_compat_managed_service "$CTDB_MANAGES_ISCSI" "iscsi"
- ctdb_compat_managed_service "$CTDB_MANAGES_CLAMD" "clamd"
- ctdb_compat_managed_service "$CTDB_MANAGES_NFS" "nfs"
-
- t=" $CTDB_MANAGED_SERVICES "
-
- # Return 0 if "<space>$service_name<space>" appears in $t
- [ "${t#* ${service_name} }" != "${t}" ]
-}
-
-ctdb_start_stop_service ()
-{
- assert_service_name
-
- # Allow service-start/service-stop pseudo-events to start/stop
- # services when we're not auto-starting/stopping and we're not
- # monitoring.
- case "$event_name" in
- service-start)
- if is_ctdb_managed_service ; then
- die 'service-start event not permitted when service is managed'
- fi
- if [ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] ; then
- die 'service-start event not permitted with $CTDB_SERVICE_AUTOSTARTSTOP = yes'
- fi
- ctdb_service_start
- exit $?
- ;;
- service-stop)
- if is_ctdb_managed_service ; then
- die 'service-stop event not permitted when service is managed'
- fi
- if [ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] ; then
- die 'service-stop event not permitted with $CTDB_SERVICE_AUTOSTARTSTOP = yes'
- fi
- ctdb_service_stop
- exit $?
- ;;
- esac
-
- # Do nothing unless configured to...
- [ "$CTDB_SERVICE_AUTOSTARTSTOP" = "yes" ] || return 0
-
- [ "$event_name" = "monitor" ] || return 0
-
- if is_ctdb_managed_service ; then
- if ! is_ctdb_previously_managed_service ; then
- echo "Starting service \"$service_name\" - now managed"
- background_with_logging ctdb_service_start
- exit $?
- fi
- else
- if is_ctdb_previously_managed_service ; then
- echo "Stopping service \"$service_name\" - no longer managed"
- background_with_logging ctdb_service_stop
- exit $?
- fi
- fi
-}
-
-ctdb_service_start ()
-{
- # The service is marked managed if we've ever tried to start it.
- ctdb_service_managed
-
- service_start || return $?
-
- ctdb_counter_init
- ctdb_check_tcp_init
-}
-
-ctdb_service_stop ()
-{
- ctdb_service_unmanaged
- service_stop
-}
-