2.8 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:

  • Manually

  • Automatically, during system boot

  • From inetd or xinetd

2.8.1 Starting the Daemons Manually

If you're in a hurry, you can start the Samba daemons by hand. As root, simply enter the following commands:

 #  /usr/local/samba/bin/smbd -D  #  /usr/local/samba/bin/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 will need to be restarted manually.

2.8.2 Automatic Startup

To have the Samba daemons started automatically when the system boots, you need to 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.

2.8.2.1 BSD Unix

With a BSD-style Unix, you need to 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 if the smbd file exists and has execute permissions, and if it does, it starts up both of the Samba daemons on system boot.

2.8.2.2 System V Unix

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 something similar to the following shell script, which for this example we will name smb :

 #!/bin/sh # Check that the Samba configuration file exists [ -f /usr/local/samba/lib/smb.conf ]  exit 0 start(  ) {         echo -n "Starting SMB services: "         /usr/local/samba/bin/smbd -D         ERROR=$?         echo         echo -n "Starting NMB services: "         /usr/local/samba/bin/nmbd -D         ERROR2=$?         if [ $ERROR2 -ne 0 ]         then                 ERROR=1         fi         echo         return $ERROR } stop(  ) {         echo -n "Shutting down SMB services: "         /bin/kill -TERM -a smbd         ERROR=$?         echo         echo -n "Shutting down NMB services: "         /bin/kill -TERM -a nmbd         ERROR2=$?         if [ $ERROR2 -ne 0 ]         then                 ERROR=1         fi         echo         return $ERROR } case "" in   start)         start         ;;   stop)         stop         ;;   *)         echo "Usage: 
 #!/bin/sh # Check that the Samba configuration file exists [ -f /usr/local/samba/lib/smb.conf ]  exit 0 start( ) { echo -n "Starting SMB services: " /usr/local/samba/bin/smbd -D ERROR=$? echo echo -n "Starting NMB services: " /usr/local/samba/bin/nmbd -D ERROR2=$? if [ $ERROR2 -ne 0 ] then ERROR=1 fi echo return $ERROR } stop( ) { echo -n "Shutting down SMB services: " /bin/kill -TERM -a smbd ERROR=$? echo echo -n "Shutting down NMB services: " /bin/kill - TERM -a nmbd ERROR2=$? if [ $ERROR2 -ne 0 ] then ERROR=1 fi echo return $ERROR } case "$1" in start) start ;; stop) stop ;; *) echo "Usage: $0 {startstop}" exit 1 esac exit $? 
{startstop}" exit 1 esac exit $?

With this script, you can 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 /usr/local/samba/bin/smbd -D  1270 ?        S      0:00 /usr/local/samba/bin/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 writing a startup script for your system, check to see if 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. Another possibility is to check the packaging directory in the Samba source distribution. In that directory, there are subdirectories for many Unix versions in which you can find a startup script for those versions. Even if your version isn't included, you can probably find a startup script for a similar version to use as a starting point.

Finally, we need to add symbolic links to the smb script in the /etc/rc.d/rcX.d directories:

 #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc3.d/S35smb  #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc5.d/S35smb  #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc0.d/K35smb  #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc1.d/K35smb  #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc2.d/K35smb  #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc4.d/K35smb  #  ln -s /etc/rc.d/init.d/smb /etc/rc.d/rc6.d/K35smb  

The first two commands, with link names starting with an "S", cause Samba to be started when entering runlevels 3 or 5, which are the runlevels in which network file sharing (NFS) is normally enabled. The second group of commands, with link names starting with a "K", cause 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 when starting Samba that all services 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 log files, but the order is not as crucial.

2.8.2.3 Darwin and Mac OS X

An installation of Samba is bundled with the Darwin distribution, which is included in Mac OS X. [5]

[5] In this book, we cover Darwin Version 6.0 and OS X Version 10.2.

The Samba daemons are started during system boot by the script /System/Library/StartupItems/Samba/Samba . To trigger the execution of this script, edit the file /etc/hostconfig and change the SMBSERVER parameter to look like this:

 SMBSERVER=-YES- 

