allow net ads join accept new osServicePack parameter
[Samba.git] / ctdb / config / events.d / 50.samba
blob4b53cba01be6f9736a25a2509df692755fc7b73a
1 #!/bin/sh
2 # ctdb event script for Samba
4 [ -n "$CTDB_BASE" ] || \
5 export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
7 . $CTDB_BASE/functions
9 detect_init_style
11 case $CTDB_INIT_STYLE in
12 suse)
13 CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
14 CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb}
16 debian)
17 CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-samba}
18 CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
21 # Use redhat style as default:
22 CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
23 CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-""}
25 esac
27 service_name="samba"
29 loadconfig
31 ctdb_setup_service_state_dir
33 service_start ()
35 # make sure samba is not already started
36 service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
37 if [ -n "$CTDB_SERVICE_NMB" ] ; then
38 service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
40 killall -0 -q smbd && {
41 sleep 1
42 # make absolutely sure samba is dead
43 killall -q -9 smbd
45 killall -0 -q nmbd && {
46 sleep 1
47 # make absolutely sure samba is dead
48 killall -q -9 nmbd
51 # start Samba service. Start it reniced, as under very heavy load
52 # the number of smbd processes will mean that it leaves few cycles
53 # for anything else
54 net serverid wipe
56 if [ -n "$CTDB_SERVICE_NMB" ] ; then
57 nice_service "$CTDB_SERVICE_NMB" start || die "Failed to start nmbd"
60 nice_service "$CTDB_SERVICE_SMB" start || die "Failed to start samba"
63 service_stop ()
65 service "$CTDB_SERVICE_SMB" stop
66 if [ -n "$CTDB_SERVICE_NMB" ] ; then
67 service "$CTDB_SERVICE_NMB" stop
71 ######################################################################
72 # Show the testparm output using a cached smb.conf to avoid delays due
73 # to registry access.
75 smbconf_cache="$service_state_dir/smb.conf.cache"
77 testparm_foreground_update ()
79 _timeout="$1"
81 if ! _out=$(timeout $_timeout testparm -v -s 2>/dev/null) ; then
82 if [ -f "$smbconf_cache" ] ; then
83 echo "WARNING: smb.conf cache update failed - using old cache file"
84 return 1
85 else
86 die "ERROR: smb.conf cache create failed"
90 _tmpfile="${smbconf_cache}.$$"
91 # Patterns to exclude...
92 pat='^[[:space:]]+(registry[[:space:]]+shares|include|copy|winbind[[:space:]]+separator)[[:space:]]+='
93 echo "$_out" | grep -Ev "$pat" >"$_tmpfile"
94 mv "$_tmpfile" "$smbconf_cache" # atomic
96 return 0
99 testparm_background_update ()
101 _timeout="$1"
103 testparm_foreground_update $_timeout >/dev/null 2>&1 </dev/null &
106 testparm_cat ()
108 testparm -s "$smbconf_cache" "$@" 2>/dev/null
111 list_samba_shares ()
113 testparm_cat |
114 sed -n -e 's@^[[:space:]]*path[[:space:]]*=[[:space:]]@@p' |
115 sed -e 's/"//g'
118 list_samba_ports ()
120 testparm_cat --parameter-name="smb ports" |
121 sed -e 's@,@ @g'
124 ###########################
126 ctdb_start_stop_service
128 is_ctdb_managed_service || exit 0
130 ###########################
132 case "$1" in
133 startup)
134 ctdb_service_start
137 shutdown)
138 ctdb_service_stop
141 monitor)
142 testparm_foreground_update 10
143 ret=$?
145 smb_ports="$CTDB_SAMBA_CHECK_PORTS"
146 if [ -z "$smb_ports" ] ; then
147 smb_ports=$(list_samba_ports)
148 [ -n "$smb_ports" ] || die "Failed to set smb ports"
150 ctdb_check_tcp_ports $smb_ports || exit $?
152 if [ "$CTDB_SAMBA_SKIP_SHARE_CHECK" != "yes" ] ; then
153 list_samba_shares | ctdb_check_directories || exit $?
156 if [ $ret -ne 0 ] ; then
157 testparm_background_update 10
162 ctdb_standard_event_handler "$@"
164 esac
166 exit 0