[Samba] restarting samba using a cron job on Debian
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
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
# Check if samba replication broke down and restart samba in this case
FAIL=`$SAMBA_TOOL drs showrepl | $SED -n "/^\s*[1-9][0-9]* consecutive
if [[ -n "$FAIL" ]]; then
$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"
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
Stopping NetBIOS name server: nmbd.
Stopping SMB/CIFS daemon: smbd.
Stopping Samba AD DC daemon: samba.
Starting Samba AD DC daemon: samba failed!
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,
More information about the samba