]>
Commit | Line | Data |
---|---|---|
1513a0b5 | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
ade16ee6 | 2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
bc7e56ac | 3 | Date: Mon, 20 Nov 2017 10:49:41 +0100 |
2d8021b3 | 4 | Subject: [PATCH] PVE: [Up] possibility to run lxc-monitord as a regular daemon |
ade16ee6 | 5 | |
bc7e56ac WB |
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. | |
ade16ee6 WB |
10 | |
11 | Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> | |
12 | --- | |
2d8021b3 | 13 | .gitignore | 1 + |
8a25e884 WB |
14 | config/init/systemd/Makefile.am | 10 ++-- |
15 | config/init/systemd/lxc-monitord.service.in | 12 +++++ | |
ade16ee6 WB |
16 | configure.ac | 1 + |
17 | lxc.spec.in | 1 + | |
8a25e884 | 18 | src/lxc/cmd/lxc_monitord.c | 60 +++++++++++++++------ |
2d8021b3 | 19 | 6 files changed, 64 insertions(+), 21 deletions(-) |
ade16ee6 WB |
20 | create mode 100644 config/init/systemd/lxc-monitord.service.in |
21 | ||
2d8021b3 | 22 | diff --git a/.gitignore b/.gitignore |
8a25e884 | 23 | index 45377714c..69e6e7ffe 100644 |
2d8021b3 WB |
24 | --- a/.gitignore |
25 | +++ b/.gitignore | |
834bb4d7 | 26 | @@ -116,6 +116,7 @@ config/bash/lxc |
2d8021b3 WB |
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 | |
ade16ee6 | 34 | diff --git a/config/init/systemd/Makefile.am b/config/init/systemd/Makefile.am |
8a25e884 | 35 | index c448850d1..4a4fde5e7 100644 |
ade16ee6 WB |
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 | |
8a25e884 | 66 | index 000000000..406351688 |
ade16ee6 WB |
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 | |
ade16ee6 | 82 | diff --git a/configure.ac b/configure.ac |
8a25e884 | 83 | index 9a6ba83c2..9f3b8fb3c 100644 |
ade16ee6 WB |
84 | --- a/configure.ac |
85 | +++ b/configure.ac | |
834bb4d7 | 86 | @@ -747,6 +747,7 @@ AC_CONFIG_FILES([ |
ade16ee6 WB |
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 | |
8a25e884 | 95 | index 7fcd811ff..59597f469 100644 |
ade16ee6 WB |
96 | --- a/lxc.spec.in |
97 | +++ b/lxc.spec.in | |
834bb4d7 | 98 | @@ -247,6 +247,7 @@ fi |
ade16ee6 WB |
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 | |
1513a0b5 | 106 | diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c |
8a25e884 | 107 | index 3b931b361..d3cc35978 100644 |
1513a0b5 WB |
108 | --- a/src/lxc/cmd/lxc_monitord.c |
109 | +++ b/src/lxc/cmd/lxc_monitord.c | |
834bb4d7 | 110 | @@ -359,17 +359,44 @@ static void lxc_monitord_sig_handler(int sig) |
ade16ee6 WB |
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; | |
f39a178a | 123 | struct lxc_log log; |
ade16ee6 WB |
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); | |
834bb4d7 | 159 | @@ -392,9 +419,6 @@ int main(int argc, char *argv[]) |
2d8021b3 | 160 | INFO("Failed to open log file %s, log will be lost", lxcpath); |
ade16ee6 WB |
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) || | |
834bb4d7 | 169 | @@ -427,15 +451,17 @@ int main(int argc, char *argv[]) |
ade16ee6 WB |
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 | - */ | |
f46e8fbf | 179 | - if (lxc_write_nointr(pipefd, "S", 1)) |
ade16ee6 WB |
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 | + */ | |
f46e8fbf | 189 | + if (lxc_write_nointr(pipefd, "S", 1)) |
ade16ee6 WB |
190 | + ; |
191 | + close(pipefd); | |
192 | + } | |
193 | ||
834bb4d7 | 194 | if (lxc_monitord_mainloop_add(&monitor)) { |
2d8021b3 | 195 | ERROR("Failed to add mainloop handlers"); |
834bb4d7 WB |
196 | @@ -446,7 +472,7 @@ int main(int argc, char *argv[]) |
197 | lxc_raw_getpid(), monitor.lxcpath); | |
2d8021b3 | 198 | |
ade16ee6 | 199 | for (;;) { |
834bb4d7 WB |
200 | - ret = lxc_mainloop(&monitor.descr, 1000 * 30); |
201 | + ret = lxc_mainloop(&monitor.descr, persistent ? -1 : 1000 * 30); | |
f39a178a WB |
202 | if (ret) { |
203 | ERROR("mainloop returned an error"); | |
ade16ee6 WB |
204 | break; |
205 | -- | |
8a25e884 | 206 | 2.20.1 |
ade16ee6 | 207 |