mirror of
https://github.com/samba-team/samba.git
synced 2025-02-24 13:57:43 +03:00
Eventscripts: split 50.samba into 49.winbind and 50.samba
winbind and samba can be separately managed. This makes the service starting and stopping code way too complicated, and even adds a small amount of complexity to the monitoring code. The sensible option is to split this eventscript in two. There are two potentially backward incompatible changes here: * Functionality has been removed that allowed 50.samba to manage winbind when CTDB_MANAGES_WINBIND was unset but the smb.conf "security" parameter was set to "ADS" or "DOMAIN". Maintaining this functionality would have required moving the testparm-related code to the functions file, deciding where the cache file should go, and then calling it from both 49.winbind and 50.samba. This feature wasn't of great value and asking administrators to set an extra variable in exchange for code simplicity seems like a reasonable deal. * External code will need to be changed if it calls 50.samba directly with winbind-related expectations. This is fairly obvious! Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit 34535ae64420926b9a3bf7d453fed4e6f4c90115)
This commit is contained in:
parent
e2d4250731
commit
f3ae31e741
@ -341,6 +341,7 @@ install: all $(PMDA_INSTALL)
|
||||
${INSTALLCMD} -m 755 config/events.d/40.vsftpd $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
${INSTALLCMD} -m 644 config/events.d/40.fs_use $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
${INSTALLCMD} -m 755 config/events.d/41.httpd $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
${INSTALLCMD} -m 755 config/events.d/49.winbind $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
${INSTALLCMD} -m 755 config/events.d/50.samba $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
${INSTALLCMD} -m 755 config/events.d/60.nfs $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
${INSTALLCMD} -m 755 config/events.d/60.ganesha $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
|
75
ctdb/config/events.d/49.winbind
Executable file
75
ctdb/config/events.d/49.winbind
Executable file
@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# ctdb event script for winbind
|
||||
|
||||
. $CTDB_BASE/functions
|
||||
|
||||
detect_init_style
|
||||
|
||||
CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
|
||||
|
||||
service_name="winbind"
|
||||
|
||||
loadconfig
|
||||
|
||||
ctdb_setup_service_state_dir
|
||||
|
||||
service_start ()
|
||||
{
|
||||
service "$CTDB_SERVICE_WINBIND" stop >/dev/null 2>&1
|
||||
killall -0 -q winbindd && {
|
||||
sleep 1
|
||||
# make absolutely sure winbindd is dead
|
||||
killall -q -9 winbindd
|
||||
}
|
||||
|
||||
service "$CTDB_SERVICE_WINBIND" start || \
|
||||
die "Failed to start winbind"
|
||||
}
|
||||
|
||||
service_stop ()
|
||||
{
|
||||
service "$CTDB_SERVICE_WINBIND" stop
|
||||
}
|
||||
|
||||
service_reconfigure ()
|
||||
{
|
||||
# winbind automatically reloads config - no restart needed.
|
||||
:
|
||||
}
|
||||
|
||||
###########################
|
||||
|
||||
ctdb_start_stop_service
|
||||
|
||||
is_ctdb_managed_service || exit 0
|
||||
|
||||
ctdb_service_check_reconfigure
|
||||
|
||||
###########################
|
||||
|
||||
case "$1" in
|
||||
startup)
|
||||
ctdb_service_start
|
||||
;;
|
||||
|
||||
shutdown)
|
||||
ctdb_service_stop
|
||||
;;
|
||||
|
||||
monitor)
|
||||
ctdb_check_command "winbind" "wbinfo -p"
|
||||
;;
|
||||
|
||||
takeip|releaseip)
|
||||
iface=$2
|
||||
ip=$3
|
||||
maskbits=$4
|
||||
|
||||
smbcontrol winbindd ip-dropped $ip >/dev/null 2>/dev/null
|
||||
;;
|
||||
*)
|
||||
ctdb_standard_event_handler "$@"
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
@ -9,18 +9,15 @@ case $CTDB_INIT_STYLE in
|
||||
suse)
|
||||
CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
|
||||
CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb}
|
||||
CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
|
||||
;;
|
||||
debian)
|
||||
CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-samba}
|
||||
CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
|
||||
CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
|
||||
;;
|
||||
*)
|
||||
# should not happen, but for now use redhat style as default:
|
||||
# Use redhat style as default:
|
||||
CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
|
||||
CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
|
||||
CTDB_SERVICE_WINBIND=${CTDB_SERVICE_WINBIND:-winbind}
|
||||
;;
|
||||
esac
|
||||
|
||||
@ -32,89 +29,40 @@ ctdb_setup_service_state_dir
|
||||
|
||||
service_start ()
|
||||
{
|
||||
# If set then we force-start the relevant service.
|
||||
_service_name="$1"
|
||||
# make sure samba is not already started
|
||||
service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
|
||||
if [ -n "$CTDB_SERVICE_NMB" ] ; then
|
||||
service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
|
||||
fi
|
||||
killall -0 -q smbd && {
|
||||
sleep 1
|
||||
# make absolutely sure samba is dead
|
||||
killall -q -9 smbd
|
||||
}
|
||||
killall -0 -q nmbd && {
|
||||
sleep 1
|
||||
# make absolutely sure samba is dead
|
||||
killall -q -9 nmbd
|
||||
}
|
||||
|
||||
# make sure samba is not already started
|
||||
if [ "$_service_name" = "samba" ] || \
|
||||
is_ctdb_managed_service "samba" ; then
|
||||
service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
|
||||
if [ -n "$CTDB_SERVICE_NMB" ] ; then
|
||||
service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
|
||||
fi
|
||||
killall -0 -q smbd && {
|
||||
sleep 1
|
||||
# make absolutely sure samba is dead
|
||||
killall -q -9 smbd
|
||||
}
|
||||
# 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
|
||||
net serverid wipe
|
||||
|
||||
killall -0 -q nmbd && {
|
||||
sleep 1
|
||||
# make absolutely sure samba is dead
|
||||
killall -q -9 nmbd
|
||||
}
|
||||
fi
|
||||
if [ -n "$CTDB_SERVICE_NMB" ] ; then
|
||||
nice_service "$CTDB_SERVICE_NMB" start || die "Failed to start nmbd"
|
||||
fi
|
||||
|
||||
# make sure winbind is not already started
|
||||
if [ "$_service_name" = "winbind" ] || \
|
||||
check_ctdb_manages_winbind ; then
|
||||
service "$CTDB_SERVICE_WINBIND" stop > /dev/null 2>&1
|
||||
killall -0 -q winbindd && {
|
||||
sleep 1
|
||||
# make absolutely sure winbindd is dead
|
||||
killall -q -9 winbindd
|
||||
}
|
||||
|
||||
fi
|
||||
|
||||
# start the winbind service
|
||||
if [ "$_service_name" = "winbind" ] || \
|
||||
check_ctdb_manages_winbind ; then
|
||||
service "$CTDB_SERVICE_WINBIND" start || {
|
||||
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
|
||||
if [ "$_service_name" = "samba" ] || \
|
||||
is_ctdb_managed_service "samba" ; then
|
||||
net serverid wipe
|
||||
|
||||
if [ -n "$CTDB_SERVICE_NMB" ] ; then
|
||||
nice_service "$CTDB_SERVICE_NMB" start || {
|
||||
echo failed to start nmbd
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
nice_service "$CTDB_SERVICE_SMB" start || {
|
||||
echo failed to start samba
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
nice_service "$CTDB_SERVICE_SMB" start || die "Failed to start samba"
|
||||
}
|
||||
|
||||
service_stop ()
|
||||
{
|
||||
# If set then we force-stop the relevant service.
|
||||
_service_name="$1"
|
||||
|
||||
# shutdown Samba when ctdb goes down
|
||||
if [ "$_service_name" = "samba" ] || \
|
||||
is_ctdb_managed_service "samba" ; then
|
||||
service "$CTDB_SERVICE_SMB" stop
|
||||
if [ -n "$CTDB_SERVICE_NMB" ] ; then
|
||||
service "$CTDB_SERVICE_NMB" stop
|
||||
fi
|
||||
fi
|
||||
|
||||
# stop the winbind service
|
||||
if [ "$_service_name" = "winbind" ] || \
|
||||
check_ctdb_manages_winbind ; then
|
||||
service "$CTDB_SERVICE_WINBIND" stop
|
||||
fi
|
||||
service "$CTDB_SERVICE_SMB" stop
|
||||
if [ -n "$CTDB_SERVICE_NMB" ] ; then
|
||||
service "$CTDB_SERVICE_NMB" stop
|
||||
fi
|
||||
}
|
||||
|
||||
service_reconfigure ()
|
||||
@ -148,7 +96,7 @@ testparm_background_update() {
|
||||
# otherwise do a background update
|
||||
(
|
||||
tmpfile="${smbconf_cache}.$$"
|
||||
testparm -s > $tmpfile 2> /dev/null &
|
||||
testparm -v -s > $tmpfile 2> /dev/null &
|
||||
# remember the pid of the teamparm process
|
||||
pid="$!"
|
||||
# give it 10 seconds to run
|
||||
@ -195,30 +143,7 @@ testparm_cat() {
|
||||
[ -f $smbconf_cache ] || {
|
||||
testparm_foreground_update
|
||||
}
|
||||
testparm -s "$smbconf_cache" "$@" 2>/dev/null
|
||||
}
|
||||
|
||||
# function to see if ctdb manages winbind - this overrides with extra
|
||||
# logic if $CTDB_MANAGES_WINBIND is not set or null.
|
||||
check_ctdb_manages_winbind() {
|
||||
if is_ctdb_managed_service "winbind" ; then
|
||||
return 0
|
||||
elif [ -n "$CTDB_MANAGES_WINBIND" ] ; then
|
||||
# If this variable is set we want to respect it. We return
|
||||
# false here because we know it is not set to "yes" - if it
|
||||
# were then the 1st "if" above would have succeeded.
|
||||
return 1
|
||||
else
|
||||
_secmode=`testparm_cat --parameter-name=security`
|
||||
case "$_secmode" in
|
||||
ADS|DOMAIN)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
testparm -v -s "$smbconf_cache" "$@" 2>/dev/null
|
||||
}
|
||||
|
||||
list_samba_shares ()
|
||||
@ -241,9 +166,10 @@ periodic_cleanup() {
|
||||
###########################
|
||||
|
||||
ctdb_start_stop_service
|
||||
ctdb_start_stop_service "winbind"
|
||||
|
||||
is_ctdb_managed_service || is_ctdb_managed_service "winbind" || exit 0
|
||||
is_ctdb_managed_service || exit 0
|
||||
|
||||
ctdb_service_check_reconfigure
|
||||
|
||||
###########################
|
||||
|
||||
@ -269,46 +195,29 @@ case "$1" in
|
||||
touch "$periodic_cleanup_file"
|
||||
}
|
||||
|
||||
is_ctdb_managed_service "samba" && {
|
||||
[ "$CTDB_SAMBA_SKIP_SHARE_CHECK" = "yes" ] || {
|
||||
testparm_background_update
|
||||
if [ "$CTDB_SAMBA_SKIP_SHARE_CHECK" != "yes" ] ; then
|
||||
testparm_background_update
|
||||
|
||||
testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && {
|
||||
testparm_foreground_update
|
||||
testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && {
|
||||
echo "ERROR: testparm shows smb.conf is not clean"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && {
|
||||
testparm_foreground_update
|
||||
testparm_cat | egrep '^WARNING|^ERROR|^Unknown' && \
|
||||
die "ERROR: testparm shows smb.conf is not clean"
|
||||
}
|
||||
|
||||
list_samba_shares |
|
||||
ctdb_check_directories_probe || {
|
||||
testparm_foreground_update
|
||||
list_samba_shares |
|
||||
ctdb_check_directories
|
||||
} || exit $?
|
||||
}
|
||||
list_samba_shares | ctdb_check_directories_probe || {
|
||||
testparm_foreground_update
|
||||
list_samba_shares |
|
||||
ctdb_check_directories
|
||||
} || exit $?
|
||||
fi
|
||||
|
||||
smb_ports="$CTDB_SAMBA_CHECK_PORTS"
|
||||
[ -z "$smb_ports" ] && {
|
||||
smb_ports=`testparm_cat --parameter-name="smb ports"`
|
||||
}
|
||||
ctdb_check_tcp_ports $smb_ports || exit $?
|
||||
}
|
||||
|
||||
# check winbind is OK
|
||||
check_ctdb_manages_winbind && {
|
||||
ctdb_check_command "winbind" "wbinfo -p"
|
||||
}
|
||||
smb_ports="$CTDB_SAMBA_CHECK_PORTS"
|
||||
if [ -z "$smb_ports" ] ; then
|
||||
smb_ports=`testparm_cat --parameter-name="smb ports"`
|
||||
fi
|
||||
ctdb_check_tcp_ports $smb_ports || exit $?
|
||||
;;
|
||||
|
||||
takeip|releaseip)
|
||||
iface=$2
|
||||
ip=$3
|
||||
maskbits=$4
|
||||
|
||||
smbcontrol winbindd ip-dropped $ip >/dev/null 2>/dev/null
|
||||
;;
|
||||
*)
|
||||
ctdb_standard_event_handler "$@"
|
||||
;;
|
||||
|
@ -139,6 +139,7 @@ rm -rf $RPM_BUILD_ROOT
|
||||
%{_sysconfdir}/ctdb/events.d/40.fs_use
|
||||
%{_sysconfdir}/ctdb/events.d/40.vsftpd
|
||||
%{_sysconfdir}/ctdb/events.d/41.httpd
|
||||
%{_sysconfdir}/ctdb/events.d/49.winbind
|
||||
%{_sysconfdir}/ctdb/events.d/50.samba
|
||||
%{_sysconfdir}/ctdb/events.d/60.nfs
|
||||
%{_sysconfdir}/ctdb/events.d/60.ganesha
|
||||
|
11
ctdb/tests/eventscripts/49.winbind.monitor.001.sh
Executable file
11
ctdb/tests/eventscripts/49.winbind.monitor.001.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "not managed, check no-op"
|
||||
|
||||
setup_winbind "down"
|
||||
|
||||
ok_null
|
||||
|
||||
simple_test
|
17
ctdb/tests/eventscripts/49.winbind.monitor.050.sh
Executable file
17
ctdb/tests/eventscripts/49.winbind.monitor.050.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "auto-start, simple"
|
||||
|
||||
setup_winbind "down"
|
||||
|
||||
export CTDB_SERVICE_AUTOSTARTSTOP="yes"
|
||||
export CTDB_MANAGED_SERVICES="foo winbind bar"
|
||||
|
||||
ok <<EOF
|
||||
Starting service "winbind" - now managed
|
||||
Starting winbind: OK
|
||||
EOF
|
||||
|
||||
simple_test
|
18
ctdb/tests/eventscripts/49.winbind.monitor.051.sh
Executable file
18
ctdb/tests/eventscripts/49.winbind.monitor.051.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "auto-stop, simple"
|
||||
|
||||
setup_winbind
|
||||
|
||||
export CTDB_SERVICE_AUTOSTARTSTOP="yes"
|
||||
export CTDB_MANAGED_SERVICES="foo"
|
||||
unset CTDB_MANAGES_WINBIND
|
||||
|
||||
ok <<EOF
|
||||
Stopping service "winbind" - no longer managed
|
||||
Stopping winbind: OK
|
||||
EOF
|
||||
|
||||
simple_test
|
11
ctdb/tests/eventscripts/49.winbind.monitor.101.sh
Executable file
11
ctdb/tests/eventscripts/49.winbind.monitor.101.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "all OK"
|
||||
|
||||
setup_winbind
|
||||
|
||||
ok_null
|
||||
|
||||
simple_test
|
@ -4,7 +4,7 @@
|
||||
|
||||
define_test "winbind down"
|
||||
|
||||
setup_samba
|
||||
setup_winbind
|
||||
wbinfo_down
|
||||
|
||||
required_result 1 "ERROR: winbind - wbinfo -p returned error"
|
@ -11,7 +11,6 @@ export CTDB_MANAGED_SERVICES="foo samba winbind bar"
|
||||
|
||||
ok <<EOF
|
||||
Starting service "samba" - now managed
|
||||
Starting winbind: OK
|
||||
Starting smb: OK
|
||||
EOF
|
||||
|
||||
|
@ -9,12 +9,10 @@ setup_samba
|
||||
export CTDB_SERVICE_AUTOSTARTSTOP="yes"
|
||||
export CTDB_MANAGED_SERVICES="foo"
|
||||
unset CTDB_MANAGES_SAMBA
|
||||
unset CTDB_MANAGES_WINBIND
|
||||
|
||||
ok <<EOF
|
||||
Stopping service "samba" - no longer managed
|
||||
Stopping smb: OK
|
||||
Stopping winbind: OK
|
||||
EOF
|
||||
|
||||
simple_test
|
||||
|
@ -374,7 +374,7 @@ setup_ctdb_policy_routing ()
|
||||
|
||||
######################################################################
|
||||
|
||||
# Samba fakery
|
||||
# Samba/winbind fakery
|
||||
|
||||
setup_samba ()
|
||||
{
|
||||
@ -384,16 +384,15 @@ setup_samba ()
|
||||
|
||||
debug "Marking Samba services as up, listening and managed by CTDB"
|
||||
# Get into known state.
|
||||
for i in "samba" "winbind" ; do
|
||||
eventscript_call ctdb_service_managed "$i"
|
||||
done
|
||||
eventscript_call ctdb_service_managed "samba"
|
||||
|
||||
# All possible service names for all known distros.
|
||||
for i in "smb" "nmb" "winbind" "samba" ; do
|
||||
for i in "smb" "nmb" "samba" ; do
|
||||
service "$i" force-started
|
||||
done
|
||||
|
||||
export CTDB_SAMBA_SKIP_SHARE_CHECK="no"
|
||||
export CTDB_MANAGED_SERVICES="foo samba winbind bar"
|
||||
export CTDB_MANAGED_SERVICES="foo samba bar"
|
||||
|
||||
export FAKE_TCP_LISTEN="0.0.0.0:445 0.0.0.0:139"
|
||||
export FAKE_WBINFO_FAIL="no"
|
||||
@ -405,18 +404,16 @@ setup_samba ()
|
||||
else
|
||||
debug "Marking Samba services as down, not listening and not managed by CTDB"
|
||||
# Get into known state.
|
||||
for i in "samba" "winbind" ; do
|
||||
eventscript_call ctdb_service_unmanaged "$i"
|
||||
done
|
||||
eventscript_call ctdb_service_unmanaged "samba"
|
||||
|
||||
# All possible service names for all known distros.
|
||||
for i in "smb" "nmb" "winbind" "samba" ; do
|
||||
for i in "smb" "nmb" "samba" ; do
|
||||
service "$i" force-stopped
|
||||
done
|
||||
|
||||
export CTDB_SAMBA_SKIP_SHARE_CHECK="no"
|
||||
export CTDB_MANAGED_SERVICES="foo bar"
|
||||
unset CTDB_MANAGES_SAMBA
|
||||
unset CTDB_MANAGES_WINBIND
|
||||
|
||||
export FAKE_TCP_LISTEN=""
|
||||
export FAKE_WBINFO_FAIL="yes"
|
||||
@ -427,6 +424,36 @@ setup_samba ()
|
||||
rm -f "$CTDB_VARDIR/state/samba/smb.conf.cache"
|
||||
}
|
||||
|
||||
setup_winbind ()
|
||||
{
|
||||
setup_ctdb
|
||||
|
||||
if [ "$1" != "down" ] ; then
|
||||
|
||||
debug "Marking Winbind service as up and managed by CTDB"
|
||||
# Get into known state.
|
||||
eventscript_call ctdb_service_managed "winbind"
|
||||
|
||||
service "winbind" force-started
|
||||
|
||||
export CTDB_MANAGED_SERVICES="foo winbind bar"
|
||||
|
||||
export FAKE_WBINFO_FAIL="no"
|
||||
|
||||
else
|
||||
debug "Marking Winbind service as down and not managed by CTDB"
|
||||
# Get into known state.
|
||||
eventscript_call ctdb_service_unmanaged "winbind"
|
||||
|
||||
service "winbind" force-stopped
|
||||
|
||||
export CTDB_MANAGED_SERVICES="foo bar"
|
||||
unset CTDB_MANAGES_WINBIND
|
||||
|
||||
export FAKE_WBINFO_FAIL="yes"
|
||||
fi
|
||||
}
|
||||
|
||||
wbinfo_down ()
|
||||
{
|
||||
debug "Making wbinfo commands fail"
|
||||
|
Loading…
x
Reference in New Issue
Block a user