Re: Using getmail with IMAP IDLE in Docker

"Charles Cazabon ([email protected])" <[email protected]> Sun, 18 Dec 2022 09:38:35 -0600
Newsgroups gmane.mail.getmail.user
Message-ID <[email protected]>
Kia Niskavaara <[email protected]> wrote:
> I'm currently running getmail with IMAP IDLE as a systemd service.
> 
> I want to move my project to a Docker container. But it seems systemd is
> not recommended with Docker.

In general, you don't want an intermediary process in between the host system
and the service process running in the container.  Such a config can be made
to work, and can be necessary if you're running multiple processes inside a
container or under some other conditions, but otherwise it doesn't provide
many benefits and can cause problems.

> What I need is getmail to restart if it stops waiting. For example if there
> is a timeout or a problem with the Internet connection.

You can do this using a shell script as your entrypoint.  Something like:

  #!/bin/bash

  trap exit SIGTERM

  while true ; do
    getmail [options]
    sleep 10
  done

That's assuming you're using the defaults signals config for your container.
The above, when receiving the default shut-down-container signal of SIGTERM,
causes the shell to exit when getmail completes - but if it's polling with
IDLE, that may not be fast enough to avoid SIGKILL.  getmail should still
handle that about as gracefully as it can.

The sleep keeps it from spinning too fast if you're got a config error or
similar.

Charles
-- 
-----------------------------------------------------------------------
Charles Cazabon
GPL'ed software available at:               http://pyropus.ca/software/
-----------------------------------------------------------------------