Managing the Samba AD DC Service Using an Init Script: Difference between revisions
(removing ubuntu - you'd really want to use an upstart script there) |
(Refer to Debian package init scripts, add info for Ubuntu) |
||
Line 75: | Line 75: | ||
== Debian |
== Debian Systems == |
||
To retrieve the Debian init script, run either: |
|||
#!/bin/sh |
|||
$ bzr cat http://bzr.debian.org/bzr/pkg-samba/samba4/unstable/debian/samba4.init > /etc/init.d/samba4 |
|||
### BEGIN INIT INFO |
|||
# Provides: samba |
|||
Or if you don't have bzr: |
|||
# Required-Start: $network $local_fs $remote_fs |
|||
# Required-Stop: $network $local_fs $remote_fs |
|||
$ wget http://anonscm.debian.org/loggerhead/pkg-samba/samba4/unstable/download/head:/1833%40fc4039ab-9d04-0410-8cac-899223bdd6b0:trunk%252Fsamba4:debian%252Fsamba4.init/samba4.init -O /etc/init.d/samba4 |
|||
# Default-Start: 2 3 4 5 |
|||
# Default-Stop: 0 1 6 |
|||
The Debian package assumes that Samba is installed in /usr. If you've installed it in the default location (/usr/local/samba) instead, run: |
|||
# Should-Start: slapd |
|||
# Should-Stop: slapd |
|||
$ sed -i 's|/usr/sbin|/usr/local/samba/sbin|g' /etc/init.d/samba4 |
|||
# Short-Description: start Samba daemon (samba) |
|||
### END INIT INFO |
|||
== Upstart Systems (such as Ubuntu) == |
|||
PIDDIR=/usr/local/samba/var/run |
|||
Ubuntu uses the upstart system. To retrieve the upstart config file, run: |
|||
SAMBADPID=$PIDDIR/samba.pid |
|||
$ bzr cat http://bzr.debian.org/bzr/pkg-samba/samba4/unstable/debian/samba4.upstart > /etc/init/samba4.conf |
|||
# clear conflicting settings from the environment |
|||
unset TMPDIR |
|||
# See if the daemons are there |
|||
test -x /usr/local/samba/sbin/samba || exit 0 |
|||
# Starting init-fuctions for Debian -shell script |
|||
. /lib/lsb/init-functions |
|||
case "$1" in |
|||
start) |
|||
log_daemon_msg "Starting Samba daemon" |
|||
# Make sure we have our PIDDIR, even if it's on a tmpfs |
|||
install -o root -g root -m 755 -d $PIDDIR |
|||
SAMBA_DISABLED=`testparm -s --parameter-name='disable netbios' 2>/dev/null` |
|||
if [ "$SAMBA_DISABLED" != 'Yes' ]; then |
|||
log_progress_msg "samba" |
|||
if ! start-stop-daemon --start --quiet --oknodo --exec /usr/local/samba/sbin/samba -- -D |
|||
then |
|||
log_end_msg 1 |
|||
exit 1 |
|||
fi |
|||
fi |
|||
log_end_msg 0 |
|||
;; |
|||
stop) |
|||
log_daemon_msg "Stopping Samba daemon" |
|||
log_progress_msg "samba" |
|||
start-stop-daemon --stop --quiet --pidfile $SAMBADPID |
|||
# Wait a little and remove stale PID file |
|||
sleep 1 |
|||
if [ -f $SAMBADPID ] && ! ps h `cat $SAMBADPID` > /dev/null |
|||
then |
|||
# Stale PID file (samba was succesfully stopped), |
|||
# remove it (should be removed by samba itself IMHO.) |
|||
rm -f $SAMBADPID |
|||
fi |
|||
log_end_msg 0 |
|||
;; |
|||
reload) |
|||
log_daemon_msg "Reloading /usr/local/samba/etc/smb.conf " |
|||
start-stop-daemon --stop --signal HUP --pidfile $SAMBADPID |
|||
log_end_msg 0 |
|||
;; |
|||
restart|force-reload) |
|||
$0 stop |
|||
sleep 1 |
|||
$0 start |
|||
;; |
|||
*) |
|||
echo "Usage: /etc/init.d/samba4 {start|stop|reload|restart|force-reload}" |
|||
exit 1 |
|||
;; |
|||
esac |
|||
exit 0 |
Revision as of 19:35, 3 September 2012
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. # ### BEGIN INIT INFO # Provides: # Should-Start: # Short-Description: Bring up/down samba4 # Description: Bring up/down samba4 ### END INIT INFO # Source function library. . /etc/init.d/functions if [ -f /etc/sysconfig/samba4 ]; then . /etc/sysconfig/samba4 fi CWD=$(pwd) prog="samba4" start() { # Attach irda device echo -n $"Starting $prog: " /usr/local/samba/sbin/samba sleep 2 if ps ax | grep -v "grep" | grep -q /samba/sbin/samba ; then success $"samba4 startup"; else failure $"samba4 startup"; fi echo } 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 echo } status() { /usr/local/samba/sbin/samba --show-build } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status irattach ;; restart|reload) stop start ;; *) echo $"Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0
Debian Systems
To retrieve the Debian init script, run either:
$ bzr cat http://bzr.debian.org/bzr/pkg-samba/samba4/unstable/debian/samba4.init > /etc/init.d/samba4
Or if you don't have bzr:
$ wget http://anonscm.debian.org/loggerhead/pkg-samba/samba4/unstable/download/head:/1833%40fc4039ab-9d04-0410-8cac-899223bdd6b0:trunk%252Fsamba4:debian%252Fsamba4.init/samba4.init -O /etc/init.d/samba4
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
Upstart Systems (such as Ubuntu)
Ubuntu uses the upstart system. To retrieve the upstart config file, run:
$ bzr cat http://bzr.debian.org/bzr/pkg-samba/samba4/unstable/debian/samba4.upstart > /etc/init/samba4.conf