Managing the Samba AD DC Service Using an Init Script: Difference between revisions
Mmuehlfeld (talk | contribs) (Removed Upstart related content (moved to a page about Upstart), removed init script for a domain member (not required on this page. It will get it's own page later).) |
Mmuehlfeld (talk | contribs) (Rewrote page. Removed unneccessary and outdated content, moved content that is not about init scripts to separate pages, Restructured page, added information about using alternative ways to start a service, such as systemd.) |
||
Line 1: | Line 1: | ||
= Introduction = |
|||
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 following describes how to use an init script to manage the Samba Active Directory (AD) domain controller (DC) service. Depending on your operating system, the location of the init script, its content, and the procedures how to manage the service can be different. For details, see your operating system's documentation. |
|||
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). |
|||
{{Imbox |
|||
== Red Hat/Fedora based systems == |
|||
| type = important |
|||
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) |
|||
| text = If you operating system uses a different system to manage services, such as <code>systemd</code>, see [[Managing_the_Samba_AD_DC_Service|Managing the Samba AD DC Service]]. |
|||
}} |
|||
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 and different run levels through the "chkconfig" tool. |
|||
= Creating the Init Script = |
|||
== Red Hat Enterprise Linux 6 == |
|||
{{Imbox |
|||
| type = note |
|||
| text = On Red Hat Enterprise Linux later than version 6, use <code>systemd</code> to manage the Samba service. For details, see [[Managing_the_Samba_AD_DC_Service_Using_Systemd|Managing the Samba AD DC Service Using Systemd]]. |
|||
}} |
|||
* Create the <code>/etc/init.d/samba-ad-dc</code> file with the following content: |
|||
#!/bin/bash |
#!/bin/bash |
||
# |
# |
||
# |
# samba-ad-dc This shell script takes care of starting and stopping |
||
# |
# samba AD daemons. |
||
# |
# |
||
# chkconfig: - 58 74 |
# chkconfig: - 58 74 |
||
# description: Samba |
# description: Samba Active Directory Domain Controller |
||
# and incorporates all the technology found in both the Samba4 alpha |
|||
# series and the stable 3.x series. The primary additional features |
|||
# over Samba 3.6 are support for the Active Directory logon protocols |
|||
# used by Windows 2000 and above. |
|||
### BEGIN INIT INFO |
### BEGIN INIT INFO |
||
# Provides: |
# Provides: samba-ad-dc |
||
# Required-Start: $network $local_fs $remote_fs |
# Required-Start: $network $local_fs $remote_fs |
||
# Required-Stop: $network $local_fs $remote_fs |
# Required-Stop: $network $local_fs $remote_fs |
||
# Should-Start: $syslog $named |
# Should-Start: $syslog $named |
||
# Should-Stop: $syslog $named |
# Should-Stop: $syslog $named |
||
# Short-Description: start and stop |
# Short-Description: start and stop samba-ad-dc |
||
# Description: Samba |
# Description: Samba Active Directory Domain Controller |
||
# and incorporates all the technology found in both the Samba4 alpha |
|||
# series and the stable 3.x series. The primary additional features |
|||
# over Samba 3.6 are support for the Active Directory logon protocols |
|||
# used by Windows 2000 and above. |
|||
### END INIT INFO |
### END INIT INFO |
||
# Source function library. |
# Source function library. |
||
. /etc/init.d/functions |
. /etc/init.d/functions |
||
# Source networking configuration. |
# Source networking configuration. |
||
. /etc/sysconfig/network |
. /etc/sysconfig/network |
||
prog=samba |
prog=samba |
||
prog_dir=/usr/local/samba/sbin/ |
prog_dir=/usr/local/samba/sbin/ |
||
lockfile=/var/lock/subsys/$prog |
lockfile=/var/lock/subsys/$prog |
||
start() { |
start() { |
||
[ "$NETWORKING" = "no" ] && exit 1 |
|||
echo -n $"Starting Samba AD DC: " |
|||
# [ -x /usr/sbin/ntpd ] || exit 5 |
|||
daemon $prog_dir/$prog -D |
|||
RETVAL=$? |
|||
# Start daemons. |
|||
echo |
|||
echo -n $"Starting samba4: " |
|||
[ $RETVAL -eq 0 ] && touch $lockfile |
|||
daemon $prog_dir/$prog -D |
|||
return $RETVAL |
|||
echo |
|||
[ $RETVAL -eq 0 ] && touch $lockfile |
|||
return $RETVAL |
|||
} |
} |
||
stop() { |
|||
[ "$EUID" != "0" ] && exit 4 |
|||
stop() { |
|||
echo -n $"Shutting down Samba AD DC: " |
|||
[ "$EUID" != "0" ] && exit 4 |
|||
killproc $prog_dir/$prog |
|||
echo -n $"Shutting down samba4: " |
|||
RETVAL=$? |
|||
killproc $prog_dir/$prog |
|||
echo |
|||
RETVAL=$? |
|||
[ $RETVAL -eq 0 ] && rm -f $lockfile |
|||
return $RETVAL |
|||
[ $RETVAL -eq 0 ] && rm -f $lockfile |
|||
return $RETVAL |
|||
} |
} |
||
# See how we were called. |
|||
case "$1" in |
case "$1" in |
||
start) |
start) |
||
start |
|||
;; |
|||
stop) |
stop) |
||
stop |
|||
;; |
|||
status) |
status) |
||
status $prog |
|||
;; |
|||
restart) |
restart) |
||
stop |
|||
start |
|||
;; |
|||
reload) |
|||
echo "Not implemented yet." |
|||
exit 3 |
|||
;; |
|||
*) |
*) |
||
echo $"Usage: $0 {start|stop|status|restart}" |
|||
exit 2 |
|||
esac |
esac |
||
* Make the script executeable: |
|||
== Debian Systems == |
|||
# chmod 755 /etc/init.d/samba-ad-dc |
|||
== Debian == |
|||
* Download the following file: |
|||
# wget "<nowiki>http://anonscm.debian.org/gitweb/?p=pkg-samba/samba.git;a=blob_plain;f=debian/samba.samba-ad-dc.init;h=3132d2e367675f822342a5b7bc2e50c046aa3b8f;hb=HEAD</nowiki>" -O /etc/init.d/samba-ad-dc |
|||
* If necessary, update the locations to the <code>samba</code> service, the <code>samba-tool</code> utility, and the <code>smb.conf</code> file in the <code>/etc/init.d/samba-ad-dc</code> file. |
|||
* Make the script executeable: |
|||
# chmod 755 /etc/init.d/samba-ad-dc |
|||
= Managing the Samba AD DC Service == |
|||
1) Retrieve the init script |
|||
The following assumes that the Samba Active Directory (AD) domain controller (DC) service is managed by the <code>/etc/init.d/samba-ad-dc</code> init script. If you have not created the script manually, see your operating system's documentation for the name of the Samba AD DC service. |
|||
To retrieve the Debian init script, run: |
|||
{{Imbox |
|||
$ wget "http://anonscm.debian.org/gitweb/?p=pkg-samba/samba.git;a=blob_plain;f=debian/samba.samba-ad-dc.init;h=3132d2e367675f822342a5b7bc2e50c046aa3b8f;hb=HEAD" -O /etc/init.d/samba-ad-dc |
|||
| type = note |
|||
| text = Depending on your operating system, there can be different ways to enable or disable a service. See your operating system's documentation for details. |
|||
}} |
|||
2) (Optional) Update the paths 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: |
|||
== Enabling and Disabling the Samba AD DC Service == |
|||
$ sed -i 's|/usr/sbin|/usr/local/samba/sbin|g' /etc/init.d/samba-ad-dc |
|||
To enable the Samba Active Directory (AD) domain controller (DC) service to start automatically when the system boots, enter: |
|||
Likewise the Debian package assumes you'll use /etc/samba/smb.conf for the configuration file. If you're using the default location and build run: |
|||
# chkconfig samba-ad-dc enable |
|||
$ sed -i 's|/etc/samba|/usr/local/samba/etc|g' /etc/init.d/samba-ad-dc |
|||
To disable the automatic start of the Samba AD DC service, enter: |
|||
Again, the Debian package assumes you'll use /var/run/samba as pid directory. If you're using the default location, run: |
|||
# chkconfig samba-ad-dc disable |
|||
$ sed -i 's|/var/run/samba|/usr/local/samba/var/run|g' /etc/init.d/samba-ad-dc |
|||
Last, if you're using the default location for samba-tools, run : |
|||
$ sed -i 's|samba-tool|/usr/local/samba/bin/samba-tool|g' /etc/init.d/samba-ad-dc |
|||
== Manually Starting and Stopping the Samba AD DC Service == |
|||
3) Make the init script executable |
|||
To manually start the Samba Active Directory (AD) domain controller (DC) service, enter: |
|||
Make the init script executable by running: |
|||
# service start samba-ad-dc |
|||
To manually stop the Samba AD DC service, enter: |
|||
4) Enable the script at startup |
|||
# service stop samba-ad-dc |
Revision as of 14:41, 8 January 2017
Introduction
The following describes how to use an init script to manage the Samba Active Directory (AD) domain controller (DC) service. Depending on your operating system, the location of the init script, its content, and the procedures how to manage the service can be different. For details, see your operating system's documentation.
If you operating system uses a different system to manage services, such as systemd , see Managing the Samba AD DC Service. |
Creating the Init Script
Red Hat Enterprise Linux 6
On Red Hat Enterprise Linux later than version 6, use systemd to manage the Samba service. For details, see Managing the Samba AD DC Service Using Systemd. |
- Create the
/etc/init.d/samba-ad-dc
file with the following content:
#!/bin/bash # # samba-ad-dc This shell script takes care of starting and stopping # samba AD daemons. # # chkconfig: - 58 74 # description: Samba Active Directory Domain Controller ### BEGIN INIT INFO # Provides: samba-ad-dc # Required-Start: $network $local_fs $remote_fs # Required-Stop: $network $local_fs $remote_fs # Should-Start: $syslog $named # Should-Stop: $syslog $named # Short-Description: start and stop samba-ad-dc # Description: Samba Active Directory Domain Controller ### END INIT INFO # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network prog=samba prog_dir=/usr/local/samba/sbin/ lockfile=/var/lock/subsys/$prog start() { [ "$NETWORKING" = "no" ] && exit 1 echo -n $"Starting Samba AD DC: " daemon $prog_dir/$prog -D RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile return $RETVAL } stop() { [ "$EUID" != "0" ] && exit 4 echo -n $"Shutting down Samba AD DC: " killproc $prog_dir/$prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $lockfile return $RETVAL } case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 2 esac
- Make the script executeable:
# chmod 755 /etc/init.d/samba-ad-dc
Debian
- Download the following file:
# wget "http://anonscm.debian.org/gitweb/?p=pkg-samba/samba.git;a=blob_plain;f=debian/samba.samba-ad-dc.init;h=3132d2e367675f822342a5b7bc2e50c046aa3b8f;hb=HEAD" -O /etc/init.d/samba-ad-dc
- If necessary, update the locations to the
samba
service, thesamba-tool
utility, and thesmb.conf
file in the/etc/init.d/samba-ad-dc
file.
- Make the script executeable:
# chmod 755 /etc/init.d/samba-ad-dc
Managing the Samba AD DC Service =
The following assumes that the Samba Active Directory (AD) domain controller (DC) service is managed by the /etc/init.d/samba-ad-dc
init script. If you have not created the script manually, see your operating system's documentation for the name of the Samba AD DC service.
Depending on your operating system, there can be different ways to enable or disable a service. See your operating system's documentation for details. |
Enabling and Disabling the Samba AD DC Service
To enable the Samba Active Directory (AD) domain controller (DC) service to start automatically when the system boots, enter:
# chkconfig samba-ad-dc enable
To disable the automatic start of the Samba AD DC service, enter:
# chkconfig samba-ad-dc disable
Manually Starting and Stopping the Samba AD DC Service
To manually start the Samba Active Directory (AD) domain controller (DC) service, enter:
# service start samba-ad-dc
To manually stop the Samba AD DC service, enter:
# service stop samba-ad-dc