LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Samba at startup (http://www.linuxquestions.org/questions/linux-newbie-8/samba-at-startup-148200/)

t3___ 02-19-2004 07:49 PM

Samba at startup
 
My objective is to get samba and nmbd to start automatically at boot time.

I ran a search on the forums here, and found a thread indicating that samba usually installs with a startup script that can be placed in /etc/init.d to make all smb related services active at startup.

After searching I found that I do indeed have a file called "smb" (no quotes though) in my /etc/init.d folder - I pasted the contents of the file below.

QUESTION - is this file the samba startup script that previous thread was refering to? And if so, why is samba and nmbd NOT starting at boot time.... Im guessing that I need to uncomment some lines in the script??? Which lines... or all? Please advise.

Any help would be greatly appreciated. Also, if anyone has a different approach to starting samba at boot, I would love to understand any alternatives as well.

~~~~~~~~~~~~~~~~~~~~
here is the file
~~~~~~~~~~~~~~~~~~~~

#! /bin/sh
# Copyright (c) 1999-2003 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Lars Mueller <lmuelle@suse.de>
#
# /etc/init.d/smb
# and its symbolic link
# /usr/sbin/rcsmb
#
### BEGIN INIT INFO
# Provides: smb
# Required-Start: $network $remote_fs syslog
# X-UnitedLinux-Should-Start: cupsd winbind nmb
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: Samba SMB/CIFS file and print server
### END INIT INFO

DAEMON_DIR="/usr/lib/samba/"
SMBD_BIN="smbd"
SMB_CONF="/etc/samba/smb.conf"
SYSCONFIG_FILE="/etc/sysconfig/samba"
PID_FILE="/var/run/samba/smbd.pid"
SAM_STATE_FILE="/var/run/samba/samsmbd.state"

# Status shell functions
. /etc/rc.status
# Reset status of this service
rc_reset

# Check for existence of needed config files.
for configfile in ${SMB_CONF} ${SYSCONFIG_FILE}; do
if [ ! -f ${configfile} ]; then
echo -n "Samba configuration file ${configfile} does not exist. "
# Tell the user this has skipped
rc_status -s
exit 6
fi
done

# Source Samba settings
. ${SYSCONFIG_FILE}

BIN_SUFFIX=$( echo ${SAMBA_SAM} | tr '[:upper:]' '[:lower:]')
# If a wrong or no BIN_SUFFIX is set, warn the user and set a default.
if [ x"${BIN_SUFFIX}" != x"classic" -a x"${BIN_SUFFIX}" != x"ldap" ]; then
echo "Unknown Samba Security Authentication Mechanism, ${SAMBA_SAM}."
echo "Please fix the sysconfig setting. Using default, classic for now."
BIN_SUFFIX="classic"
fi

# Get current sam if a state file exists.
test -f ${SAM_STATE_FILE} && \
curr_sam=$( cat ${SAM_STATE_FILE}) || \
curr_sam=${BIN_SUFFIX}

# Check for missing binary
if [ ! -x ${DAEMON_DIR}${BIN_SUFFIX}/${SMBD_BIN} ]; then
echo -n "Samba daemon, ${DAEMON_DIR}${BIN_SUFFIX}/${SMBD_BIN} is not installed. "
# Tell the user this has skipped
rc_status -s
exit 5
fi

# wait for cupsd to be ready
function wait_for_cupsd
{
echo -n "Samba SMB: Waiting for cupsd to get ready"
SAMBA_CUPSD_TIMEOUT=30
rc_timer_on ${SAMBA_CUPSD_TIMEOUT} 42
for ((i=0; i<${SAMBA_CUPSD_TIMEOUT}; i++)); do
if lpstat -r &>/dev/null; then continue
else sleep 1
fi
done
rc_timer_off

lpstat -r &>/dev/null && rc_status -v || rc_status -s
rc_reset
}

# check and create TDB
function check_create_tdb
{
test -f /var/lib/samba/$1.tdb || \
echo "create /var/lib/samba/$1.tdb" | /usr/lib/samba/tdbtool >/dev/null
}

# be extra carefull cause connection fail if TMPDIR is not writeable
export TMPDIR="/var/tmp"

case "$1" in
start)
if grep -qi '^[[:space:]]*printing[[:space:]]*=[[:space:]]*cups' ${SMB_CONF} && chkconfig --check cups; then
wait_for_cupsd
fi
if [ ${BIN_SUFFIX} != ${curr_sam} ]; then
echo -n "Samba ${curr_sam} SMB daemon might run; I will try to stop it first. "
killproc -p ${PID_FILE} ${DAEMON_DIR}${curr_sam}/${SMBD_BIN}
rc_status -v
fi
echo -n "Starting Samba ${BIN_SUFFIX} SMB daemon "
checkproc -p ${PID_FILE} ${DAEMON_DIR}${BIN_SUFFIX}/${SMBD_BIN} && \
echo -n " Warning: daemon already running. "
check_create_tdb brlock
check_create_tdb locking
startproc -p ${PID_FILE} ${DAEMON_DIR}${BIN_SUFFIX}/${SMBD_BIN} -D -s ${SMB_CONF}
rc_status -v
echo ${BIN_SUFFIX} >${SAM_STATE_FILE}
;;
stop)
echo -n "Shutting down Samba ${curr_sam} SMB daemon "
checkproc -p ${PID_FILE} ${DAEMON_DIR}${curr_sam}/${SMBD_BIN} || \
echo -n " Warning: daemon not running. "
killproc -p ${PID_FILE} ${DAEMON_DIR}${curr_sam}/${SMBD_BIN}
rc_status -v
rm -f ${SAM_STATE_FILE}
;;
try-restart)
$0 status >/dev/null && $0 restart
rc_status
;;
restart)
$0 stop
$0 start
rc_status
;;
force-reload)
$0 reload
rc_status
;;
reload)
echo -n "Reloading Samba ${curr_sam} SMB daemon "
checkproc -p ${PID_FILE} ${DAEMON_DIR}${curr_sam}/${SMBD_BIN} || \
echo -n " Warning: daemon not running. "
killproc -p ${PID_FILE} -HUP ${DAEMON_DIR}${curr_sam}/${SMBD_BIN}
rc_status -v
;;
status)
echo -n "Checking for Samba ${curr_sam} SMB daemon "
checkproc -p ${PID_FILE} ${DAEMON_DIR}${curr_sam}/${SMBD_BIN}
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
exit 1
;;
esac
rc_exit

