summaryrefslogtreecommitdiffabout
path: root/src/process.cc
Unidiff
Diffstat (limited to 'src/process.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/process.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/process.cc b/src/process.cc
index bfab311..1ffac9f 100644
--- a/src/process.cc
+++ b/src/process.cc
@@ -10,31 +10,20 @@
10#include <iostream> 10#include <iostream>
11#include <fstream> 11#include <fstream>
12#include <stdexcept> 12#include <stdexcept>
13using namespace std; 13using namespace std;
14#include "process.h" 14#include "process.h"
15#include "configuration.h" 15#include "configuration.h"
16 16
17void process::check(const string& id,configuration& config) { 17void process::check(const string& id,configuration& config) {
18 bool running = false; 18 try {
19 ifstream pids(pidfile.c_str(),ios::in); 19 signal(0);
20 if(pids) {
21 pid_t pid = 0;
22 pids >> pid;
23 pids.close();
24 if(pid) {
25 if(!kill(pid,0)) {
26 running = true;
27 }
28 }
29 }
30 if(running){
31 patience = 0; 20 patience = 0;
32 }else{ 21 }catch(exception& e) {
33 if(patience>60) { // TODO: configurable 22 if(patience>60) { // TODO: configurable
34 patience = 0; 23 patience = 0;
35 }else{ 24 }else{
36 if(patience<10) { // TODO: configurable 25 if(patience<10) { // TODO: configurable
37 syslog(LOG_NOTICE,"The process '%s' is down, trying to launch.",id.c_str()); 26 syslog(LOG_NOTICE,"The process '%s' is down, trying to launch.",id.c_str());
38 do_notify(id,"Starting up", 27 do_notify(id,"Starting up",
39 "The named process seems to be down. Dudki will try\n" 28 "The named process seems to be down. Dudki will try\n"
40 "to revive it by running the specified command.\n", 29 "to revive it by running the specified command.\n",
@@ -180,8 +169,21 @@ void process::notify_mailto(const string& email,const string& id,const string& e
180 "This message was sent automatically by the 'dudki' daemon\n", 169 "This message was sent automatically by the 'dudki' daemon\n",
181 id.c_str(), event.c_str(), 170 id.c_str(), event.c_str(),
182 description.c_str() ); 171 description.c_str() );
183 fclose(mta); 172 fclose(mta);
184 int status; 173 int status;
185 waitpid(pid,&status,0); 174 waitpid(pid,&status,0);
186 // TODO: check the return code 175 // TODO: check the return code
187} 176}
177
178void process::signal(int signum) const {
179 ifstream pids(pidfile.c_str(),ios::in);
180 if(!pids)
181 throw runtime_error("no pidfile found");
182 pid_t pid = 0;
183 pids >> pid;
184 pids.close();
185 if(!pid)
186 throw runtime_error("no pid in pidfile");
187 if(kill(pid,signum))
188 throw runtime_error("failed to signal process");
189}