Initial import
[samba] / debian / samba.init
1 #!/bin/sh
2 #
3 # Start/stops the Samba daemons (nmbd and smbd).
4 #
5 #
6
7 # Defaults
8 RUN_MODE="daemons"
9
10 # Reads config file (will override defaults above)
11 [ -r /etc/default/samba ] && . /etc/default/samba
12
13 PIDDIR=/var/run/samba
14 NMBDPID=$PIDDIR/nmbd.pid
15 SMBDPID=$PIDDIR/smbd.pid
16
17 # clear conflicting settings from the environment
18 unset TMPDIR
19
20 # See if the daemons are there
21 test -x /usr/sbin/nmbd -a -x /usr/sbin/smbd || exit 0
22
23 case "$1" in
24         start)
25                 echo -n "Starting Samba daemons..."
26
27                 # Make sure we have our PIDDIR, even if it's on a tmpfs
28                 mkdir -p $PIDDIR
29                 chown root:root $PIDDIR
30                 chmod 755 $PIDDIR
31
32                 if ! start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/nmbd -- -D; then
33                         echo "FAILED."
34                         exit 1
35                 fi
36
37                 if [ "$RUN_MODE" != "inetd" ]; then
38                         #log_progress_msg "smbd"
39                         if ! start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/smbd -- -D; then
40                                 echo "FAILED."
41                                 exit 1
42                         fi
43                 fi
44
45                 echo "done."
46                 ;;
47         stop)
48                 echo -n "Stopping Samba daemons..."
49
50                 start-stop-daemon --stop --quiet --pidfile $NMBDPID
51                 # Wait a little and remove stale PID file
52                 sleep 1
53                 if [ -f $NMBDPID ] && ! ps h `cat $NMBDPID` > /dev/null
54                 then
55                         # Stale PID file (nmbd was succesfully stopped),
56                         # remove it (should be removed by nmbd itself IMHO.)
57                         rm -f $NMBDPID
58                 fi
59
60                 if [ "$RUN_MODE" != "inetd" ]; then
61                         #log_progress_msg "smbd"
62                         start-stop-daemon --stop --quiet --pidfile $SMBDPID
63                         # Wait a little and remove stale PID file
64                         sleep 1
65                         if [ -f $SMBDPID ] && ! ps h `cat $SMBDPID` > /dev/null
66                         then
67                                 # Stale PID file (nmbd was succesfully stopped),
68                                 # remove it (should be removed by smbd itself IMHO.)
69                                 rm -f $SMBDPID
70                         fi
71                 fi
72
73                 echo "done."
74
75                 ;;
76         reload)
77                 echo -n "Reloading /etc/samba/smb.conf..."
78
79                 start-stop-daemon --stop --signal HUP --pidfile $SMBDPID
80
81                 echo "done."
82                 ;;
83         restart|force-reload)
84                 $0 stop
85                 sleep 1
86                 $0 start
87                 ;;
88         *)
89                 echo "Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload}"
90                 exit 1
91                 ;;
92 esac
93
94 exit 0