-
Notifications
You must be signed in to change notification settings - Fork 221
Add functionality to notify systemd on olad startup and config reload #1444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
a30e440
a5e57fe
183ac8d
693fe33
0257949
50c9bda
29556d0
b7afd38
83807d4
469361d
f15b385
d674930
bf8deff
175b393
17d917c
1cd1202
64400b8
d62a8f6
ff34724
f6f5813
15efd6f
18735c4
a21f0a4
c714ee8
527b115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -748,6 +748,21 @@ AC_ARG_ENABLE( | |
| [AS_HELP_STRING([--disable-doxygen-version], | ||
| [Substitute the Doxygen version with latest, for the website])]) | ||
|
|
||
| # systemd support | ||
| AC_ARG_ENABLE( | ||
| [systemd], | ||
| [AS_HELP_STRING([--enable-systemd], [Enable systemd support])]) | ||
|
|
||
| have_libsystemd="no" | ||
| AS_IF([test "x$enable_systemd" = "xyes"], | ||
| [PKG_CHECK_MODULES([libsystemd], [libsystemd >= 38], [have_libsystemd="yes"]) | ||
| AC_CHECK_HEADER([systemd/sd-daemon.h], [], [have_libsystemd="no"])]) | ||
|
|
||
| AS_IF([test "x$have_libsystemd" = xyes], | ||
| [AC_DEFINE([HAVE_LIBSYSTEMD], [1], [define if systemd support wanted])]) | ||
|
||
|
|
||
| AM_CONDITIONAL([HAVE_LIBSYSTEMD], [test "x$have_libsystemd" = xyes]) | ||
|
|
||
| # UUCP Lock directory | ||
| AC_ARG_WITH([uucp-lock], | ||
| [AS_HELP_STRING([--with-uucp-lock], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,11 @@ ola_server_sources += olad/HttpServerActions.cpp \ | |
| ola_server_additional_libs += common/http/libolahttp.la | ||
| endif | ||
|
|
||
| if HAVE_LIBSYSTEMD | ||
| ola_server_sources += olad/NotifySystemd.cpp olad/Systemd.h | ||
|
||
| ola_server_additional_libs += $(libsystemd_LIBS) | ||
| endif | ||
|
|
||
| # lib olaserver | ||
| lib_LTLIBRARIES += olad/libolaserver.la | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Library General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * NotifySystemd.cpp | ||
| * Provides wrapped access to the systemd notification interface. | ||
| * Copyright (C) 2018 Shenghao Yang | ||
| */ | ||
|
|
||
| #if HAVE_CONFIG_H | ||
| #include <config.h> | ||
| #endif // HAVE_CONFIG_H | ||
|
|
||
| #if HAVE_LIBSYSTEMD | ||
| #include <systemd/sd-daemon.h> | ||
| #include <errno.h> | ||
| #include <string.h> | ||
| #endif // HAVE_LIBSYSTEMD | ||
|
|
||
| #include "ola/Logging.h" | ||
|
|
||
| #include "olad/Systemd.h" | ||
|
|
||
| namespace ola { | ||
|
|
||
| int notify_systemd(int unset_environment, const char *state) { | ||
|
||
| int rtn = sd_notify(unset_environment, state); | ||
| if (rtn < 0) { | ||
| char buf[1024]; | ||
| OLA_WARN << "Error sending notification to systemd: " << | ||
| strerror_r(-rtn, buf, sizeof(buf)); | ||
|
||
| } | ||
| return rtn; | ||
| } | ||
|
|
||
| bool notify_available() { | ||
|
||
| return (sd_notify(0, "") != 0); | ||
| } | ||
|
|
||
| } // namespace ola | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,10 @@ | |
| #include "olad/OladHTTPServer.h" | ||
| #endif // HAVE_LIBMICROHTTPD | ||
|
|
||
| #ifdef HAVE_LIBSYSTEMD | ||
| #include "olad/Systemd.h" | ||
| #endif // HAVE_LIBSYSTEMD | ||
|
|
||
| DEFINE_s_uint16(rpc_port, r, ola::OlaServer::DEFAULT_RPC_PORT, | ||
| "The port to listen for RPCs on. Defaults to 9010."); | ||
| DEFINE_default_bool(register_with_dns_sd, true, | ||
|
|
@@ -472,9 +476,15 @@ bool OlaServer::InternalNewConnection( | |
| } | ||
|
|
||
| void OlaServer::ReloadPluginsInternal() { | ||
| #ifdef HAVE_LIBSYSTEMD | ||
| ola::notify_systemd(0, "RELOADING=1\nSTATUS=Reloading plugins\n"); | ||
|
||
| #endif // HAVE_LIBSYSTEMD | ||
| OLA_INFO << "Reloading plugins"; | ||
| StopPlugins(); | ||
| m_plugin_manager->LoadAll(); | ||
| #ifdef HAVE_LIBSYSTEMD | ||
| ola::notify_systemd(0, "READY=1\nSTATUS=Plugin reload complete\n"); | ||
| #endif // HAVE_LIBSYSTEMD | ||
| } | ||
|
|
||
| void OlaServer::UpdatePidStore(const RootPidStore *pid_store) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Library General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Systemd.h | ||
| * Interface to systemd functionality. | ||
| * Copyright (C) 2018 Shenghao Yang | ||
| */ | ||
|
|
||
| #ifndef OLAD_SYSTEMD_H_ | ||
| #define OLAD_SYSTEMD_H_ | ||
|
|
||
| namespace ola { | ||
|
|
||
| /* | ||
| * @brief Notify systemd about daemon state changes. | ||
| * | ||
| * This function logs on failures to queue notifications, but only if the | ||
|
||
| * notification socket environment variable is set. | ||
| * | ||
| * @param unset_environment whether to unset the notification socket environment | ||
| * variable so child processes cannot utilize it. | ||
| * @param state state block to pass to systemd. | ||
| * @return value returned from \ref sd_notify() | ||
| */ | ||
| int notify_systemd(int unset_environment, const char *state); | ||
|
|
||
| /* | ||
| * @brief Tests whether the systemd notification socket is available. | ||
| * @return @c true if the socket is available, @c false if not. | ||
| */ | ||
| bool notify_available(); | ||
|
|
||
| } // namespace ola | ||
| #endif // OLAD_SYSTEMD_H_ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to negate this, so it's turned on by default where available (or no-one will realise it exists/use it). See e.g. https://github.com/OpenLightingProject/ola/blob/master/configure.ac#L573-L589 and don't forget to update the AS_IF below too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eek.. an automatic dependency feels a little weird to me, unless we put it out for people to know. If we put the existence of this option in
NEWS(which is probably where it will end up in) and you suspect:then, if we put in a warning that
libsystemdis going to become an automatic dependency, I kinda also think thatuntil bug reports come in regarding
libsystemdnot being found on non-build systems...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we have the best of both worlds with our plugins, a literal auto mode, so by default if the bits are there, you get your plugin and if they aren't you don't, but you can also force it on (so it complains if dependencies are missing) or force it off (so it doesn't use it even if present).
You may be right about bug reports, I guess I'd tend towards the nudge theory, if we turn it on, then people who read the docs will turn it off easily, those who don't will ideally search or file a bug/ask on the mailing list and there's a workaround.
If we leave it off, we should at least enable it in our Debian build config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, alright. Let's default it to enabled. We're going to be playing devil's advocate (to some people out there) and silently promote
systemdadoption...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 83807d4