From: Ammar Faizi <[email protected]>
To: GNU/Weeb Mailing List <[email protected]>
Cc: Muhamad Hazmi Alfarizqi <[email protected]>,
Muhamad Hazmi Alfarizqi <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>,
Arthur Lapz <[email protected]>,
Ammar Faizi <[email protected]>
Subject: [PATCH a001 v1 6/7] Create a simple init program
Date: Wed, 29 Mar 2023 14:59:31 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Using "tail -f /dev/null" as the init program is wrong because it
doesn't handle the SIGCHLD signal, resulting many zombie processes like
these:
Zs 08:30 0:00 [master] <defunct>
Z 08:30 0:00 [qmgr] <defunct>
Zs 08:30 0:00 [dovecot] <defunct>
Z 08:30 0:00 [anvil] <defunct>
Z 08:30 0:00 [log] <defunct>
Z 08:30 0:00 [config] <defunct>
Z 08:30 0:00 [tlsmgr] <defunct>
Z 08:30 0:00 [stats] <defunct>
Z 08:33 0:00 [imap-login] <defunct>
Z 08:33 0:00 [imap] <defunct>
Z 08:33 0:00 [imap-login] <defunct>
Z 08:33 0:00 [imap] <defunct>
Z 08:39 0:01 [imap-login] <defunct>
Z 08:39 0:03 [imap] <defunct>
Z 11:50 0:00 [pickup] <defunct>
Zs 12:31 0:00 [dovecot] <defunct>
Z 12:31 0:00 [anvil] <defunct>
Z 12:31 0:00 [log] <defunct>
Z 12:31 0:00 [config] <defunct>
Z 12:31 0:00 [imap-login] <defunct>
Z 12:31 0:00 [stats] <defunct>
Z 12:31 0:00 [imap] <defunct>
Create a simple init program that ignores SIGCHLD so that the zombie
processes are gone.
Signed-off-by: Ammar Faizi <[email protected]>
---
.gitignore | 1 +
Dockerfile | 5 +++--
init.c | 15 +++++++++++++++
install.sh | 1 +
4 files changed, 20 insertions(+), 2 deletions(-)
create mode 100644 init.c
diff --git a/.gitignore b/.gitignore
index 50cf6dedd170238f..bceb5ce4098add1a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/config
+/init
diff --git a/Dockerfile b/Dockerfile
index 7bc54e0afb43d8ce..3492aa0408b7b5a3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -41,10 +41,11 @@ RUN apt update \
postfix-policyd-spf-python dovecot-core dovecot-imapd \
dovecot-lmtpd dovecot-mysql opendkim opendmarc
+COPY init /bin/gwinitd
COPY mailserver /root/mailserver
RUN --mount=type=secret,required=true,id=config /root/mailserver/setup.sh
-
+RUN chmod -v +x /bin/gwinitd
COPY docker-entrypoint.sh /
ENTRYPOINT [ "/docker-entrypoint.sh" ]
-CMD [ "tail", "-f", "/dev/null" ]
+CMD [ "/bin/gwinitd" ]
diff --git a/init.c b/init.c
new file mode 100644
index 0000000000000000..adc67275dd3414c0
--- /dev/null
+++ b/init.c
@@ -0,0 +1,15 @@
+#include <signal.h>
+#include <unistd.h>
+
+int main(void)
+{
+ struct sigaction a = { .sa_handler = SIG_IGN };
+
+ if (sigaction(SIGCHLD, &a, NULL) < 0)
+ return 1;
+
+ while (1)
+ sleep(1000000);
+
+ return 0;
+}
diff --git a/install.sh b/install.sh
index 652861d263a698dc..dea60516f2e27512 100755
--- a/install.sh
+++ b/install.sh
@@ -1,4 +1,5 @@
#!/bin/bash
set -e;
+gcc -Wall -Wextra -Os init.c -o init;
DOCKER_BUILDKIT=1 docker build --secret id=config -t server-a001 .;
--
Ammar Faizi
next prev parent reply other threads:[~2023-03-29 8:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-29 7:59 [PATCH a001 v1 0/7] server-a001 updates Ammar Faizi
2023-03-29 7:59 ` [PATCH a001 v1 1/7] Use nginx from Ubuntu for simplicity Ammar Faizi
2023-03-29 7:59 ` [PATCH a001 v1 2/7] start.sh: Add vmail storage directory Ammar Faizi
2023-03-29 7:59 ` [PATCH a001 v1 3/7] Dockerfile: Upgrade the Ubuntu version to 22.04 (jammy) Ammar Faizi
2023-03-29 7:59 ` [PATCH a001 v1 4/7] Dockerfile: Set the default main user to "ubuntu" Ammar Faizi
2023-03-29 7:59 ` [PATCH a001 v1 5/7] Add an installer script Ammar Faizi
2023-03-29 7:59 ` Ammar Faizi [this message]
2023-03-29 7:59 ` [PATCH a001 v1 7/7] docker-entrypoint: Properly set directory ownership and mode Ammar Faizi
2023-03-29 19:36 ` [PATCH a001 v1 0/7] server-a001 updates Alviro Iskandar Setiawan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox