patch to include support for daemontools from Michael Handler
[samba.git] / source3 / web / startstop.c
1 /* 
2    Unix SMB/CIFS implementation.
3    start/stop nmbd and smbd
4    Copyright (C) Andrew Tridgell 1998
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "../web/swat_proto.h"
23 #include "dynconfig.h"
24
25 /** Need to wait for daemons to startup */
26 #define SLEEP_TIME 3
27
28 /** Startup smbd from web interface. */
29 void start_smbd(void)
30 {
31         pstring binfile;
32
33         if (geteuid() != 0) return;
34
35         if (fork()) {
36                 sleep(SLEEP_TIME);
37                 return;
38         }
39
40         slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR);
41
42         become_daemon(True);
43
44         execl(binfile, binfile, "-D", NULL);
45
46         exit(0);
47 }
48
49 /* startup nmbd */
50 void start_nmbd(void)
51 {
52         pstring binfile;
53
54         if (geteuid() != 0) return;
55
56         if (fork()) {
57                 sleep(SLEEP_TIME);
58                 return;
59         }
60
61         slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR);
62         
63         become_daemon(True);
64
65         execl(binfile, binfile, "-D", NULL);
66
67         exit(0);
68 }
69
70 /** Startup winbindd from web interface. */
71 void start_winbindd(void)
72 {
73         pstring binfile;
74
75         if (geteuid() != 0) return;
76
77         if (fork()) {
78                 sleep(SLEEP_TIME);
79                 return;
80         }
81
82         slprintf(binfile, sizeof(pstring) - 1, "%s/winbindd", dyn_SBINDIR);
83
84         become_daemon(True);
85
86         execl(binfile, binfile, NULL);
87
88         exit(0);
89 }
90
91
92 /* stop smbd */
93 void stop_smbd(void)
94 {
95         pid_t pid = pidfile_pid("smbd");
96
97         if (geteuid() != 0) return;
98
99         if (pid <= 0) return;
100
101         kill(pid, SIGTERM);
102 }
103
104 /* stop nmbd */
105 void stop_nmbd(void)
106 {
107         pid_t pid = pidfile_pid("nmbd");
108
109         if (geteuid() != 0) return;
110
111         if (pid <= 0) return;
112
113         kill(pid, SIGTERM);
114 }
115 #ifdef WITH_WINBIND
116 /* stop winbindd */
117 void stop_winbindd(void)
118 {
119         pid_t pid = pidfile_pid("winbindd");
120
121         if (geteuid() != 0) return;
122
123         if (pid <= 0) return;
124
125         kill(pid, SIGTERM);
126 }
127 #endif
128 /* kill a specified process */
129 void kill_pid(pid_t pid)
130 {
131         if (geteuid() != 0) return;
132
133         if (pid <= 0) return;
134
135         kill(pid, SIGTERM);
136         sleep(SLEEP_TIME);
137 }