diff options
author | Jose <jose@zeroc.com> | 2018-10-29 18:30:50 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2018-10-29 18:30:50 +0100 |
commit | 5ce35f80fb561b58372fdf46ad52c2fd2949a630 (patch) | |
tree | 8da6db0bfc4a2a587e1266589a08259869856a9c /cpp/src/Ice/Service.cpp | |
parent | Fix for PHP 5.3 (Amzn 2018.03) build failures (diff) | |
download | ice-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.cpp | 29 |
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) |