rc.samba for smbd
This is an advanced new version ;-)
I have separated everything in functions, therefore actions may be put together from these modules as required (less repeat).
The script is still incomplete, as there was a problem logging start and stop actions. I will fix it someday...
The name service, nmbd is not handled in this script!
#!/usr/bin/ksh## Samba control script# (c) LGee## Variables specific to the Samba installationx_libpath=/usr/local/libx_smbpath="/usr/local/bin:/usr/local/sbin"x_smbconf=/usr/local/etc/smb.confx_smbdpid=/usr/local/var/locks/smbd-smb.conf.pidexport LIBPATH="$x_libpath"export PATH=/usr/bin:/usr/sbin:$x_smbpathx_action="$1"x_user=$(logname)## Functionslog_result(){ logger -t samba action: "$x_action" user: "$x_user": "$x_result"}log_restart(){ logger -t samba action: restart \(stop/start\) user: "$x_user": see the following lines}rc_start(){ smbd -D -s "$x_smbconf" -d 1 \ && echo "\nSamba was started successfully\n" \ || echo "\nERROR: failed to start Samba\n"}rc_stop(){ kill -TERM $(<"$x_smbdpid") 2> /dev/null \ && echo "\nSamba was stopped successfully\n" \ || echo "\nERROR: Samba stop failed (is it running?)\n"}rc_status(){ smbcontrol -s "$x_smbconf" $(<"$x_smbdpid") ping > /dev/null \ && echo "\nSamba is running\n" \ || echo "\nSamba is NOT running\n"}rc_reload(){ kill -HUP $(<"$x_smbdpid") 2> /dev/null \ && echo "\nSamba was reloaded successfully\n" && x_result=success \ || echo "\nERROR: Samba reload failed (is it running?)\n" && x_result=failure logger -t samba action: "$x_action" user: "$x_user": "$x_result"}## Maincase "$x_action" in checkconf) testparm -s -f "$x_smbconf" ;; status) rc_status ;; start) rc_start log_result ;; stop) rc_stop log_result ;; restart) log_restart rc_stop log_result rc_start log_result ;; reload) rc_reload ;; *) echo "\nUsage: "$0" checkconf|status|start|stop|restart|reload\n"esac...
This is a simple initial version; scroll down for a newer, better one.
#!/usr/bin/ksh## Samba control script# (c) LGee## Variables specific to the Samba installationx_libpath=/usr/local/libx_smbpath="/usr/local/bin:/usr/local/sbin"x_smbconf=/usr/local/etc/smb.confx_smbdpid=/usr/local/var/locks/smbd-smb.conf.pidexport LIBPATH="$x_libpath"export PATH=/usr/bin:/usr/sbin:$x_smbpath#x_user=$(who -m | read username junk; echo $username || echo UNKNOWN)x_user=$(logname)case "$1" in checkconf) testparm -s -f "$x_smbconf" ;; status) # smbstatus -s "$x_smbconf" smbcontrol -s "$x_smbconf" $(<"$x_smbdpid") ping > /dev/null \ && echo "\nSamba is running\n" \ || echo "\nSamba is NOT running\n" ;; start) smbd -D -s "$x_smbconf" -d 1 \ && ( echo "\nSamba was started successfully\n" ; x_result=success ) \ || ( echo "\nERROR: failed to start Samba\n" ; x_result=failure ) logger -t samba Samba start attempt through user "$x_user": "$x_result" ;; reload) kill -HUP $(<"$x_smbdpid") 2> /dev/null \ && ( echo "\nSamba was reloaded successfully\n" ; x_result=success ) \ || ( echo "\nERROR: Samba reload failed (is it running?)\n" ; x_result=failure ) logger -t samba Samba reload attempt through user "$x_user": "$x_result" ;; *) echo "\nUsage: "$0" checkconf|status|start|stop|reload\n"esac