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 <errno.h>
00030 #include <stdlib.h>
00031
00032 #ifdef HAVE_STRING_H
00033 #include <string.h>
00034 #endif
00035
00036 #ifdef HAVE_UNISTD_H
00037 #include <unistd.h>
00038 #endif
00039
00040 #ifdef HAVE_SYS_WAIT_H
00041 #include <sys/wait.h>
00042 #endif
00043
00044 #include "monitor.h"
00045 #include "net.h"
00046 #include "engine.h"
00047
00048
00049 static void *thread_wrapper(void *arg);
00050
00051
00052 static pthread_t thread;
00053
00054
00067
00068
00069
00073 int check_httpd() {
00074
00075 return check_connect(Run.bind_addr?Run.bind_addr:"localhost",
00076 Run.httpdport, SOCK_STREAM);
00077
00078 }
00079
00080
00086 int can_http() {
00087
00088 if ( Run.dohttpd && Run.isdaemon ) {
00089
00090 if ( ! has_hosts_allow() && ! Run.Auth.defined ) {
00091
00092 error("%s: monit httpd not started since no connect allowed\n",
00093 prog);
00094
00095 return FALSE;
00096
00097 }
00098
00099 return TRUE;
00100
00101 }
00102
00103 return FALSE;
00104
00105 }
00106
00107
00112 void monit_http(int action) {
00113
00114 int status;
00115
00116 switch ( action ) {
00117
00118 case STOP_HTTP: {
00119
00120 log("Stopping %s HTTP server\n", prog);
00121 stop_httpd();
00122
00123 }
00124
00125 return;
00126
00127 case START_HTTP:
00128
00129 log("Starting %s HTTP server at portnumber %d\n", prog, Run.httpdport);
00130
00131 break;
00132
00133 }
00134
00135 status= pthread_create(&thread, NULL, thread_wrapper, NULL);
00136
00137 if ( status != 0 ) {
00138
00139 log("%s: Failed to create the http server. Thread error -- %s.\n",
00140 prog, strerror(status));
00141
00142 }
00143
00144 }
00145
00146
00147
00148
00149
00150 static void *thread_wrapper(void *arg) {
00151
00152 sigset_t ns;
00153
00154 pthread_detach(pthread_self());
00155
00156
00157 sigemptyset(&ns);
00158 sigaddset(&ns, SIGUSR1);
00159 pthread_sigmask(SIG_BLOCK, &ns, NULL);
00160
00161 start_httpd(Run.httpdport, 10, Run.bind_addr);
00162
00163 return NULL;
00164
00165 }
00166
00167