aboutsummaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-03-12 12:00:10 +0100
committerGitHub <noreply@github.com>2019-03-12 12:00:10 +0100
commit780fcd6f39ea3672e1c7d520486e5cdf15885dd1 (patch)
tree5f32f2f4bdf6df89a25f3328cd5caace3aa6ddc1 /configd
parent12edc09d7baf54b851f922447738d53beea292b2 (diff)
parentf9c2e2629cdf04b9a643f27c3583086b5c6e60d7 (diff)
Merge pull request #8736 from vespa-engine/arnej/add-restart-service
add "restart" hooks
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/cmd/main.cpp3
-rw-r--r--configd/src/apps/sentinel/cmdq.h2
-rw-r--r--configd/src/apps/sentinel/config-handler.cpp17
-rw-r--r--configd/src/apps/sentinel/rpchooks.cpp16
-rw-r--r--configd/src/apps/sentinel/rpchooks.h1
5 files changed, 37 insertions, 2 deletions
diff --git a/configd/src/apps/cmd/main.cpp b/configd/src/apps/cmd/main.cpp
index f2d6e161727..6228de86a80 100644
--- a/configd/src/apps/cmd/main.cpp
+++ b/configd/src/apps/cmd/main.cpp
@@ -36,6 +36,7 @@ void usage()
fprintf(stderr, "usage: vespa-sentinel-cmd <cmd> [arg]\n");
fprintf(stderr, "with cmd one of:\n");
fprintf(stderr, " list\n");
+ fprintf(stderr, " restart {service}\n");
fprintf(stderr, " start {service}\n");
fprintf(stderr, " stop {service}\n");
}
@@ -109,6 +110,8 @@ parseCmd(const char *arg)
{
if (strcmp(arg, "list") == 0) {
return "sentinel.ls";
+ } else if (strcmp(arg, "restart") == 0) {
+ return "sentinel.service.restart";
} else if (strcmp(arg, "start") == 0) {
return "sentinel.service.start";
} else if (strcmp(arg, "stop") == 0) {
diff --git a/configd/src/apps/sentinel/cmdq.h b/configd/src/apps/sentinel/cmdq.h
index df7dc9f241d..105d5f29b60 100644
--- a/configd/src/apps/sentinel/cmdq.h
+++ b/configd/src/apps/sentinel/cmdq.h
@@ -13,7 +13,7 @@ namespace config::sentinel {
class Cmd {
public:
using UP = std::unique_ptr<Cmd>;
- enum CmdType { LIST, START, STOP };
+ enum CmdType { LIST, RESTART, START, STOP };
Cmd(FRT_RPCRequest *req, CmdType cmdType, const char *service = "")
: _req(req), _cmdType(cmdType), _serviceName(service)
diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp
index 486c46e7442..d9f4d1f8bd7 100644
--- a/configd/src/apps/sentinel/config-handler.cpp
+++ b/configd/src/apps/sentinel/config-handler.cpp
@@ -402,6 +402,22 @@ ConfigHandler::handleCmd(const Cmd& cmd)
cmd.retValue(retbuf);
}
break;
+ case Cmd::RESTART:
+ {
+ Service *service = serviceByName(cmd.serviceName());
+ if (service == nullptr) {
+ cmd.retError("Cannot find named service");
+ return;
+ }
+ service->setAutomatic(true);
+ service->resetRestartPenalty();
+ if (service->isRunning()) {
+ service->terminate(true, false);
+ } else {
+ service->start();
+ }
+ }
+ break;
case Cmd::START:
{
Service *service = serviceByName(cmd.serviceName());
@@ -410,6 +426,7 @@ ConfigHandler::handleCmd(const Cmd& cmd)
return;
}
service->setAutomatic(true);
+ service->resetRestartPenalty();
if (! service->isRunning()) {
service->start();
}
diff --git a/configd/src/apps/sentinel/rpchooks.cpp b/configd/src/apps/sentinel/rpchooks.cpp
index 6e271db3977..99bcd404402 100644
--- a/configd/src/apps/sentinel/rpchooks.cpp
+++ b/configd/src/apps/sentinel/rpchooks.cpp
@@ -23,13 +23,17 @@ RPCHooks::initRPC(FRT_Supervisor *supervisor)
rb.MethodDesc("list services");
rb.ReturnDesc("status", "Status for services");
//-------------------------------------------------------------------------
+ rb.DefineMethod("sentinel.service.restart", "s", "",
+ FRT_METHOD(RPCHooks::rpc_restartService), this);
+ rb.MethodDesc("restart a service");
+ //-------------------------------------------------------------------------
rb.DefineMethod("sentinel.service.stop", "s", "",
FRT_METHOD(RPCHooks::rpc_stopService), this);
rb.MethodDesc("stop a service");
//-------------------------------------------------------------------------
rb.DefineMethod("sentinel.service.start", "s", "",
FRT_METHOD(RPCHooks::rpc_startService), this);
- rb.MethodDesc("stop a service");
+ rb.MethodDesc("start a service");
//-------------------------------------------------------------------------
}
@@ -42,6 +46,16 @@ RPCHooks::rpc_listServices(FRT_RPCRequest *req)
}
void
+RPCHooks::rpc_restartService(FRT_RPCRequest *req)
+{
+ FRT_Values &args = *req->GetParams();
+ const char *srvNM = args[0]._string._str;
+ LOG(debug, "got restartservice '%s'", srvNM);
+ req->Detach();
+ _commands.enqueue(std::make_unique<Cmd>(req, Cmd::RESTART, srvNM));
+}
+
+void
RPCHooks::rpc_stopService(FRT_RPCRequest *req)
{
FRT_Values &args = *req->GetParams();
diff --git a/configd/src/apps/sentinel/rpchooks.h b/configd/src/apps/sentinel/rpchooks.h
index 9375dc895be..05070830491 100644
--- a/configd/src/apps/sentinel/rpchooks.h
+++ b/configd/src/apps/sentinel/rpchooks.h
@@ -32,6 +32,7 @@ public:
void initRPC(FRT_Supervisor *supervisor);
private:
void rpc_listServices(FRT_RPCRequest *req);
+ void rpc_restartService(FRT_RPCRequest *req);
void rpc_stopService(FRT_RPCRequest *req);
void rpc_startService(FRT_RPCRequest *req);
};