From a5469e5572f2fc494004d7ab1e39ae4260743301 Mon Sep 17 00:00:00 2001 From: James Ravn Date: Fri, 7 Apr 2017 11:36:31 +0100 Subject: [PATCH 1/3] Cast KILL*TIMEOUTS to int As int is required by signal.alarm. --- image/bin/my_init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image/bin/my_init b/image/bin/my_init index 354b362..8fabe6b 100755 --- a/image/bin/my_init +++ b/image/bin/my_init @@ -1,8 +1,8 @@ #!/usr/bin/python3 -u import os, os.path, sys, stat, signal, errno, argparse, time, json, re -KILL_PROCESS_TIMEOUT = os.environ.get('KILL_PROCESS_TIMEOUT', 5) -KILL_ALL_PROCESSES_TIMEOUT = os.environ.get('KILL_ALL_PROCESSES_TIMEOUT', 5) +KILL_PROCESS_TIMEOUT = int(os.environ.get('KILL_PROCESS_TIMEOUT', 5)) +KILL_ALL_PROCESSES_TIMEOUT = int(os.environ.get('KILL_ALL_PROCESSES_TIMEOUT', 5)) LOG_LEVEL_ERROR = 1 LOG_LEVEL_WARN = 1 From f706ea8d920a4ec1f66563d5f12dba979593f946 Mon Sep 17 00:00:00 2001 From: James Ravn Date: Fri, 7 Apr 2017 11:44:20 +0100 Subject: [PATCH 2/3] Add shutdown details to README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 7aa1cb4..b8b4be2 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,22 @@ In `Dockerfile`: RUN chmod +x /etc/my_init.d/logtime.sh + +#### Shutting down your process + +`/sbin/my_init` handles termination of children processes at shutdown. When it receives a SIGTERM +it will pass the signal onto the child process for correct shutdown. If your process is started with +a shell script, make sure you `exec` the actual process, otherwise the shell will receive the signal +and not your process. + +`/sbin/my_init` will terminate processes after a 5 second timeout. This can be adjusted by setting +environment variables: + + # Give children processes 5 minutes to timeout + ENV KILL_PROCESS_TIMEOUT=300 + # Give all other processes (such as those which have been forked) 5 minutes to timeout + ENV KILL_ALL_PROCESSES_TIMEOUT=300 + ### Environment variables If you use `/sbin/my_init` as the main container command, then any environment variables set with `docker run --env` or with the `ENV` command in the Dockerfile, will be picked up by `my_init`. These variables will also be passed to all child processes, including `/etc/my_init.d` startup scripts, Runit and Runit-managed services. There are however a few caveats you should be aware of: From 93477b34cce62104c8e8d8f0ff6d1383b40c9c09 Mon Sep 17 00:00:00 2001 From: James Ravn Date: Fri, 7 Apr 2017 11:45:55 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b8b4be2..200b715 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ In `Dockerfile`: #### Shutting down your process `/sbin/my_init` handles termination of children processes at shutdown. When it receives a SIGTERM -it will pass the signal onto the child process for correct shutdown. If your process is started with +it will pass the signal onto the child processes for correct shutdown. If your process is started with a shell script, make sure you `exec` the actual process, otherwise the shell will receive the signal and not your process. @@ -214,8 +214,8 @@ environment variables: # Give children processes 5 minutes to timeout ENV KILL_PROCESS_TIMEOUT=300 - # Give all other processes (such as those which have been forked) 5 minutes to timeout - ENV KILL_ALL_PROCESSES_TIMEOUT=300 + # Give all other processes (such as those which have been forked) 5 minutes to timeout + ENV KILL_ALL_PROCESSES_TIMEOUT=300 ### Environment variables