]> git.proxmox.com Git - lxc.git/blame - debian/patches/0007-possibility-to-run-lxc-monitord-as-a-regular-daemon.patch
bump version to 3.0.0-3
[lxc.git] / debian / patches / 0007-possibility-to-run-lxc-monitord-as-a-regular-daemon.patch
CommitLineData
1513a0b5 1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ade16ee6 2From: Wolfgang Bumiller <w.bumiller@proxmox.com>
bc7e56ac 3Date: Mon, 20 Nov 2017 10:49:41 +0100
1513a0b5 4Subject: [PATCH] possibility to run lxc-monitord as a regular daemon
ade16ee6 5
bc7e56ac
WB
6lxc-monitord instances are spawned on demand and, if this
7happens from a service, the daemon is considered part of
8it by systemd, as it is running in the same cgroups. This
9can be avoided by leaving it running permanently.
ade16ee6
WB
10
11Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
12---
13 config/init/systemd/Makefile.am | 10 +++--
14 config/init/systemd/lxc-monitord.service.in | 12 ++++++
ade16ee6
WB
15 configure.ac | 1 +
16 lxc.spec.in | 1 +
1513a0b5 17 src/lxc/cmd/lxc_monitord.c | 60 +++++++++++++++++++++--------
bc7e56ac 18 5 files changed, 63 insertions(+), 21 deletions(-)
ade16ee6
WB
19 create mode 100644 config/init/systemd/lxc-monitord.service.in
20
21diff --git a/config/init/systemd/Makefile.am b/config/init/systemd/Makefile.am
7395ab25 22index c448850d..4a4fde5e 100644
ade16ee6
WB
23--- a/config/init/systemd/Makefile.am
24+++ b/config/init/systemd/Makefile.am
25@@ -2,19 +2,21 @@ EXTRA_DIST = \
26 lxc-apparmor-load \
27 lxc.service.in \
28 lxc@.service.in \
29- lxc-net.service.in
30+ lxc-net.service.in \
31+ lxc-monitord.service.in
32
33 if INIT_SCRIPT_SYSTEMD
34-BUILT_SOURCES = lxc.service lxc@.service lxc-net.service
35+BUILT_SOURCES = lxc.service lxc@.service lxc-net.service lxc-monitord.service
36
37-install-systemd: lxc.service lxc@.service lxc-net.service lxc-apparmor-load
38+install-systemd: lxc.service lxc@.service lxc-net.service lxc-monitord.service lxc-apparmor-load
39 $(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
40- $(INSTALL_DATA) lxc.service lxc@.service lxc-net.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/
41+ $(INSTALL_DATA) lxc.service lxc@.service lxc-net.service lxc-monitord.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/
42
43 uninstall-systemd:
44 rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc.service
45 rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc@.service
46 rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc-net.service
47+ rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc-monitord.service
48 rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
49
50 pkglibexec_SCRIPTS = lxc-apparmor-load
51diff --git a/config/init/systemd/lxc-monitord.service.in b/config/init/systemd/lxc-monitord.service.in
52new file mode 100644
7395ab25 53index 00000000..40635168
ade16ee6
WB
54--- /dev/null
55+++ b/config/init/systemd/lxc-monitord.service.in
56@@ -0,0 +1,12 @@
57+[Unit]
58+Description=LXC Container Monitoring Daemon
59+After=syslog.service network.target
60+
61+[Service]
62+Type=simple
63+ExecStart=@LIBEXECDIR@/lxc/lxc-monitord --daemon
64+StandardOutput=syslog
65+StandardError=syslog
66+
67+[Install]
68+WantedBy=multi-user.target
ade16ee6 69diff --git a/configure.ac b/configure.ac
1513a0b5 70index 50c99836..efe56991 100644
ade16ee6
WB
71--- a/configure.ac
72+++ b/configure.ac
1513a0b5 73@@ -658,6 +658,7 @@ AC_CONFIG_FILES([
ade16ee6
WB
74 config/init/systemd/lxc.service
75 config/init/systemd/lxc@.service
76 config/init/systemd/lxc-net.service
77+ config/init/systemd/lxc-monitord.service
78 config/init/sysvinit/Makefile
79 config/init/sysvinit/lxc-containers
80 config/init/sysvinit/lxc-net
81diff --git a/lxc.spec.in b/lxc.spec.in
1513a0b5 82index 004ced26..1adbb6bd 100644
ade16ee6
WB
83--- a/lxc.spec.in
84+++ b/lxc.spec.in
1513a0b5 85@@ -235,6 +235,7 @@ fi
ade16ee6
WB
86 %{_unitdir}/lxc-net.service
87 %{_unitdir}/lxc.service
88 %{_unitdir}/lxc@.service
89+%{_unitdir}/lxc-monitord.service
90 %else
91 %{_sysconfdir}/rc.d/init.d/lxc
92 %{_sysconfdir}/rc.d/init.d/lxc-net
1513a0b5
WB
93diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
94index 99f2bdb8..2bc44dea 100644
95--- a/src/lxc/cmd/lxc_monitord.c
96+++ b/src/lxc/cmd/lxc_monitord.c
97@@ -346,17 +346,44 @@ static void lxc_monitord_sig_handler(int sig)
ade16ee6
WB
98
99 int main(int argc, char *argv[])
100 {
101- int ret, pipefd;
102+ int ret, pipefd = -1;
103 char logpath[PATH_MAX];
104 sigset_t mask;
105- char *lxcpath = argv[1];
106+ const char *lxcpath = NULL;
107 bool mainloop_opened = false;
108 bool monitord_created = false;
109+ bool persistent = false;
f39a178a 110 struct lxc_log log;
ade16ee6
WB
111
112- if (argc != 3) {
113+ if (argc > 1 && !strcmp(argv[1], "--daemon")) {
114+ persistent = true;
115+ --argc;
116+ ++argv;
117+ }
118+
119+ if (argc > 1) {
120+ lxcpath = argv[1];
121+ --argc;
122+ ++argv;
123+ } else {
124+ lxcpath = lxc_global_config_value("lxc.lxcpath");
125+ if (!lxcpath) {
126+ ERROR("Out of memory getting lxcpath");
127+ exit(EXIT_FAILURE);
128+ }
129+ }
130+
131+ if (argc > 1) {
132+ if (lxc_safe_int(argv[1], &pipefd) < 0)
133+ exit(EXIT_FAILURE);
134+ --argc;
135+ ++argv;
136+ }
137+
138+ if (argc != 1 || (persistent != (pipefd == -1))) {
139 fprintf(stderr,
140- "Usage: lxc-monitord lxcpath sync-pipe-fd\n\n"
141+ "Usage: lxc-monitord lxcpath sync-pipe-fd\n"
142+ " lxc-monitord --daemon lxcpath\n\n"
143 "NOTE: lxc-monitord is intended for use by lxc internally\n"
144 " and does not need to be run by hand\n\n");
145 exit(EXIT_FAILURE);
1513a0b5 146@@ -378,9 +405,6 @@ int main(int argc, char *argv[])
ade16ee6
WB
147 INFO("Failed to open log file %s, log will be lost.", lxcpath);
148 lxc_log_options_no_override();
149
150- if (lxc_safe_int(argv[2], &pipefd) < 0)
151- exit(EXIT_FAILURE);
152-
153 if (sigfillset(&mask) ||
154 sigdelset(&mask, SIGILL) ||
155 sigdelset(&mask, SIGSEGV) ||
1513a0b5 156@@ -412,15 +436,17 @@ int main(int argc, char *argv[])
ade16ee6
WB
157 goto on_error;
158 monitord_created = true;
159
160- /* sync with parent, we're ignoring the return from write
161- * because regardless if it works or not, the following
162- * close will sync us with the parent process. the
163- * if-empty-statement construct is to quiet the
164- * warn-unused-result warning.
165- */
166- if (write(pipefd, "S", 1))
167- ;
168- close(pipefd);
169+ if (pipefd != -1) {
170+ /* sync with parent, we're ignoring the return from write
171+ * because regardless if it works or not, the following
172+ * close will sync us with the parent process. the
173+ * if-empty-statement construct is to quiet the
174+ * warn-unused-result warning.
175+ */
176+ if (write(pipefd, "S", 1))
177+ ;
178+ close(pipefd);
179+ }
180
181 if (lxc_monitord_mainloop_add(&mon)) {
182 ERROR("Failed to add mainloop handlers.");
1513a0b5 183@@ -430,7 +456,7 @@ int main(int argc, char *argv[])
ade16ee6 184 NOTICE("lxc-monitord with pid %d is now monitoring lxcpath %s.",
1513a0b5 185 lxc_raw_getpid(), mon.lxcpath);
ade16ee6
WB
186 for (;;) {
187- ret = lxc_mainloop(&mon.descr, 1000 * 30);
188+ ret = lxc_mainloop(&mon.descr, persistent ? -1 : 1000 * 30);
f39a178a
WB
189 if (ret) {
190 ERROR("mainloop returned an error");
ade16ee6
WB
191 break;
192--
7395ab25 1932.11.0
ade16ee6 194