]> git.proxmox.com Git - lxc.git/blob - 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
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Mon, 20 Nov 2017 10:49:41 +0100
4 Subject: [PATCH] possibility to run lxc-monitord as a regular daemon
5
6 lxc-monitord instances are spawned on demand and, if this
7 happens from a service, the daemon is considered part of
8 it by systemd, as it is running in the same cgroups. This
9 can be avoided by leaving it running permanently.
10
11 Signed-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 ++++++
15 configure.ac | 1 +
16 lxc.spec.in | 1 +
17 src/lxc/cmd/lxc_monitord.c | 60 +++++++++++++++++++++--------
18 5 files changed, 63 insertions(+), 21 deletions(-)
19 create mode 100644 config/init/systemd/lxc-monitord.service.in
20
21 diff --git a/config/init/systemd/Makefile.am b/config/init/systemd/Makefile.am
22 index c448850d..4a4fde5e 100644
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
51 diff --git a/config/init/systemd/lxc-monitord.service.in b/config/init/systemd/lxc-monitord.service.in
52 new file mode 100644
53 index 00000000..40635168
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
69 diff --git a/configure.ac b/configure.ac
70 index 50c99836..efe56991 100644
71 --- a/configure.ac
72 +++ b/configure.ac
73 @@ -658,6 +658,7 @@ AC_CONFIG_FILES([
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
81 diff --git a/lxc.spec.in b/lxc.spec.in
82 index 004ced26..1adbb6bd 100644
83 --- a/lxc.spec.in
84 +++ b/lxc.spec.in
85 @@ -235,6 +235,7 @@ fi
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
93 diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
94 index 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)
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;
110 struct lxc_log log;
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);
146 @@ -378,9 +405,6 @@ int main(int argc, char *argv[])
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) ||
156 @@ -412,15 +436,17 @@ int main(int argc, char *argv[])
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.");
183 @@ -430,7 +456,7 @@ int main(int argc, char *argv[])
184 NOTICE("lxc-monitord with pid %d is now monitoring lxcpath %s.",
185 lxc_raw_getpid(), mon.lxcpath);
186 for (;;) {
187 - ret = lxc_mainloop(&mon.descr, 1000 * 30);
188 + ret = lxc_mainloop(&mon.descr, persistent ? -1 : 1000 * 30);
189 if (ret) {
190 ERROR("mainloop returned an error");
191 break;
192 --
193 2.11.0
194