summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Service.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-10-29 18:30:50 +0100
committerJose <jose@zeroc.com>2018-10-29 18:30:50 +0100
commit5ce35f80fb561b58372fdf46ad52c2fd2949a630 (patch)
tree8da6db0bfc4a2a587e1266589a08259869856a9c /cpp/src/Ice/Service.cpp
parentFix for PHP 5.3 (Amzn 2018.03) build failures (diff)
downloadice-5ce35f80fb561b58372fdf46ad52c2fd2949a630.tar.bz2
ice-5ce35f80fb561b58372fdf46ad52c2fd2949a630.tar.xz
ice-5ce35f80fb561b58372fdf46ad52c2fd2949a630.zip
Add support for systemd Type=notify to Ice::Service
Close #75
Diffstat (limited to 'cpp/src/Ice/Service.cpp')
-rw-r--r--cpp/src/Ice/Service.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index b1243532bfc..a6b6d70493a 100644
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -34,6 +34,9 @@
# include <sys/types.h>
# include <sys/stat.h>
# include <csignal>
+# ifdef ICE_USE_SYSTEMD
+# include <systemd/sd-daemon.h>
+# endif
#endif
using namespace std;
@@ -822,11 +825,20 @@ Ice::Service::run(int argc, const char* const argv[], const InitializationData&
//
if(start(av.argc, av.argv, status))
{
+#ifdef ICE_USE_SYSTEMD
+ sd_notify(0, "READY=1");
+#endif
//
// Wait for service shutdown.
//
waitForShutdown();
+#ifdef ICE_USE_SYSTEMD
+ //
+ // Inform the service manager that the service is beginning its shutdown.
+ //
+ sd_notify(0, "STOPPING=1");
+#endif
//
// Stop the service.
//
@@ -840,25 +852,42 @@ Ice::Service::run(int argc, const char* const argv[], const InitializationData&
{
ServiceError err(this);
err << "service terminating after catching exception:\n" << ex;
+#ifdef ICE_USE_SYSTEMD
+ const string msg = err.str();
+ sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg.c_str());
+#endif
}
catch(const std::exception& ex)
{
ServiceError err(this);
err << "service terminating after catching exception:\n" << ex;
+#ifdef ICE_USE_SYSTEMD
+ const string msg = err.str();
+ sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg.c_str());
+#endif
}
catch(const std::string& msg)
{
ServiceError err(this);
err << "service terminating after catching exception:\n" << msg;
+#ifdef ICE_USE_SYSTEMD
+ sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg.c_str());
+#endif
}
catch(const char* msg)
{
ServiceError err(this);
err << "service terminating after catching exception:\n" << msg;
+#ifdef ICE_USE_SYSTEMD
+ sd_notifyf(0, "STATUS=Failed service terminating after catching exception: %s", msg);
+#endif
}
catch(...)
{
error("service terminating after catching unknown exception");
+#ifdef ICE_USE_SYSTEMD
+ sd_notify(0, "STATUS=Failed service terminating after catching unknown exception");
+#endif
}
if(_communicator)