~ubuntu-branches/ubuntu/vivid/ctdb/vivid-proposed

« back to all changes in this revision

Viewing changes to config/events.d/50.samba

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2011-11-06 15:18:59 UTC
  • mto: (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20111106151859-84nk51h3enndlo4q
Tags: upstream-1.11+git20111102
ImportĀ upstreamĀ versionĀ 1.11+git20111102

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
esac
26
26
 
27
27
service_name="samba"
28
 
service_start="start_samba"
29
 
service_stop="stop_samba"
30
28
 
31
29
loadconfig
32
30
 
33
 
start_samba() {
34
 
        # create the state directory for samba
35
 
        /bin/mkdir -p $CTDB_VARDIR/state/samba
 
31
ctdb_setup_service_state_dir
 
32
 
 
33
service_start ()
 
34
{
 
35
        # If set then we force-start the relevant service.
 
36
        _service_name="$1"
36
37
 
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
 
44
                fi
41
45
                killall -0 -q smbd && {
42
46
                    sleep 1
43
47
                    # make absolutely sure samba is dead
49
53
                    # make absolutely sure samba is dead
50
54
                    killall -q -9 nmbd
51
55
                }
52
 
        }
 
56
        fi
53
57
 
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 && {
59
63
                    sleep 1
61
65
                    killall -q -9 winbindd
62
66
                }
63
67
 
64
 
        }
 
68
        fi
65
69
 
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
70
 
                        exit 1
 
74
                    echo failed to start winbind
 
75
                    exit 1
71
76
                }
72
 
 
73
 
        }
 
77
        fi
74
78
 
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
77
81
        # anything else
78
 
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
79
 
                /usr/bin/net serverid wipe
 
82
        if [ "$_service_name" = "samba" ] || \
 
83
            is_ctdb_managed_service "samba" ; then
 
84
                net serverid wipe
80
85
 
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
83
89
                        exit 1
84
 
                }
85
 
 
 
90
                    }
 
91
                fi
86
92
                nice_service "$CTDB_SERVICE_SMB" start || {
87
93
                        echo failed to start samba
88
94
                        exit 1
89
95
                }
90
 
        }
91
 
        return 0
 
96
        fi
92
97
}
93
98
 
94
 
stop_samba() {
 
99
service_stop ()
 
100
{
 
101
        # If set then we force-stop the relevant service.
 
102
        _service_name="$1"
 
103
 
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
99
 
        }
 
108
                if [ -n "$CTDB_SERVICE_NMB" ] ; then
 
109
                    service "$CTDB_SERVICE_NMB" stop
 
110
                fi
 
111
        fi
100
112
 
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
105
 
        }
 
117
        fi
 
118
}
106
119
 
107
 
        return 0
 
120
service_reconfigure ()
 
121
{
 
122
    # Samba automatically reloads config - no restart needed.
 
123
    :
108
124
}
109
125
 
110
126
# set default samba cleanup period - in minutes
113
129
}
114
130
 
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"
117
133
 
118
134
 
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"
124
139
}
125
140
 
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
146
161
                wait $pid
147
162
                [ $? = 0 ] || {
167
182
        done
168
183
        # it took more than 10 seconds - kill it off
169
184
        rm -f "${tmpfile}"
170
 
        /bin/kill -9 "$pid" > /dev/null 2>&1
 
185
        kill -9 "$pid" > /dev/null 2>&1
171
186
        echo "50.samba: timed out updating smbconf cache in background"
172
187
        exit 1
173
188
    ) &
183
198
    testparm -s "$smbconf_cache" "$@" 2>/dev/null
184
199
}
185
200
 
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`
190
 
    case $secmode in
191
 
        ADS|DOMAIN)
192
 
            CTDB_MANAGES_WINBIND="yes";
193
 
            ;;
194
 
        *)
195
 
            CTDB_MANAGES_WINBIND="no";
196
 
            ;;
197
 
    esac
198
 
  }
 
204
    if is_ctdb_managed_service "winbind" ; then
 
205
        return 0
 
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.
 
210
        return 1
 
211
    else
 
212
        _secmode=`testparm_cat --parameter-name=security`
 
213
        case "$_secmode" in
 
214
            ADS|DOMAIN)
 
215
                return 0
 
216
                ;;
 
217
            *)
 
218
                return 1
 
219
                ;;
 
220
        esac
 
221
    fi
199
222
}
200
223
 
201
224
list_samba_shares ()
217
240
 
218
241
###########################
219
242
 
220
 
[ "$1" = "monitor" ] && {
221
243
ctdb_start_stop_service
222
244
ctdb_start_stop_service "winbind"
223
 
}
224
245
 
225
246
is_ctdb_managed_service || is_ctdb_managed_service "winbind" || exit 0
226
247
 
238
259
     monitor)
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"
243
265
        }
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
246
268
                periodic_cleanup
247
 
                touch $CTDB_VARDIR/state/samba/periodic_cleanup
 
269
                touch "$periodic_cleanup_file"
248
270
        }
249
271
 
250
 
        [ "$CTDB_MANAGES_SAMBA" = "yes" ] && {
 
272
        is_ctdb_managed_service "samba" && {
251
273
                [ "$CTDB_SAMBA_SKIP_SHARE_CHECK" = "yes" ] || {
252
274
                        testparm_background_update
253
275
 
275
297
        }
276
298
 
277
299
        # check winbind is OK
278
 
        check_ctdb_manages_winbind
279
 
        [ "$CTDB_MANAGES_WINBIND" = "yes" ] && {
 
300
        check_ctdb_manages_winbind && {
280
301
                ctdb_check_command "winbind" "wbinfo -p"
281
302
        }
282
303
        ;;