wi77ard 02-19-2004 08:01 PM

If you are running redhat 9, i know how ............

goto start aplications (kde) / gnome menu

then system settings, then server settings

and choose services.

this will open a new window with loads of check boxes, scroll down until you find smb and make sure it has a tick in its box. once done save using the menu file -> save and then quit and reboot your system. This should automatically start smb.

hope this helps (hope you use Redhat lol)

t3___ 02-19-2004 08:15 PM

nope, as my signature indicated, im on Suse 9.0.

Furthermore I am particularly intersted in understand what is "under the hood" as opposed to a shortcup method.

thanks nonetheless....

levian 02-20-2004 02:10 AM

Hi,
In which run level you would like samba to run?
The smb script in /etc/init.d only defines on "how" the smb service would like to start, stop, or restart.
To start the smb service on particular run level simply make a symlink in /etc/rc?.d to the smb script in /etc/init.d. The symlink should begin with S (whereas K will stop the service) followed by two digits number that will provide a mechanism to select the priority in which the program will run.

For example if we would like smb to start at runlevel 5 :
#ln -s /etc/init.d/smb /etc/rc5.d/S91smb

Im still a beginner, though, so i may make a mistake also. cheers

TexasDex 02-20-2004 03:57 AM

Explanation of runlevels: At different runlevels your computer enables different services. You can customize it so that your computer runs the SMBD service only while in mode 3 (console) or you can add it to both 3 and 5 (the most commonly used runlevels)

Runlevel 0: Halt
Runlevel 1: Single user - no services
Runlevel 2: other (custom)
Runlevel 3: typically console mode
Runlevel 4: other (custom)
Runlevel 5: X11 (GUI) mode
Runlevel 6: Reboot

Levian's explanation on how to add a service to a runlevel looks right--i havn't done it in a while.

t3___ 02-20-2004 12:47 PM

Wow... thanks everyone for the replies....

Ok, so I understand that I must make a symlink (somewhere) in the /etc/rc.d/rc#.d folder... I want samba to run all the time (in gui and runlevel 3), so I must create 2 symlinks, right?

my other question now is how on earth would I chose a number for the "priority"? I havent a clue what priority I would like this to run at... is there a default value for this field.

Also... can someone verify the syntax on the command that levian noted for me?

THANKS EVERYONE!!!

Linner 05-22-2004 03:14 AM

levian syntax is right.

#ln -s /etc/init.d/smb /etc/rc[runlevel].d/S[priority]smb

with regards to priority, i have noticed that when you view the those init.d script file, there is entry for chkconfig. i think thats the priority numbers.

well, i havent tried it...newbie too. ;-) goodluck.


All times are GMT -5. The time now is 04:31 AM.