return rval;
}
+static int signalNameToNumber(std::string &signame)
+{
+ if (signame == "HUP") return SIGHUP;
+ if (signame == "INT") return SIGINT;
+ if (signame == "QUIT") return SIGQUIT;
+ if (signame == "USR1") return SIGUSR1;
+ if (signame == "USR2") return SIGUSR2;
+ return -1;
+}
// Find a service record, or load it from file. If the service has
// dependencies, load those also.
std::list<ServiceRecord *> depends_soft;
string logfile;
OnstartFlags onstart_flags;
+ int term_signal = -1; // additional termination signal
string line;
bool auto_restart = false;
}
}
}
+ else if (setting == "termsignal") {
+ string signame = read_setting_value(i, end, nullptr);
+ int signo = signalNameToNumber(signame);
+ if (signo == -1) {
+ throw new ServiceDescriptionExc(name, "Unknown/unsupported termination signal: " + signame);
+ }
+ else {
+ term_signal = signo;
+ }
+ }
else {
throw ServiceDescriptionExc(name, "Unknown setting: " + setting);
}
rval->setLogfile(logfile);
rval->setAutoRestart(auto_restart);
rval->setOnstartFlags(onstart_flags);
+ rval->setExtraTerminationSignal(term_signal);
*iter = rval;
break;
}
if (pid != -1) {
// The process is still kicking on - must actually kill it.
kill(pid, SIGTERM);
+ if (term_signal != -1) {
+ kill(pid, term_signal);
+ }
// Now we wait; the rest is done in process_child_callback
}
else {
#include <string>
#include <list>
#include <vector>
+#include <csignal>
#include "ev.h"
/*
// case if for example the process dies; the service,
// and all its dependencies, MUST be stopped.
+ int term_signal = -1; // signal to use for process termination
+
// Implementation details
pid_t pid; /* PID of the process. If state is STARTING or STOPPING,
{
this->onstart_flags = flags;
}
+
+ // Set an additional signal (other than SIGTERM) to be used to terminate the process
+ void setExtraTerminationSignal(int signo)
+ {
+ this->term_signal = signo;
+ }
const char *getServiceName() const { return service_name.c_str(); }
ServiceState getState() const { return service_state; }