]> git.proxmox.com Git - lxc.git/blob - debian/patches/pve/0007-PVE-Up-possibility-to-run-lxc-monitord-as-a-regular-.patch
bump version to 3.0.1+pve1-1
[lxc.git] / debian / patches / pve / 0007-PVE-Up-possibility-to-run-lxc-monitord-as-a-regular-.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] PVE: [Up] 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 .gitignore | 1 +
14 config/init/systemd/Makefile.am | 10 +++--
15 config/init/systemd/lxc-monitord.service.in | 12 ++++++
16 configure.ac | 1 +
17 lxc.spec.in | 1 +
18 src/lxc/cmd/lxc_monitord.c | 60 +++++++++++++++++++++--------
19 6 files changed, 64 insertions(+), 21 deletions(-)
20 create mode 100644 config/init/systemd/lxc-monitord.service.in
21
22 diff --git a/.gitignore b/.gitignore
23 index 0d266c20..b2a4b020 100644
24 --- a/.gitignore
25 +++ b/.gitignore
26 @@ -115,6 +115,7 @@ config/bash/lxc
27 config/init/common/lxc-containers
28 config/init/common/lxc-net
29 config/init/systemd/lxc-autostart-helper
30 +config/init/systemd/lxc-monitord.service
31 config/init/systemd/lxc-net.service
32 config/init/systemd/lxc.service
33 config/init/systemd/lxc@.service
34 diff --git a/config/init/systemd/Makefile.am b/config/init/systemd/Makefile.am
35 index c448850d..4a4fde5e 100644
36 --- a/config/init/systemd/Makefile.am
37 +++ b/config/init/systemd/Makefile.am
38 @@ -2,19 +2,21 @@ EXTRA_DIST = \
39 lxc-apparmor-load \
40 lxc.service.in \
41 lxc@.service.in \
42 - lxc-net.service.in
43 + lxc-net.service.in \
44 + lxc-monitord.service.in
45
46 if INIT_SCRIPT_SYSTEMD
47 -BUILT_SOURCES = lxc.service lxc@.service lxc-net.service
48 +BUILT_SOURCES = lxc.service lxc@.service lxc-net.service lxc-monitord.service
49
50 -install-systemd: lxc.service lxc@.service lxc-net.service lxc-apparmor-load
51 +install-systemd: lxc.service lxc@.service lxc-net.service lxc-monitord.service lxc-apparmor-load
52 $(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
53 - $(INSTALL_DATA) lxc.service lxc@.service lxc-net.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/
54 + $(INSTALL_DATA) lxc.service lxc@.service lxc-net.service lxc-monitord.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/
55
56 uninstall-systemd:
57 rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc.service
58 rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc@.service
59 rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc-net.service
60 + rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc-monitord.service
61 rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
62
63 pkglibexec_SCRIPTS = lxc-apparmor-load
64 diff --git a/config/init/systemd/lxc-monitord.service.in b/config/init/systemd/lxc-monitord.service.in
65 new file mode 100644
66 index 00000000..40635168
67 --- /dev/null
68 +++ b/config/init/systemd/lxc-monitord.service.in
69 @@ -0,0 +1,12 @@
70 +[Unit]
71 +Description=LXC Container Monitoring Daemon
72 +After=syslog.service network.target
73 +
74 +[Service]
75 +Type=simple
76 +ExecStart=@LIBEXECDIR@/lxc/lxc-monitord --daemon
77 +StandardOutput=syslog
78 +StandardError=syslog
79 +
80 +[Install]
81 +WantedBy=multi-user.target
82 diff --git a/configure.ac b/configure.ac
83 index 59a0d410..ea312bf3 100644
84 --- a/configure.ac
85 +++ b/configure.ac
86 @@ -674,6 +674,7 @@ AC_CONFIG_FILES([
87 config/init/systemd/lxc.service
88 config/init/systemd/lxc@.service
89 config/init/systemd/lxc-net.service
90 + config/init/systemd/lxc-monitord.service
91 config/init/sysvinit/Makefile
92 config/init/sysvinit/lxc-containers
93 config/init/sysvinit/lxc-net
94 diff --git a/lxc.spec.in b/lxc.spec.in
95 index 87978feb..fcf307fa 100644
96 --- a/lxc.spec.in
97 +++ b/lxc.spec.in
98 @@ -235,6 +235,7 @@ fi
99 %{_unitdir}/lxc-net.service
100 %{_unitdir}/lxc.service
101 %{_unitdir}/lxc@.service
102 +%{_unitdir}/lxc-monitord.service
103 %else
104 %{_sysconfdir}/rc.d/init.d/lxc
105 %{_sysconfdir}/rc.d/init.d/lxc-net
106 diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
107 index 38eee0a9..ffa6deca 100644
108 --- a/src/lxc/cmd/lxc_monitord.c
109 +++ b/src/lxc/cmd/lxc_monitord.c
110 @@ -354,17 +354,44 @@ static void lxc_monitord_sig_handler(int sig)
111
112 int main(int argc, char *argv[])
113 {
114 - int ret, pipefd;
115 + int ret, pipefd = -1;
116 char logpath[PATH_MAX];
117 sigset_t mask;
118 - char *lxcpath = argv[1];
119 + const char *lxcpath = NULL;
120 bool mainloop_opened = false;
121 bool monitord_created = false;
122 + bool persistent = false;
123 struct lxc_log log;
124
125 - if (argc != 3) {
126 + if (argc > 1 && !strcmp(argv[1], "--daemon")) {
127 + persistent = true;
128 + --argc;
129 + ++argv;
130 + }
131 +
132 + if (argc > 1) {
133 + lxcpath = argv[1];
134 + --argc;
135 + ++argv;
136 + } else {
137 + lxcpath = lxc_global_config_value("lxc.lxcpath");
138 + if (!lxcpath) {
139 + ERROR("Out of memory getting lxcpath");
140 + exit(EXIT_FAILURE);
141 + }
142 + }
143 +
144 + if (argc > 1) {
145 + if (lxc_safe_int(argv[1], &pipefd) < 0)
146 + exit(EXIT_FAILURE);
147 + --argc;
148 + ++argv;
149 + }
150 +
151 + if (argc != 1 || (persistent != (pipefd == -1))) {
152 fprintf(stderr,
153 - "Usage: lxc-monitord lxcpath sync-pipe-fd\n\n"
154 + "Usage: lxc-monitord lxcpath sync-pipe-fd\n"
155 + " lxc-monitord --daemon lxcpath\n\n"
156 "NOTE: lxc-monitord is intended for use by lxc internally\n"
157 " and does not need to be run by hand\n\n");
158 exit(EXIT_FAILURE);
159 @@ -387,9 +414,6 @@ int main(int argc, char *argv[])
160 INFO("Failed to open log file %s, log will be lost", lxcpath);
161 lxc_log_options_no_override();
162
163 - if (lxc_safe_int(argv[2], &pipefd) < 0)
164 - exit(EXIT_FAILURE);
165 -
166 if (sigfillset(&mask) ||
167 sigdelset(&mask, SIGILL) ||
168 sigdelset(&mask, SIGSEGV) ||
169 @@ -422,15 +446,17 @@ int main(int argc, char *argv[])
170 goto on_error;
171 monitord_created = true;
172
173 - /* sync with parent, we're ignoring the return from write
174 - * because regardless if it works or not, the following
175 - * close will sync us with the parent process. the
176 - * if-empty-statement construct is to quiet the
177 - * warn-unused-result warning.
178 - */
179 - if (write(pipefd, "S", 1))
180 - ;
181 - close(pipefd);
182 + if (pipefd != -1) {
183 + /* sync with parent, we're ignoring the return from write
184 + * because regardless if it works or not, the following
185 + * close will sync us with the parent process. the
186 + * if-empty-statement construct is to quiet the
187 + * warn-unused-result warning.
188 + */
189 + if (write(pipefd, "S", 1))
190 + ;
191 + close(pipefd);
192 + }
193
194 if (lxc_monitord_mainloop_add(&mon)) {
195 ERROR("Failed to add mainloop handlers");
196 @@ -441,7 +467,7 @@ int main(int argc, char *argv[])
197 lxc_raw_getpid(), mon.lxcpath);
198
199 for (;;) {
200 - ret = lxc_mainloop(&mon.descr, 1000 * 30);
201 + ret = lxc_mainloop(&mon.descr, persistent ? -1 : 1000 * 30);
202 if (ret) {
203 ERROR("mainloop returned an error");
204 break;
205 --
206 2.11.0
207