1#!/bin/sh
2#
3# chkconfig: 35 91 9
4# description: Starts and stops the Samba smbd and nmbd daemons \
5#	       used to provide SMB network services.
6
7# Source function library.
8if [ -f /etc/init.d/functions ] ; then
9  . /etc/init.d/functions
10elif [ -f /etc/rc.d/init.d/functions ] ; then
11  . /etc/rc.d/init.d/functions
12else
13  exit 0
14fi
15
16# Source networking configuration.
17. /etc/sysconfig/network
18
19# Check that networking is up.
20[ ${NETWORKING} = "no" ] && exit 0
21
22# Check that smb.conf exists.
23[ -f /etc/samba/smb.conf ] || exit 0
24
25RETVAL=0
26
27
28start() {
29       # If CUPS is used as printing system, reload smb after a 1 minute delay
30       # to allow the printers to appear properly as samba shares.
31        if killall -0 cupsd 2>/dev/null; then
32         ( sleep 60 && killproc smbd -HUP 1>/dev/null) &
33       fi
34       export TMPDIR="/var/tmp"
35	echo -n "Starting SMB services: "
36	daemon smbd -D 	
37	RETVAL=$?
38	echo
39	echo -n "Starting NMB services: "
40	daemon nmbd -D 
41	RETVAL2=$?
42	echo
43	[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/smb || \
44	   RETVAL=1
45	return $RETVAL
46}	
47stop() {
48	echo -n "Shutting down SMB services: "
49	killproc smbd
50	RETVAL=$?
51	echo
52	echo -n "Shutting down NMB services: "
53	killproc nmbd
54	RETVAL2=$?
55	[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/smb
56	echo ""
57	return $RETVAL
58}	
59restart() {
60	stop
61	start
62}	
63reload() {
64       export TMPDIR="/var/tmp"
65        echo -n "Reloading smb.conf file: "
66	killproc smbd -HUP
67	RETVAL=$?
68	echo
69	return $RETVAL
70}	
71mdkstatus() {
72	status smbd
73	status nmbd
74}	
75
76case "$1" in
77  start)
78  	start
79	;;
80  stop)
81  	stop
82	;;
83  restart)
84  	restart
85	;;
86  reload)
87  	reload
88	;;
89  status)
90  	mdkstatus
91	;;
92  condrestart)
93  	[ -f /var/lock/subsys/smb ] && restart || :
94	;;
95  *)
96	echo "Usage: $0 {start|stop|restart|status|condrestart}"
97	exit 1
98esac
99
100exit $?
101