summaryrefslogtreecommitdiff
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
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
-rw-r--r--CHANGELOG-3.7.md10
-rw-r--r--config/PropertyNames.xml1
-rw-r--r--cpp/src/Ice/Instance.cpp8
-rw-r--r--cpp/src/Ice/Makefile.mk7
-rw-r--r--cpp/src/Ice/PropertyNames.cpp3
-rw-r--r--cpp/src/Ice/PropertyNames.h2
-rw-r--r--cpp/src/Ice/Service.cpp29
-rw-r--r--cpp/src/Ice/SystemdJournalI.cpp71
-rw-r--r--cpp/src/Ice/SystemdJournalI.h44
-rw-r--r--cpp/src/IceBox/ServiceManagerI.cpp1
-rw-r--r--csharp/src/Ice/PropertyNames.cs3
-rw-r--r--java-compat/src/Ice/src/main/java/IceInternal/PropertyNames.java3
-rw-r--r--java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java3
-rw-r--r--js/src/Ice/PropertyNames.js3
14 files changed, 182 insertions, 6 deletions
diff --git a/CHANGELOG-3.7.md b/CHANGELOG-3.7.md
index 2fb3b49582f..f43f2629754 100644
--- a/CHANGELOG-3.7.md
+++ b/CHANGELOG-3.7.md
@@ -55,6 +55,16 @@ These are the changes since Ice 3.7.1 included in this pre-release.
- Fixed an IceStorm bug that prevents topics to being correctly restored from
the database when there are multiple topics.
+- Add support for systemd `Type=Notify` to `Ice::Service`, services
+ started without `--daemon` command line option will send notifications
+ to systemd using `sd_notify` systemd API.
+
+- Add systemd journal logger, this longer can be enabled by setting `Ice.UseSystemdJournal`
+ property to a value greater than 1.
+
+
+`Ice.UseSystemdJournal`
+
## Java Changes
- Fixed Android IceSSL issue which would cause SSL connections to hang
diff --git a/config/PropertyNames.xml b/config/PropertyNames.xml
index 6f53c6aef27..e3139cd7594 100644
--- a/config/PropertyNames.xml
+++ b/config/PropertyNames.xml
@@ -401,6 +401,7 @@ generated from the section label.
<property name="TCP.SndSize" />
<property name="UseApplicationClassLoader" />
<property name="UseSyslog" />
+ <property name="UseSystemdJournal" />
<property name="Warn.AMICallback" />
<property name="Warn.Connections" />
<property name="Warn.Datagrams" />
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 45dad54ca6e..d1d1c7c9fda 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -58,6 +58,7 @@
#ifndef _WIN32
# include <Ice/SysLoggerI.h>
+# include <Ice/SystemdJournalI.h>
# include <signal.h>
# include <syslog.h>
@@ -1100,6 +1101,13 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi
_initData.properties->getProperty("Ice.ProgramName"),
_initData.properties->getPropertyWithDefault("Ice.SyslogFacility", "LOG_USER"));
}
+# ifdef ICE_USE_SYSTEMD
+ else if(_initData.properties->getPropertyAsInt("Ice.UseSystemdJournal") > 0)
+ {
+ _initData.logger = ICE_MAKE_SHARED(SystemdJournalI,
+ _initData.properties->getProperty("Ice.ProgramName"));
+ }
+# endif
else
#endif
if(!logfile.empty())
diff --git a/cpp/src/Ice/Makefile.mk b/cpp/src/Ice/Makefile.mk
index 7e4187cbc41..321188df0bc 100644
--- a/cpp/src/Ice/Makefile.mk
+++ b/cpp/src/Ice/Makefile.mk
@@ -26,6 +26,13 @@ ifeq ($(os),Darwin)
Ice_excludes += src/IceUtil/ConvertUTF.cpp src/IceUtil/Unicode.cpp
endif
+ifeq ($(os),Linux)
+ifeq ($(shell pkg-config --exists libsystemd 2> /dev/null && echo yes),yes)
+Ice_cppflags += -DICE_USE_SYSTEMD $(shell pkg-config --cflags libsystemd)
+Ice_ldflags += $(shell pkg-config --libs libsystemd)
+endif
+endif
+
Ice[iphoneos]_excludes := $(wildcard $(addprefix $(currentdir)/,Tcp*.cpp))
Ice[iphoneos]_extra_sources := $(wildcard $(addprefix $(currentdir)/ios/,*.cpp *.mm))
Ice[iphonesimulator]_excludes = $(Ice[iphoneos]_excludes)
diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp
index 5edd1c14013..982a087045f 100644
--- a/cpp/src/Ice/PropertyNames.cpp
+++ b/cpp/src/Ice/PropertyNames.cpp
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Sep 12 19:11:29 2018
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Oct 25 22:10:11 2018
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -181,6 +181,7 @@ const IceInternal::Property IcePropsData[] =
IceInternal::Property("Ice.TCP.SndSize", false, 0),
IceInternal::Property("Ice.UseApplicationClassLoader", false, 0),
IceInternal::Property("Ice.UseSyslog", false, 0),
+ IceInternal::Property("Ice.UseSystemdJournal", false, 0),
IceInternal::Property("Ice.Warn.AMICallback", false, 0),
IceInternal::Property("Ice.Warn.Connections", false, 0),
IceInternal::Property("Ice.Warn.Datagrams", false, 0),
diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h
index dac29ada243..16afba38aca 100644
--- a/cpp/src/Ice/PropertyNames.h
+++ b/cpp/src/Ice/PropertyNames.h
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Sep 12 19:11:29 2018
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Oct 25 22:10:11 2018
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
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)
diff --git a/cpp/src/Ice/SystemdJournalI.cpp b/cpp/src/Ice/SystemdJournalI.cpp
new file mode 100644
index 00000000000..aaede9991e3
--- /dev/null
+++ b/cpp/src/Ice/SystemdJournalI.cpp
@@ -0,0 +1,71 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#ifdef ICE_USE_SYSTEMD
+
+#include <Ice/SystemdJournalI.h>
+#include <Ice/LocalException.h>
+#include <syslog.h>
+#include <systemd/sd-journal.h>
+
+using namespace std;
+using namespace Ice;
+using namespace IceInternal;
+
+Ice::SystemdJournalI::SystemdJournalI(const string& prefix) :
+ _prefix(prefix)
+{
+}
+
+void
+Ice::SystemdJournalI::print(const string& message)
+{
+ write(LOG_INFO, message);
+}
+
+void
+Ice::SystemdJournalI::trace(const string& category, const string& message)
+{
+ write(LOG_INFO, category + ": " + message);
+}
+
+void
+Ice::SystemdJournalI::warning(const string& message)
+{
+ write(LOG_WARNING, message);
+}
+
+void
+Ice::SystemdJournalI::error(const string& message)
+{
+ write(LOG_ERR, message);
+}
+
+string
+Ice::SystemdJournalI::getPrefix()
+{
+ return _prefix;
+}
+
+Ice::LoggerPtr
+Ice::SystemdJournalI::cloneWithPrefix(const string& prefix)
+{
+ return ICE_MAKE_SHARED(SystemdJournalI, prefix);
+}
+
+void
+Ice::SystemdJournalI::write(int priority, const string& message) const
+{
+ sd_journal_send("MESSAGE=%s", message.c_str(),
+ "PRIORITY=%i", priority,
+ "SYSLOG_IDENTIFIER=%s", _prefix.c_str(),
+ 0);
+}
+
+#endif
diff --git a/cpp/src/Ice/SystemdJournalI.h b/cpp/src/Ice/SystemdJournalI.h
new file mode 100644
index 00000000000..c21a68e9015
--- /dev/null
+++ b/cpp/src/Ice/SystemdJournalI.h
@@ -0,0 +1,44 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#ifndef ICE_SYSTEMD_JOURNAL_I_H
+#define ICE_SYSTEMD_JOURNAL_I_H
+
+#ifdef ICE_USE_SYSTEMD
+
+#include <Ice/Logger.h>
+
+namespace Ice
+{
+
+class SystemdJournalI : public Logger
+{
+public:
+
+ SystemdJournalI(const std::string&);
+
+ virtual void print(const std::string&);
+ virtual void trace(const std::string&, const std::string&);
+ virtual void warning(const std::string&);
+ virtual void error(const std::string&);
+ virtual std::string getPrefix();
+ virtual LoggerPtr cloneWithPrefix(const std::string&);
+
+private:
+
+ void write(int, const std::string&) const;
+
+ const std::string _prefix;
+};
+
+}
+
+#endif
+
+#endif
diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp
index d0c82984777..1bfdb899f5d 100644
--- a/cpp/src/IceBox/ServiceManagerI.cpp
+++ b/cpp/src/IceBox/ServiceManagerI.cpp
@@ -622,6 +622,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
if(initData.properties->getProperty("Ice.LogFile").empty()
#ifndef _WIN32
&& initData.properties->getPropertyAsInt("Ice.UseSyslog") <= 0
+ && initData.properties->getPropertyAsInt("Ice.UseSystemdJournal") <= 0
#endif
)
{
diff --git a/csharp/src/Ice/PropertyNames.cs b/csharp/src/Ice/PropertyNames.cs
index f6d40b69ab4..8981c901318 100644
--- a/csharp/src/Ice/PropertyNames.cs
+++ b/csharp/src/Ice/PropertyNames.cs
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Sep 12 19:11:29 2018
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Oct 25 22:10:11 2018
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -183,6 +183,7 @@ namespace IceInternal
new Property(@"^Ice\.TCP\.SndSize$", false, null),
new Property(@"^Ice\.UseApplicationClassLoader$", false, null),
new Property(@"^Ice\.UseSyslog$", false, null),
+ new Property(@"^Ice\.UseSystemdJournal$", false, null),
new Property(@"^Ice\.Warn\.AMICallback$", false, null),
new Property(@"^Ice\.Warn\.Connections$", false, null),
new Property(@"^Ice\.Warn\.Datagrams$", false, null),
diff --git a/java-compat/src/Ice/src/main/java/IceInternal/PropertyNames.java b/java-compat/src/Ice/src/main/java/IceInternal/PropertyNames.java
index 48911b019a0..3dda3e42717 100644
--- a/java-compat/src/Ice/src/main/java/IceInternal/PropertyNames.java
+++ b/java-compat/src/Ice/src/main/java/IceInternal/PropertyNames.java
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Sep 12 19:11:29 2018
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Oct 25 22:10:11 2018
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -183,6 +183,7 @@ public final class PropertyNames
new Property("Ice\\.TCP\\.SndSize", false, null),
new Property("Ice\\.UseApplicationClassLoader", false, null),
new Property("Ice\\.UseSyslog", false, null),
+ new Property("Ice\\.UseSystemdJournal", false, null),
new Property("Ice\\.Warn\\.AMICallback", false, null),
new Property("Ice\\.Warn\\.Connections", false, null),
new Property("Ice\\.Warn\\.Datagrams", false, null),
diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java
index df9d327c7a1..ac8b4514dff 100644
--- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java
+++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/PropertyNames.java
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Sep 12 19:11:29 2018
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Oct 25 22:10:11 2018
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -183,6 +183,7 @@ public final class PropertyNames
new Property("Ice\\.TCP\\.SndSize", false, null),
new Property("Ice\\.UseApplicationClassLoader", false, null),
new Property("Ice\\.UseSyslog", false, null),
+ new Property("Ice\\.UseSystemdJournal", false, null),
new Property("Ice\\.Warn\\.AMICallback", false, null),
new Property("Ice\\.Warn\\.Connections", false, null),
new Property("Ice\\.Warn\\.Datagrams", false, null),
diff --git a/js/src/Ice/PropertyNames.js b/js/src/Ice/PropertyNames.js
index 544db00f3c2..e8431bb73ca 100644
--- a/js/src/Ice/PropertyNames.js
+++ b/js/src/Ice/PropertyNames.js
@@ -6,7 +6,7 @@
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
-// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Sep 12 19:11:29 2018
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Oct 25 22:10:11 2018
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -186,6 +186,7 @@ PropertyNames.IceProps =
new Property("/^Ice\.TCP\.SndSize/", false, null),
new Property("/^Ice\.UseApplicationClassLoader/", false, null),
new Property("/^Ice\.UseSyslog/", false, null),
+ new Property("/^Ice\.UseSystemdJournal/", false, null),
new Property("/^Ice\.Warn\.AMICallback/", false, null),
new Property("/^Ice\.Warn\.Connections/", false, null),
new Property("/^Ice\.Warn\.Datagrams/", false, null),