]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # chkconfig: 345 91 35 | |
4 | # description: Starts and stops the Samba smbd and nmbd daemons \ | |
5 | # used to provide SMB network services. | |
6 | # | |
7 | # config: /etc/samba/smb.conf | |
8 | # config: /etc/samba/lmhosts | |
9 | # processname: nmbd | |
10 | # processname: smbd | |
11 | ||
12 | # Source function library. | |
13 | . /etc/rc.d/init.d/functions | |
14 | ||
15 | # Source networking configuration. | |
16 | . /etc/sysconfig/network | |
17 | ||
18 | # Set default config | |
19 | CFGFILE="/etc/samba/smb.conf" | |
20 | smbd_pidfile="/var/run/smbd.pid" | |
21 | nmbd_pidfile="/var/run/nmbd.pid" | |
22 | lockname=smb | |
23 | ||
24 | # Demon specified configuration. | |
25 | . /etc/sysconfig/samba | |
26 | ||
27 | # Check that networking is up. | |
28 | if is_yes "${NETWORKING}"; then | |
29 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
30 | msg_network_down "Samba SMB/CIFS Server" | |
31 | exit 1 | |
32 | fi | |
33 | else | |
34 | exit 0 | |
35 | fi | |
36 | ||
37 | TMPDIR="/tmp"; export TMPDIR | |
38 | unset TMP || : | |
39 | ||
40 | SERVER_ROLE=`samba-tool testparm --parameter-name="server role" 2>/dev/null | tail -1` | |
41 | if [ "$SERVER_ROLE" = "active directory domain controller" ]; then | |
42 | exit 0 | |
43 | fi | |
44 | ||
45 | start() { | |
46 | # Check if the service is already running? | |
47 | if [ -f /var/lock/subsys/$lockname ]; then | |
48 | msg_already_running "Samba SMB/CIFS Server" | |
49 | return | |
50 | fi | |
51 | ||
52 | msg_starting "Samba SMB/CIFS Server" | |
53 | daemon /usr/sbin/smbd -D -s $CFGFILE | |
54 | RETVAL=$? | |
55 | NMBD_DISABLED=`testparm -s --parameter-name='disable netbios' 2>/dev/null` | |
56 | if [ "$NMBD_DISABLED" != Yes ]; then | |
57 | msg_starting "Samba NetBIOS Name Server" | |
58 | daemon /usr/sbin/nmbd -D $CFGFILE | |
59 | [ $RETVAL -eq 0 ] && RETVAL=$? | |
60 | fi | |
61 | if [ $RETVAL -eq 0 ]; then | |
62 | touch /var/lock/subsys/$lockname | |
63 | fi | |
64 | } | |
65 | ||
66 | stop() { | |
67 | # Stop daemons. | |
68 | if [ ! -f /var/lock/subsys/$lockname ]; then | |
69 | msg_not_running "Samba SMB/CIFS Server" | |
70 | return | |
71 | fi | |
72 | ||
73 | msg_stopping "Samba SMB/CIFS Server" | |
74 | killproc --pidfile $smbd_pidfile smbd | |
75 | ||
76 | msg_stopping "Samba NetBIOS Name Server" | |
77 | killproc --pidfile $nmbd_pidfile nmbd | |
78 | rm -f /var/lock/subsys/$lockname >/dev/null 2>&1 | |
79 | } | |
80 | ||
81 | reload() { | |
82 | if [ ! -f /var/lock/subsys/$lockname ]; then | |
83 | msg_not_running "Samba SMB/CIFS Server" | |
84 | RETVAL=7 | |
85 | return | |
86 | fi | |
87 | ||
88 | msg_reloading "Samba SMB/CIFS Server" | |
89 | killproc --pidfile $smbd_pidfile smbd -HUP | |
90 | RETVAL=$? | |
91 | } | |
92 | ||
93 | condrestart() { | |
94 | if [ ! -f /var/lock/subsys/$lockname ]; then | |
95 | msg_not_running "Samba SMB/CIFS Server" | |
96 | RETVAL=$1 | |
97 | return | |
98 | fi | |
99 | ||
100 | stop | |
101 | start | |
102 | } | |
103 | ||
104 | rc_status() { | |
105 | status smbd | |
106 | RETVAL=$? | |
107 | status nmbd | |
108 | RET=$? | |
109 | [ $RETVAL -eq 0 ] && RETVAL=$RET | |
110 | } | |
111 | ||
112 | RETVAL=0 | |
113 | # See how we were called. | |
114 | case "$1" in | |
115 | start) | |
116 | start | |
117 | ;; | |
118 | stop) | |
119 | stop | |
120 | ;; | |
121 | restart) | |
122 | stop | |
123 | start | |
124 | ;; | |
125 | try-restart) | |
126 | condrestart 0 | |
127 | ;; | |
128 | reload|force-reload) | |
129 | reload | |
130 | ;; | |
131 | status) | |
132 | rc_status | |
133 | ;; | |
134 | *) | |
135 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}" | |
136 | exit 3 | |
137 | esac | |
138 | ||
139 | exit $RETVAL |