On Mac OS X, the graphical user interface (GUI) provides an alternative to using the command line. Launch the System Preferences application, and select Sharing (see Figure 2-4). Under the Services tab, turn on Windows File Sharing. This will make the aforementioned change to /etc/hostconfig and immediately execute the startup item.

Figure 2-4. Mac OS X sharing preferences
figs/sam2_0204.gif

If you decide to install Samba yourself on Mac OS X, it's best not to stomp on the installation provided with the OS. Use the procedures detailed earlier in this chapter to install the software into /usr/local/samba or some other area unaffected by OS upgrades. (Remember to set up users with smbpasswd if you're using encrypted passwords, as described earlier in this chapter. This step is handled automatically with entries in /var/db/samba/hash if you're using the built-in server on Mac OS X.) Once you've got that working, you can edit the Samba startup item script to refer to your installation, like this:

 #!/bin/sh     # Start Samba     . /etc/rc.common     if [ "${SMBSERVER:=-NO-}" = "-YES-" ]; then         ConsoleMessage "Starting SMB server"         if [ -f /usr/local/samba/lib/smb.conf ]; then             /usr/local/samba/bin/smbd -D             /usr/local/samba/bin/nmbd -D         fi     fi 

However, beware of OS updates, which can wipe out your changes. One solution is to make the script immutable, like this:

 #  chflags uchg /System/Library/StartupItems/Samba/Samba  
2.8.2.4 Testing automatic startup

If you can afford a few minutes of downtime, reboot your system and again use the ps command to check that the smbd and nmbd daemons are running. And if you are managing a 24/7 server, we highly recommend that you find some downtime in which to reboot and perform this check. Otherwise, your next unscheduled downtime might surprise you with a mysterious absence of SMB networking services when the system comes up again!

2.8.3 Starting from inetd

The inetd [6] daemon is a Unix system's Internet "super daemon." It listens on ports defined in /etc/services and executes the appropriate program for each port, which is defined in /etc/inetd.conf . The advantage of this scheme is that you can have a large number of daemons ready to answer queries, but they don't all have to be running all the time. Instead, inetd listens for connection requests and starts the appropriate daemon when it is needed. The penalty is a small overhead cost of creating a new daemon process, as well as the fact that you need to edit two files rather than one to set things up. The inetd daemon is handy if you have only one or two Samba users or your machine is running too many daemons already. It's also easier to perform an upgrade without disturbing an existing connection.

[6] With early releases of Samba 2.2, there were reports of intermittent errors when starting from inetd . We provide this information so that it will be available for later releases when the problem will hopefully have been identified and corrected.

If you wish to start from inetd , first open /etc/services in your text editor. If you don't already have them defined, add the following two lines:

 netbios-ssn     139/tcp netbios-ns      137/udp 

Next, edit /etc/inetd.conf . Look for the following two lines and add them if they don't exist. If you already have smbd and nmbd lines in the file, edit them to point at the new smbd and nmbd you've installed. Your brand of Unix might use a slightly different syntax in this file; use the existing entries and the inetd.conf manual page as a guide:

 netbios-ssn stream tcp nowait root /usr/local/samba/bin/smbd smbd  netbios-ns  dgram  udp wait   root /usr/local/samba/bin/nmbd nmbd 

Finally, kill any smbd or nmbd processes and send the inetd process a hangup (HUP) signal to tell it to reread its configuration file:

 #  /bin/kill -TERM -a smbd  #  /bin/kill -TERM -a nmbd  #  /bin/kill -HUP -a inetd  

After that, Samba should be up and running.

As we've pointed out before, Red Hat and perhaps other Unix vendors supply xinetd rather than inetd . If you need to use xinetd , you will need to supply a configuration file in the /etc/xinetd.d directory.

   


Using Samba
Using Samba: A File and Print Server for Linux, Unix & Mac OS X, 3rd Edition
ISBN: 0596007698
EAN: 2147483647
Year: 2003
Pages: 475

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net