File tree 7 files changed +99
-16
lines changed
include/decibel/messaging
7 files changed +99
-16
lines changed Original file line number Diff line number Diff line change @@ -50,18 +50,28 @@ as follows:
50
50
provides the API to sysadmin
51
51
- [ yaml-cpp] ( https://github.com/jbeder/yaml-cpp ) provides YAML config file support
52
52
53
+ Systemd Integration
54
+ ===================
55
+
56
+ sysadmin can integrate with systemd as a ` notify ` type service which can
57
+ prevent races between other services that rely on sysadmin for configuration.
58
+ In order to build sysadmin with systemd notify support you need to pass
59
+ ` -DSYSADMIN_USE_SD_NOTIFY ` during step 3 outlined below. When building sysadmin
60
+ in this configuration ` libsystemd ` becomes a required dependency.
61
+
62
+ There is an a systemd service definition which incorporates this functionality
63
+ located [ here] ( configs/prod/systemd-notify.service ) .
64
+
53
65
Development
54
66
===========
55
67
56
68
Generally speaking, build as follows:
57
69
58
- ```
59
- mkdir build
60
- cd build
61
- cmake ..
62
- make check
63
- make
64
- ```
70
+ 1 . mkdir build
71
+ 2 . cd build
72
+ 3 . cmake ..
73
+ 4 . make check
74
+ 5 . make
65
75
66
76
` make check ` runs only sysadmin's tests. If you wish to run the decibel-cpp tests, run
67
77
` make decibel-check ` .
Original file line number Diff line number Diff line change
1
+ #.rst:
2
+ # FindSystemd
3
+ # -------
4
+ #
5
+ # Find Systemd library
6
+ #
7
+ # Try to find Systemd library on UNIX systems. The following values are defined
8
+ #
9
+ # ::
10
+ #
11
+ # SYSTEMD_FOUND - True if Systemd is available
12
+ # SYSTEMD_INCLUDE_DIRS - Include directories for Systemd
13
+ # SYSTEMD_LIBRARIES - List of libraries for Systemd
14
+ # SYSTEMD_DEFINITIONS - List of definitions for Systemd
15
+ #
16
+ #=============================================================================
17
+ # Copyright (c) 2015 Jari Vetoniemi
18
+ #
19
+ # Distributed under the OSI-approved BSD License (the "License");
20
+ #
21
+ # This software is distributed WITHOUT ANY WARRANTY; without even the
22
+ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
+ # See the License for more information.
24
+ #=============================================================================
25
+
26
+ include (FeatureSummary)
27
+ set_package_properties(Systemd PROPERTIES
28
+ URL "http://freedesktop.org/wiki/Software/systemd/"
29
+ DESCRIPTION "System and Service Manager" )
30
+
31
+ find_package (PkgConfig)
32
+ pkg_check_modules(PC_SYSTEMD QUIET libsystemd)
33
+ find_library (SYSTEMD_LIBRARIES NAMES systemd ${PC_SYSTEMD_LIBRARY_DIRS} )
34
+ find_path (SYSTEMD_INCLUDE_DIRS systemd/sd-login.h HINTS ${PC_SYSTEMD_INCLUDE_DIRS} )
35
+
36
+ set (SYSTEMD_DEFINITIONS ${PC_SYSTEMD_CFLAGS_OTHER} )
37
+
38
+ include (FindPackageHandleStandardArgs)
39
+ find_package_handle_standard_args(SYSTEMD DEFAULT_MSG SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
40
+ mark_as_advanced (SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES SYSTEMD_DEFINITIONS)
Original file line number Diff line number Diff line change
1
+ [Unit]
2
+ Description =Sysadmin
3
+ After =network.target syslog.target
4
+
5
+ [Service]
6
+ Type =notify
7
+ ExecStart =/bin/sysadmin /etc/sysadmin/config.yaml
8
+ Restart =always
9
+ RestartSec =30
10
+
11
+ [Install]
12
+ WantedBy =multi-user.target
Original file line number Diff line number Diff line change @@ -70,9 +70,7 @@ class Reactor : public folly::Timekeeper
70
70
return pPromise->getFuture ();
71
71
}
72
72
73
- // This is kept around for posterity should anyone want to add back
74
- // folly::Executor functionality
75
- // virtual void add(folly::Func fn);
73
+ virtual void add (folly::Func fn);
76
74
77
75
// folly::TimeKeeper
78
76
virtual folly::Future<folly::Unit> after (folly::Duration duration);
Original file line number Diff line number Diff line change @@ -152,12 +152,10 @@ void Reactor::CancelCall(std::shared_ptr<OneShotTimerEvent> pTimer)
152
152
pTimer->Stop ();
153
153
}
154
154
155
- // This is kept around for posterity should anyone want to add back
156
- // folly::Executor functionality
157
- // void Reactor::add(folly::Func fn)
158
- // {
159
- // CallSoon(fn);
160
- // }
155
+ void Reactor::add (folly::Func fn)
156
+ {
157
+ CallSoon (fn);
158
+ }
161
159
162
160
folly::Future<folly::Unit> Reactor::after (folly::Duration duration)
163
161
{
Original file line number Diff line number Diff line change @@ -72,5 +72,15 @@ target_link_libraries(libsysadmin INTERFACE ${LIBS} decibel)
72
72
target_include_directories (libsysadmin PUBLIC ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR} )
73
73
target_link_libraries (sysadmin libsysadmin)
74
74
75
+ if (SYSADMIN_USE_SD_NOTIFY)
76
+ include (FindSystemd)
77
+ find_package (Systemd REQUIRED)
78
+
79
+ target_link_libraries (sysadmin ${SYSTEMD_LIBRARIES} )
80
+ target_include_directories (sysadmin PRIVATE ${SYSTEMD_INCLUDE_DIRS} )
81
+
82
+ target_compile_definitions (sysadmin PRIVATE _SYSADMIN_USE_SD_NOTIFY)
83
+ endif ()
84
+
75
85
install (TARGETS sysadmin
76
86
RUNTIME DESTINATION bin)
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
+
3
+ #ifdef _SYSADMIN_USE_SD_NOTIFY
4
+ #include < systemd/sd-daemon.h>
5
+ #endif
6
+
2
7
#include < boost/filesystem.hpp>
3
8
#include < log4cxx/logger.h>
4
9
#include < log4cxx/propertyconfigurator.h>
@@ -103,6 +108,16 @@ int main(int argc, const char* argv[])
103
108
protocol->Send (errResponse);
104
109
});
105
110
111
+ #ifdef _SYSADMIN_USE_SD_NOTIFY
112
+ reactor.add ([]() {
113
+ auto rc = sd_notify (1 , " READY=1" );
114
+
115
+ if (rc < 0 ) {
116
+ LOG4CXX_WARN (spLogger, " Failed to notify systemd, error: " << rc);
117
+ }
118
+ });
119
+ #endif
120
+
106
121
LOG4CXX_INFO (spLogger, " Starting sysadmin on port " << config.port );
107
122
reactor.ServeTcp (config.host , config.port , &factory);
108
123
reactor.Start ();
You can’t perform that action at this time.
0 commit comments