summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2011-08-11 09:39:25 +1000
committerMartin Schwenke <martin@meltin.net>2011-08-11 10:46:20 +1000
commit428e32d6475c7ef8ecc70cf61731cd94a22c2fbb (patch)
tree525b1db33d7f473745a9db029fd064c7357eca73
parentf60802c77600c6503f19060ee90791817236fe13 (diff)
downloadsamba-428e32d6475c7ef8ecc70cf61731cd94a22c2fbb.tar.gz
samba-428e32d6475c7ef8ecc70cf61731cd94a22c2fbb.tar.xz
samba-428e32d6475c7ef8ecc70cf61731cd94a22c2fbb.zip
Eventscript function: change service_start into a function.
service_start is currently a variable. This makes passing arguments hard. We change it to be a function and put default definitions into the functions file. We use a convention that if a service name argument is passed to a redefined version of service_start() or service_stop() then it will act unconditionally. If no argument is passed then it can use internal logic to decide if services should really be started. This is useful when a single eventscript handles multiple services. This is a cherry-pick of ae38895 that needed to be reset mid-stream. There is still some breakage following this commit. Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit 86e4aefed9fd1028660c98e3ea758c2b75ffc1d8)
-rwxr-xr-x[-rw-r--r--]ctdb/config/events.d/31.clamd7
-rwxr-xr-xctdb/config/events.d/40.vsftpd11
-rwxr-xr-xctdb/config/events.d/41.httpd12
-rwxr-xr-xctdb/config/events.d/50.samba52
-rwxr-xr-xctdb/config/events.d/60.nfs22
-rwxr-xr-xctdb/config/functions39
6 files changed, 93 insertions, 50 deletions
diff --git a/ctdb/config/events.d/31.clamd b/ctdb/config/events.d/31.clamd
index 73454d7c53..53739e24f3 100644..100755
--- a/ctdb/config/events.d/31.clamd
+++ b/ctdb/config/events.d/31.clamd
@@ -16,8 +16,11 @@ case $CTDB_INIT_STYLE in
;;
esac
-service_start="service $service_name stop > /dev/null 2>&1 ; service $service_name start"
-service_stop="service $service_name stop"
+service_start ()
+{
+ service $service_name stop > /dev/null 2>&1
+ service $service_name start
+}
loadconfig
diff --git a/ctdb/config/events.d/40.vsftpd b/ctdb/config/events.d/40.vsftpd
index 72190db2a6..8ce2066348 100755
--- a/ctdb/config/events.d/40.vsftpd
+++ b/ctdb/config/events.d/40.vsftpd
@@ -5,8 +5,15 @@
service_name="vsftpd"
# make sure the service is stopped first
-service_start="service $service_name stop > /dev/null 2>&1 ; service $service_name start"
-service_stop="service $service_name stop > /dev/null 2>&1"
+service_start ()
+{
+ service $service_name stop > /dev/null 2>&1
+ service $service_name start
+}
+service_stop ()
+{
+ service $service_name stop > /dev/null 2>&1
+}
service_reconfigure="service $service_name restart"
service_fail_limit=2
service_tcp_ports=21
diff --git a/ctdb/config/events.d/41.httpd b/ctdb/config/events.d/41.httpd
index e94bde3fad..1115ba4c2c 100755
--- a/ctdb/config/events.d/41.httpd
+++ b/ctdb/config/events.d/41.httpd
@@ -27,8 +27,16 @@ cleanup_httpd_semaphore_leak() {
##########
-service_start="cleanup_httpd_semaphore_leak; service $service_name start"
-service_stop="service $service_name stop; killall -q -9 $service_name || true"
+service_start ()
+{
+ cleanup_httpd_semaphore_leak
+ service $service_name start
+}
+service_stop ()
+{
+ service $service_name stop
+ killall -q -9 $service_name || true
+}
service_reconfigure="service $service_name restart"
loadconfig
diff --git a/ctdb/config/events.d/50.samba b/ctdb/config/events.d/50.samba
index 8008c9c30d..461ea07098 100755
--- a/ctdb/config/events.d/50.samba
+++ b/ctdb/config/events.d/50.samba
@@ -25,17 +25,17 @@ case $CTDB_INIT_STYLE in
esac
service_name="samba"
-service_start="start_samba"
-service_stop="stop_samba"
loadconfig
-start_samba() {
- # create the state directory for samba
- mkdir -p $CTDB_VARDIR/state/samba
+service_start ()
+{
+ # If set then we force-start the relevant service.
+ _service_name="$1"
# make sure samba is not already started
- is_ctdb_managed_service "samba" && {
+ if [ "$_service_name" = "samba" ] || \
+ is_ctdb_managed_service "samba" ; then
service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
killall -0 -q smbd && {
@@ -49,10 +49,11 @@ start_samba() {
# make absolutely sure samba is dead
killall -q -9 nmbd
}
- }
+ fi
# make sure winbind is not already started
- check_ctdb_manages_winbind && {
+ if [ "$_service_name" = "winbind" ] || \
+ check_ctdb_manages_winbind ; then
service "$CTDB_SERVICE_WINBIND" stop > /dev/null 2>&1
killall -0 -q winbindd && {
sleep 1
@@ -60,47 +61,52 @@ start_samba() {
killall -q -9 winbindd
}
- }
+ fi
# start the winbind service
- check_ctdb_manages_winbind && {
+ if [ "$_service_name" = "winbind" ] || \
+ check_ctdb_manages_winbind ; then
service "$CTDB_SERVICE_WINBIND" start || {
- echo failed to start winbind
- exit 1
+ echo failed to start winbind
+ exit 1
}
-
- }
+ fi
# start Samba service. Start it reniced, as under very heavy load
# the number of smbd processes will mean that it leaves few cycles for
# anything else
- is_ctdb_managed_service "samba" && {
+ if [ "$_service_name" = "samba" ] || \
+ is_ctdb_managed_service "samba" ; then
net serverid wipe
nice_service "$CTDB_SERVICE_NMB" start || {
echo failed to start nmbd
exit 1
}
-
nice_service "$CTDB_SERVICE_SMB" start || {
echo failed to start samba
exit 1
}
- }
- return 0
+ fi
}
-stop_samba() {
+service_stop ()
+{
+ # If set then we force-stop the relevant service.
+ _service_name="$1"
+
# shutdown Samba when ctdb goes down
- is_ctdb_managed_service "samba" && {
+ if [ "$_service_name" = "samba" ] || \
+ is_ctdb_managed_service "samba" ; then
service "$CTDB_SERVICE_SMB" stop
service "$CTDB_SERVICE_NMB" stop
- }
+ fi
# stop the winbind service
- check_ctdb_manages_winbind && {
+ if [ "$_service_name" = "winbind" ] || \
+ check_ctdb_manages_winbind ; then
service "$CTDB_SERVICE_WINBIND" stop
- }
+ fi
return 0
}
diff --git a/ctdb/config/events.d/60.nfs b/ctdb/config/events.d/60.nfs
index c0207eeaed..bdd9427f02 100755
--- a/ctdb/config/events.d/60.nfs
+++ b/ctdb/config/events.d/60.nfs
@@ -1,19 +1,21 @@
#!/bin/sh
# script to manage nfs in a clustered environment
-start_nfs() {
- mkdir -p $CTDB_VARDIR/state/nfs
- mkdir -p $CTDB_VARDIR/state/statd/ip
- startstop_nfs stop
- startstop_nfs start
- set_proc "sys/net/ipv4/tcp_tw_recycle" 1
-}
-
. $CTDB_BASE/functions
service_name="nfs"
-service_start="start_nfs"
-service_stop="startstop_nfs stop"
+service_start ()
+{
+ mkdir -p $CTDB_VARDIR/state/nfs
+ mkdir -p $CTDB_VARDIR/state/statd/ip
+ startstop_nfs stop
+ startstop_nfs start
+ set_proc "sys/net/ipv4/tcp_tw_recycle" 1
+}
+service_stop ()
+{
+ startstop_nfs stop
+}
service_reconfigure="startstop_nfs restart"
loadconfig
diff --git a/ctdb/config/functions b/ctdb/config/functions
index ee671e598e..452b8d0d97 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -731,23 +731,40 @@ ctdb_start_stop_service ()
ctdb_service_start ()
{
- if [ -n "$service_start" ] ; then
- eval $service_start || return $?
- else
- service "$service_name" start || return $?
- fi
- ctdb_counter_init
+ # Here we only want $1. If no argument is passed then
+ # service_start needs to know.
+ service_start "$@" || return $?
+
+ ctdb_counter_init "$@"
}
ctdb_service_stop ()
{
- if [ -n "$service_stop" ] ; then
- eval $service_stop
- else
- service "$service_name" stop
- fi
+ service_stop "$@"
+}
+
+# Default service_start() and service_stop() functions.
+
+# These may be overridden in an eventscript. When overriding, the
+# following convention must be followed. If these functions are
+# called with no arguments then they may use internal logic to
+# determine whether the service is managed and, therefore, whether
+# they should take any action. However, if the service name is
+# specified as an argument then an attempt must be made to start or
+# stop the service. This is because the auto-start/stop code calls
+# them with the service name as an argument.
+service_start ()
+{
+ service "${1:-${service_name}}" start
+}
+
+service_stop ()
+{
+ service "${1:-${service_name}}" stop
}
+##################################################################
+
ctdb_standard_event_handler ()
{
case "$1" in