On Fri, Feb 26, 2021 at 11:21 PM boardbill_unpretended--- via Podman <
podman(a)lists.podman.io> wrote:
Thanks for the information! I've had a look at `man oci-hooks`
and its way
over my league with many terms I don't understand.
Regarding the clean up script I was asking about, I did some searching per
your suggestion to wait for the SIGTERM signal, and the closest tool I can
find so far is the `trap` command which seems to do something *if* a given
signal is given.
My best guess right now is:
1. Create the clean up script, let's call it `my-cleaner.sh`. This script
has at least one line with the `trap` command waiting for the SIGTERM
signal. (is there a way to tell `trap` to wait for SIGTERM *or* SIGKILL???)
SIGKILL is special since you (i.e., a user-mode process) can't really
handle this signal. When a process receives it, the kernel will go ahead
and kill/exit it.
2. In the Dockerfile add a `COPY my-cleaner.sh /my-cleaner.sh` line
so
that the script is put into the container during `podman build`.
3. As you know, the container images I'm working with already has `CMD
/init` (BTW, what does `/init` do anyway????), so I guess I'll have to
start the script by changing the `CMD` line this way:
That depends on the individual container image. In most cases, `/init`/ is
a symlink to `systemd`. When a container is started with either of the two
as the command/entrypoint, Podman will automatically do the setup to allow
for running systemd inside the container.
```
CMD /my-cleaner.sh & \
&& /init
```
4. Cross fingers and hope that when I run `podman stop` on the container,
the resulting SIGTERM will be seen by the `trap` command in `my-cleaner.sh`
and take the clean up steps. (by the way, how can I check that the clean up
actually happened? is there a canonical way to document if the desired
actions were taken?)
Does the above look right?
I suggest having a close look whether `/init` is needed in your container.
As mentioned above, Podman will setup systemd to run inside the container
but that behaviour would now change given the CMD is altered.
Kind regards,
Valentin
_____________________________________________
Podman mailing list -- podman(a)lists.podman.io
To unsubscribe send an email to podman-leave(a)lists.podman.io