[Samba] restarting samba using a cron job on Debian
Lars Hanke
debian at lhanke.de
Mon Nov 30 10:01:01 UTC 2015
For some reason my secondary DC loses sync every once in a while. It
looks like this in samba-tool drs showrepl:
Last attempt @ Thu Nov 19 13:53:09 2015 CET failed, result 5
(WERR_ACCESS_DENIED)
229 consecutive failure(s).
Last success @ Wed Nov 18 18:48:07 2015 CET
Restarting samba fixes the issue for an unpredictable time. Sometimes
hours, sometimes many weeks. So I wrote a script to restart samba in
this case:
#!/bin/bash
#
# Check if samba replication broke down and restart samba in this case
#
SAMBA_TOOL=/usr/bin/samba-tool
SED=/bin/sed
MAIL=/usr/bin/mail
RM=/bin/rm
MKTMP=/bin/mktemp
FAIL=`$SAMBA_TOOL drs showrepl | $SED -n "/^\s*[1-9][0-9]* consecutive
failure(s)\.$/p"`
if [[ -n "$FAIL" ]]; then
TMP=$($MKTMP)
$SAMBA_TOOL drs showrepl > "$TMP"
echo "Restart ..." >> "$TMP"
/etc/init.d/samba restart >> "$TMP"
echo "... done!" >> "$TMP"
$MAIL -s 'DC2 restart' sysop at example.com < "$TMP"
$RM -f "$TMP"
fi
And it works perfectly, if I run it manually. However, the idea is to
run it by cron every 5 minutes. But when it's run from cron restarting
samba fails:
Restart ...
Stopping NetBIOS name server: nmbd.
Stopping SMB/CIFS daemon: smbd.
Stopping Samba AD DC daemon: samba.
Starting Samba AD DC daemon: samba failed!
... done!
Running the same script manually from a root shell works however fine.
The system is Debian Jessie using samba 4.1.17-Debian. I start the
script using the following entry in root's crontab:
*/5 * * * * /root/samba-restart.sh
Any ideas what I'm doing wrong?
Thanks for your help,
- lars.
More information about the samba
mailing list