124 |
*/ |
*/ |
125 |
void dstart_process(char *P) { |
void dstart_process(char *P) { |
126 |
|
|
127 |
int pid; |
Dependant_T d; |
128 |
|
Process_T p; |
129 |
|
int pid, s; |
130 |
|
|
131 |
if ( ! exist_process(P) ) { |
if ( ! exist_process(P) ) { |
132 |
|
|
133 |
error("%s: Cannot start program '%s' -- not found in %s\n", |
error("%s: Cannot start program '%s' -- not found in %s\n", |
136 |
return; |
return; |
137 |
|
|
138 |
} |
} |
139 |
|
|
140 |
if ( (pid= is_process_running(get_process(P))) ) { |
p= get_process(P); |
141 |
|
|
142 |
|
if ( (pid= is_process_running(p))) { |
143 |
|
|
144 |
error("%s: '%s' is already running with pid=%d\n", prog, P, pid); |
error("%s: '%s' is already running with pid=%d\n", prog, P, pid); |
145 |
|
|
146 |
return; |
return; |
147 |
|
|
148 |
} |
} |
149 |
|
|
150 |
if ( exist_daemon() ) { |
if ( exist_daemon() ) { |
151 |
|
|
152 |
/* If a monit daemon exist we request that the daemon start the |
/* If a monit daemon exist we request that the daemon start the |
153 |
program in case the daemon timed out the program. This way any |
program in case the daemon timed out the program. This way any |
154 |
process timeout lock in the daemon is removed */ |
process timeout lock in the daemon is removed */ |
155 |
|
|
156 |
|
char req[2*STRLEN]; |
157 |
|
char *auth= get_basic_authentication_header(); |
158 |
|
|
159 |
int s= create_socket(Run.bind_addr?Run.bind_addr:"localhost", |
/* stop dependant processes */ |
160 |
Run.httpdport, SOCK_STREAM); |
for(d= p->dependantlist; d; d= p->dependantlist->next) { |
161 |
|
if(d->dependant == NULL) { |
162 |
if (s<0) { |
break; |
163 |
|
} |
164 |
|
s= create_socket(Run.bind_addr?Run.bind_addr:"localhost", |
165 |
|
Run.httpdport, SOCK_STREAM); |
166 |
|
if(s<0) { |
167 |
|
error("%s: Cannot connect to the monit daemon. " |
168 |
|
"Did you start it with http support?\n", prog); |
169 |
|
return; |
170 |
|
} else { |
171 |
|
snprintf(req, 2*STRLEN, |
172 |
|
"GET /%s?action=stop HTTP/1.0\r\n%s\r\n", d->dependant, auth); |
173 |
|
sock_send(s, req, sizeof(req), 0); |
174 |
|
close_socket(s); |
175 |
|
if(d->next == NULL) { |
176 |
|
break; |
177 |
|
} |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
|
/* Now start the process we asked for */ |
182 |
|
s= create_socket(Run.bind_addr?Run.bind_addr:"localhost", |
183 |
|
Run.httpdport, SOCK_STREAM); |
184 |
|
if(s<0) { |
185 |
error("%s: Cannot connect to the monit daemon. " |
error("%s: Cannot connect to the monit daemon. " |
186 |
"Did you start it with http support?\n", prog); |
"Did you start it with http support?\n", prog); |
|
|
|
187 |
return; |
return; |
|
|
|
188 |
} else { |
} else { |
|
|
|
|
char req[2*STRLEN]; |
|
|
char *auth= get_basic_authentication_header(); |
|
|
|
|
189 |
snprintf(req, 2*STRLEN, |
snprintf(req, 2*STRLEN, |
190 |
"GET /%s?action=start HTTP/1.0\r\n%s\r\n", P, auth); |
"GET /%s?action=start HTTP/1.0\r\n%s\r\n", P, auth); |
|
|
|
191 |
sock_send(s, req, sizeof(req), 0); |
sock_send(s, req, sizeof(req), 0); |
192 |
close_socket(s); |
close_socket(s); |
193 |
free(auth); |
free(auth); |
194 |
|
} |
195 |
|
/* Set flags on dependant processes so they restart */ |
196 |
|
for(d= p->dependantlist; d; d= p->dependantlist->next) { |
197 |
|
if(d->dependant == NULL) { |
198 |
|
break; |
199 |
|
} |
200 |
|
start_process(get_process(d->dependant)); |
201 |
|
if(d->next == NULL) { |
202 |
|
break; |
203 |
|
} |
204 |
} |
} |
205 |
} else { |
} else { |
206 |
|
|
207 |
/* No monit daemon exist, just start the program */ |
/* No monit daemon exist, just start the program */ |
208 |
start_process(get_process(P)); |
/* stop dependant processes */ |
209 |
|
for(d= p->dependantlist; d; d= p->dependantlist->next) { |
210 |
|
if(d->dependant == NULL) { |
211 |
|
break; |
212 |
|
} |
213 |
|
stop_process(get_process(d->dependant)); |
214 |
|
if(d->next == NULL) { |
215 |
|
break; |
216 |
|
} |
217 |
|
} |
218 |
|
start_process(p); |
219 |
|
|
220 |
|
/* Set flags on dependant processes so they restart */ |
221 |
|
for(d= p->dependantlist; d; d= p->dependantlist->next) { |
222 |
|
if(d->dependant == NULL) { |
223 |
|
break; |
224 |
|
} |
225 |
|
start_process(get_process(d->dependant)); |
226 |
|
if(d->next == NULL) { |
227 |
|
break; |
228 |
|
} |
229 |
|
} |
230 |
} |
} |
|
|
|
231 |
} |
} |