2.7. Starting the Samba Daemons
Two Samba processes, smbd and nmbd, need to be running for Samba to work correctly.[*] There are three ways to start them:
2.7.1. Starting the Daemons Manually
If you're in a hurry, you can start the Samba daemons by hand. As root, enter the following commands:
$ /usr/local/samba/sbin/smbd -D $ /usr/local/samba/sbin/nmbd -D
Samba will now be running on your system and is ready to accept connections. However, keep in mind that if either of the daemons exit for any reason (including system reboots), they must be restarted manually.
2.7.2. Automatic Startup
To have the Samba daemons started automatically when the system boots, add the commands listed in the previous section to your standard Unix startup scripts. The exact method varies depending on the flavor of Unix you're using.
184.108.40.206. BSD Unix
With a BSD-style Unix variant, append the following code to the rc.local file, which is typically found in the /etc or /etc/rc.d directories:
if [ -x /usr/local/samba/bin/smbd]; then echo "Starting smbd..." /usr/local/samba/bin/smbd -D echo "Starting nmbd..." /usr/local/samba/bin/nmbd -D fi
This code is very simple: it checks to see whether the smbd file exists and has execute permissions, and if so, starts up both of the Samba daemons.
220.127.116.11. System V Unix and most Linux distributions
With System V, things can get a little more complex. Depending on your Unix version, you might be able to get away with making a simple change to an rc.local file as with BSD Unix, but System V typically uses directories containing links to scripts that control daemons on the system. Hence, you need to instruct the system how to start and stop the Samba daemons. The first step to implement this is to modify the contents of the /etc/rc.d/init.d directory by adding an init script. The samba-3.0.x/packaging/sysv directory contains an example init script that should work on most System V based hosts. It is at least a place to begin making any local tweaks necessary for your system.
Assuming that we have installed this script using the name smb and set the execute permissions on it, we can now start and stop smbd and nmbd like this:
# /etc/rc.d/init.d/smb start Starting SMB services: Starting NMB services: # ps ax | grep mbd 1268 ? S 0:00 smbd -D 1269 ? S 0:00 smbd -D 1270 ? S 0:00 nmbd -D 1465 pts/2 S 0:00 grep mbd # /etc/rc.d/init.d/smb stop Shutting down SMB services: Shutting down NMB services:
If you are having trouble modifying the existing SysV init script or are unable to write your own, check to see whether there is a packaged release of Samba (available from your Unix vendor or the Samba FTP site). If so, you might be able to extract a startup script from it to use as a starting point. Typically, this script doesn't change much (if at all) from release to release, so using a script from an older Samba version should not be a problem.
Finally, we need to add symbolic links to the smb script in the /etc/rc.d/rcn.d directories:
# for i in 3 5; do > ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc$i.d/S35smb > done # for i in 0 1 2 4 6; do > ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc$i.d/K35smb > done
The first for loop, with a link name starting with an S (S35smb), causes Samba to be started when entering runlevels 3 or 5, which are the runlevels in which network file sharing (NFS) is normally enabled. The next for loop, with a link name starting with a K, causes Samba to be shut down when entering any of the other runlevels (0, 1, 2, 4, or 6).
The links starting with S are used to start the daemons, and the links starting with K are used for killing them. When the runlevel is changed, the links starting with K in the corresponding directory (e.g., the rc3.d directory for runlevel 3) are executed, followed by the links starting with S. If we wanted, we could have Samba restarted when switching between runlevels 3 and 5 by adding a K35smb link to each rc3.d and rc5.d directory.
The number after the K or S in the link names is used to set the order in which all the daemons with links in the directory are started or killed off. Get a long listing of the rc3.d or rc5.d directories to see how this is set up on your system. We use 35 to match the behavior of Red Hat's Samba RPM package. The important thing is to make sure that when starting Samba, all services that it requires are started before it. When shutting down, it is a good idea to shut down Samba before services it requires, to avoid excess error messages in the logfiles, but the shut down order is not as crucial.
18.104.22.168. Mac OS X
An installation of Samba is bundled with Mac OS X.[*] In true Apple style, all of the startup and shutdown details have been hidden beneath the System Preferences Sharing applet. Selecting the Services sheet displays a list of network services that are installed (although all may not be currently running). See Figure 2-4 for a screenshot of this window. Under the Services tab, turn on Windows File Sharing. In technical terms, enabling Windows File Sharing launches nmbd as a daemon and enables smbd to be run via the xinetd meta-server. The OS X included smb.conf file is located in the /etc directory.