r11398: Keep s3 in sync with trunk
[samba.git] / packaging / Debian / debian-unstable / 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 NMBDPID=/var/run/samba/nmbd.pid
14 SMBDPID=/var/run/samba/smbd.pid
15
16 # clear conflicting settings from the environment
17 unset TMPDIR
18
19 # See if the daemons are there
20 test -x /usr/sbin/nmbd -a -x /usr/sbin/smbd || exit 0
21
22 . /lib/lsb/init-functions
23
24 case "$1" in
25         start)
26                 log_daemon_msg "Starting Samba daemons" "nmbd"
27
28                 if ! start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/nmbd -- -D; then
29                         log_end_msg 1
30                         exit 1
31                 fi
32
33                 if [ "$RUN_MODE" != "inetd" ]; then
34                         log_progress_msg "smbd"
35                         if ! start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/smbd -- -D; then
36                                 log_end_msg 1
37                                 exit 1
38                         fi
39                 fi
40
41                 log_end_msg 0
42                 ;;
43         stop)
44                 log_daemon_msg "Stopping Samba daemons" "nmbd"
45
46                 start-stop-daemon --stop --quiet --pidfile $NMBDPID
47                 # Wait a little and remove stale PID file
48                 sleep 1
49                 if [ -f $NMBDPID ] && ! ps h `cat $NMBDPID` > /dev/null
50                 then
51                         # Stale PID file (nmbd was succesfully stopped),
52                         # remove it (should be removed by nmbd itself IMHO.)
53                         rm -f $NMBDPID
54                 fi
55
56                 if [ "$RUN_MODE" != "inetd" ]; then
57                         log_progress_msg "smbd"
58                         start-stop-daemon --stop --quiet --pidfile $SMBDPID
59                         # Wait a little and remove stale PID file
60                         sleep 1
61                         if [ -f $SMBDPID ] && ! ps h `cat $SMBDPID` > /dev/null
62                         then
63                                 # Stale PID file (nmbd was succesfully stopped),
64                                 # remove it (should be removed by smbd itself IMHO.)
65                                 rm -f $SMBDPID
66                         fi
67                 fi
68
69                 log_end_msg 0
70
71                 ;;
72         reload)
73                 log_daemon_msg "Reloading /etc/samba/smb.conf" "smbd only"
74
75                 start-stop-daemon --stop --signal HUP --pidfile $SMBDPID
76
77                 log_end_msg 0
78                 ;;
79         restart|force-reload)
80                 $0 stop
81                 sleep 1
82                 $0 start
83                 ;;
84         *)
85                 echo "Usage: /etc/init.d/samba {start|stop|reload|restart|force-reload}"
86                 exit 1
87                 ;;
88 esac
89
90 exit 0