00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <stdio.h>
00023
00024 #ifdef HAVE_SYS_TYPES_H
00025 #include <sys/types.h>
00026 #endif
00027
00028 #include <sys/socket.h>
00029 #include <stdlib.h>
00030
00031 #ifdef HAVE_STRING_H
00032 #include <string.h>
00033 #endif
00034
00035 #include "monitor.h"
00036 #include "net.h"
00037
00038
00050
00051
00052
00056 void start() {
00057
00058 Process_T p;
00059
00060 for(p= processlist; p; p= p->next) {
00061
00062 if(p->start) dstart_process(p->name);
00063
00064 }
00065
00066 }
00067
00068
00072 void start_group(char *G) {
00073
00074 Process_T p;
00075
00076 for(p= processlist; p; p= p->next) {
00077
00078 if(is(p->group, G) ) {
00079
00080 if(p->start) dstart_process(p->name);
00081
00082 }
00083
00084
00085 }
00086
00087 }
00088
00089
00094 void start_process(Process_T p) {
00095
00096 pid_t pid= -1;
00097
00098 if(!p->start) {
00099
00100 error("Start: '%s' the start program is not defined\n", p->name);
00101 return;
00102
00103 }
00104
00105 if((pid= is_process_running(p))) {
00106
00107 error("Start: '%s' is already started with pid=%d\n",
00108 p->name, (int)pid);
00109
00110 return;
00111
00112 }
00113
00114 log("Start: (%s) %s\n", p->name, p->start->arg[0]);
00115
00116 spawn(p, p->start);
00117
00118 }
00119
00120
00125 void dstart_process(char *P) {
00126
00127 int pid;
00128
00129 if ( ! exist_process(P) ) {
00130
00131 error("%s: Cannot start program '%s' -- not found in %s\n",
00132 prog, P, Run.controlfile);
00133
00134 return;
00135
00136 }
00137
00138 if ( (pid= is_process_running(get_process(P))) ) {
00139
00140 error("%s: '%s' is already running with pid=%d\n", prog, P, pid);
00141
00142 return;
00143
00144 }
00145
00146 if ( exist_daemon() ) {
00147
00148
00149
00150
00151
00152 int s= create_socket(Run.bind_addr?Run.bind_addr:"localhost",
00153 Run.httpdport, SOCK_STREAM);
00154
00155 if (s<0) {
00156
00157 error("%s: Cannot connect to the monit daemon. "
00158 "Did you start it with http support?\n", prog);
00159
00160 return;
00161
00162 } else {
00163
00164 char req[2*STRLEN];
00165 char *auth= get_basic_authentication_header();
00166
00167 snprintf(req, 2*STRLEN,
00168 "GET /%s?action=start HTTP/1.0\r\n%s\r\n", P, auth);
00169
00170 sock_send(s, req, sizeof(req), 0);
00171 close_socket(s);
00172 free(auth);
00173
00174 }
00175 } else {
00176
00177
00178 start_process(get_process(P));
00179
00180 }
00181
00182 }