Managing the Samba AD DC Service Using an Init Script

From SambaWiki

This is a topic which pops every so often -- where are the Init scripts for Samba4? The problem is that init scripts are very distribution specific. The HOWTO states, "Samba4 alpha13 doesn't yet have init scripts included for each platform, but making one for your platform should not be difficult." Well, they may not be rocket science, but not everyone knows how to build a robust startup script and then integrate it with their particular startup infrastructure. This gets even more weird when distributions like Fedora radically overhaul their approach to init. (SysV to "systemd")

The intent of this page is to provide a sample of at least a few init scripts, listed by their distribution family (eg., Debian based systems and Red Hat/Fedora).

Red Hat/Fedora based systems

For SysV style service init scripts, Red Hat puts the init scripts in the /etc/rc.d/init.d directory, and then links to these scripts from the various run level directories (eg, link in /etc/rc3.d/S80samba4 -> ../rc.d/init.d/samba4)

Fedora has gone to a systemd based startup for Init. You can still use SysV style scripts such as this one, and configure the automatic startup of the Samba4 server ad different run levels through the "chkconfig" tool.

 #! /bin/bash
 # samba4       Bring up/down samba4 service 
 # chkconfig: - 90 10
 # description: Activates/Deactivates all samba4 interfaces configured to \
 #              start at boot time.
 # Provides: 
 # Should-Start: 
 # Short-Description: Bring up/down samba4
 # Description: Bring up/down samba4
 # Source function library.
 . /etc/init.d/functions
 if [ -f /etc/sysconfig/samba4 ]; then
 	. /etc/sysconfig/samba4
 start() {
       # Attach irda device 
       echo -n $"Starting $prog: "
 	sleep 2
 	if ps ax | grep -v "grep" | grep -q /samba/sbin/samba ; then success $"samba4 startup"; else failure $"samba4 startup"; fi
 stop() {
       # Stop service.
       echo -n $"Shutting down $prog: "
 	killall samba
 	sleep 2
 	if ps ax | grep -v "grep" | grep -q /samba/sbin/samba ; then failure $"samba4 shutdown"; else success $"samba4 shutdown"; fi
 status() {
 	/usr/local/samba/sbin/samba --show-build
 # See how we were called.
 case "$1" in
 	status irattach
       echo $"Usage: $0 {start|stop|restart|status}"
       exit 1
 exit 0

Debian Systems

1) Retrieve the init script

To retrieve the Debian init script, run either:

  $ bzr cat > /etc/init.d/samba4

Or if you don't have bzr:

  $ wget -O /etc/init.d/samba4

2) (Optional) Update the path where Samba is installed

The Debian package assumes that Samba is installed in /usr. If you've installed it in the default location (/usr/local/samba) instead, run:

  $ sed -i 's|/usr/sbin|/usr/local/samba/sbin|g' /etc/init.d/samba4

3) Make the init script executable

Make the init script executable by running:

  $ chmod 755 /etc/init.d/samba4

4) Enable the script at startup

  $ update-rc.d samba4 defaults

Upstart Systems (such as Ubuntu)

Ubuntu uses the upstart system. To retrieve the upstart config file, run:

  $ bzr cat > /etc/init/samba4.conf