27
27
service_name="samba"
28
service_start="start_samba"
29
service_stop="stop_samba"
34
# create the state directory for samba
35
/bin/mkdir -p $CTDB_VARDIR/state/samba
31
ctdb_setup_service_state_dir
35
# If set then we force-start the relevant service.
37
38
# make sure samba is not already started
38
[ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
39
if [ "$_service_name" = "samba" ] || \
40
is_ctdb_managed_service "samba" ; then
39
41
service "$CTDB_SERVICE_SMB" stop > /dev/null 2>&1
40
service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
42
if [ -n "$CTDB_SERVICE_NMB" ] ; then
43
service "$CTDB_SERVICE_NMB" stop > /dev/null 2>&1
41
45
killall -0 -q smbd && {
43
47
# make absolutely sure samba is dead
49
53
# make absolutely sure samba is dead
54
58
# make sure winbind is not already started
55
check_ctdb_manages_winbind
56
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
59
if [ "$_service_name" = "winbind" ] || \
60
check_ctdb_manages_winbind ; then
57
61
service "$CTDB_SERVICE_WINBIND" stop > /dev/null 2>&1
58
62
killall -0 -q winbindd && {
61
65
killall -q -9 winbindd
66
70
# start the winbind service
67
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
71
if [ "$_service_name" = "winbind" ] || \
72
check_ctdb_manages_winbind ; then
68
73
service "$CTDB_SERVICE_WINBIND" start || {
69
echo failed to start winbind
74
echo failed to start winbind
75
79
# start Samba service. Start it reniced, as under very heavy load
76
80
# the number of smbd processes will mean that it leaves few cycles for
78
[ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
79
/usr/bin/net serverid wipe
82
if [ "$_service_name" = "samba" ] || \
83
is_ctdb_managed_service "samba" ; then
81
nice_service "$CTDB_SERVICE_NMB" start || {
86
if [ -n "$CTDB_SERVICE_NMB" ] ; then
87
nice_service "$CTDB_SERVICE_NMB" start || {
82
88
echo failed to start nmbd
86
92
nice_service "$CTDB_SERVICE_SMB" start || {
87
93
echo failed to start samba
101
# If set then we force-stop the relevant service.
95
104
# shutdown Samba when ctdb goes down
96
[ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
105
if [ "$_service_name" = "samba" ] || \
106
is_ctdb_managed_service "samba" ; then
97
107
service "$CTDB_SERVICE_SMB" stop
98
service "$CTDB_SERVICE_NMB" stop
108
if [ -n "$CTDB_SERVICE_NMB" ] ; then
109
service "$CTDB_SERVICE_NMB" stop
101
113
# stop the winbind service
102
check_ctdb_manages_winbind
103
[ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
114
if [ "$_service_name" = "winbind" ] || \
115
check_ctdb_manages_winbind ; then
104
116
service "$CTDB_SERVICE_WINBIND" stop
120
service_reconfigure ()
122
# Samba automatically reloads config - no restart needed.
110
126
# set default samba cleanup period - in minutes
115
131
# we keep a cached copy of smb.conf here
116
smbconf_cache="$CTDB_VARDIR/state/samba/smb.conf.cache"
132
smbconf_cache="$service_state_dir/smb.conf.cache"
119
135
#############################################
120
136
# update the smb.conf cache in the foreground
121
137
testparm_foreground_update() {
122
mkdir -p "$CTDB_VARDIR/state/samba" || exit 1
123
138
testparm -s 2> /dev/null | egrep -v 'registry.shares.=|include.=' > "$smbconf_cache"
141
156
while [ $timeleft -gt 0 ]; do
142
157
timeleft=$(($timeleft - 1))
143
158
# see if the process still exists
144
/bin/kill -0 $pid > /dev/null 2>&1 || {
159
kill -0 $pid > /dev/null 2>&1 || {
145
160
# it doesn't exist, grab its exit status
183
198
testparm -s "$smbconf_cache" "$@" 2>/dev/null
186
# function to see if ctdb manages winbind
201
# function to see if ctdb manages winbind - this overrides with extra
202
# logic if $CTDB_MANAGES_WINBIND is not set or null.
187
203
check_ctdb_manages_winbind() {
188
[ -z "$CTDB_MANAGES_WINBIND" ] && {
189
secmode=`testparm_cat --parameter-name=security`
192
CTDB_MANAGES_WINBIND="yes";
195
CTDB_MANAGES_WINBIND="no";
204
if is_ctdb_managed_service "winbind" ; then
206
elif [ -n "$CTDB_MANAGES_WINBIND" ] ; then
207
# If this variable is set we want to respect it. We return
208
# false here because we know it is not set to "yes" - if it
209
# were then the 1st "if" above would have succeeded.
212
_secmode=`testparm_cat --parameter-name=security`
201
224
list_samba_shares ()
239
260
# Create a dummy file to track when we need to do periodic cleanup
240
261
# of samba databases
241
[ -f $CTDB_VARDIR/state/samba/periodic_cleanup ] || {
242
touch $CTDB_VARDIR/state/samba/periodic_cleanup
262
periodic_cleanup_file="$service_state_dir/periodic_cleanup"
263
[ -f "$periodic_cleanup_file" ] || {
264
touch "$periodic_cleanup_file"
244
[ `/usr/bin/find $CTDB_VARDIR/state/samba/periodic_cleanup -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
266
[ `find "$periodic_cleanup_file" -mmin +$SAMBA_CLEANUP_PERIOD | wc -l` -eq 1 ] && {
245
267
# Cleanup the databases
247
touch $CTDB_VARDIR/state/samba/periodic_cleanup
269
touch "$periodic_cleanup_file"
250
[ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
272
is_ctdb_managed_service "samba" && {
251
273
[ "$CTDB_SAMBA_SKIP_SHARE_CHECK" = "yes" ] || {
252
274
testparm_background_update