systemd problem
Hi I have written a systemd service for imapfilter. When I start this imapfilter also runs once. However, the process does not stay active and continues to check the emails at the specified interval. Status of the service dead. However, when I call imapfilter in the shell, the constant check in the interval works and the process remains.
Can anyone give me a hint what I am doing wrong?
I am using imapfilter version 2.6.12.
Do you mean that when running inside systemd, the interval for sleeping is not respected, and instead it does a continuous loop?
And are the 2 configs (when run inside systemd and from the shell) exactly the same?
Or that it dies when running inside systemd, and thus continuously restarted by systemd?
Hi a little more details:
at the end of my config.lua:
become_daemon(600, <function>)
my systemd.service:
[Unit]
Description=ImapFilter Client Daemon
Documentation=man:imapfilter
# Start after network and specified mounts are available.
After=network-online.target
[Service]
Type=simple
User=<user>
Group=<user>
ExecStart=/usr/bin/imapfilter -c ./.imapfilter/config.lua -l /var/log/imapfilter/imapfilter.log
WorkingDirectory=/home/<user>/
Restart=on-failure
StartLimitIntervalSec=3
# Time to wait before forcefully stopped.
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target
when I start the service:
● imapfilter.service - ImapFilter Client Daemon
Loaded: loaded (/etc/systemd/system/imapfilter.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2021-12-12 16:59:28 CET; 1s ago
Docs: man:imapfilter
Process: 6181 ExecStart=/usr/bin/imapfilter -c ./.imapfilter/config.lua -l /var/log/imapfilter/imapfilter.log (code=exited, status=0/SUCCESS)
Main PID: 6181 (code=exited, status=0/SUCCESS)
Dez 12 16:59:26 device systemd[1]: Started ImapFilter Client Daemon.
Dez 12 16:59:27 device imapfilter[6181]: <output>
Dez 12 16:59:28 device systemd[1]: imapfilter.service: Succeeded.
So it run once successfully but seems to ignore the become_daemon functionality. When I ssh to the shell and use imapfilter on user, the process keeps running and the demon works every 10 minutes.
What am I doing wrong?
I tried this, and indeed it seems that imapfilter doesn't run correctly as a systemd service using become_daemon(). I suspect that it might be because imapfilter becomes daemon by use of the fork() function.
Since systemd handles running services as daemons itself, you can structure your config like this:
function loop()
-- your commands
end
-- become_daemon(600, loop)
while true
loop()
sleep(600)
end
So the loop function is repeated with the same interval, but imapfilter runs as a normal process, and not as a daemon.
I have tried this systemd, and it seems to work as expected.