add -p option to write a pid file
Used by the imapfilter systemd template file I'm working on. Systemd template files use the 'imapfilter@{user}.service' pattern, making it easy to run a separate imapfilter instance per user.
- A PID file per user helps keep things organized when there are multiple imapfilter instances running under systemd.
- If 'config.lua' exists in CONFIG_SHAREDIR, but not in the user's config dir, then copy it into the user's config dir at startup as a starting point for the user to customize.
Thanks for the PR!
The pid commit might be useful, can you share an example of how it would be used with multiple instances and systemd?
I'm not sure about the config copy commit, how would it be used?
In a nutshell, these two changes provide the ability for multiple, separate instances to co-exist and be managed cleanly by systemd.
Yep, service template files are not well explained in the systemd docs. Barely mentioned, even.
Systemd has a concept called 'service templates', which can be identified as service files with an @ appended to the basename, like: [email protected]. For this type of file, you can instantiate multiple copies of a service, each running under a different username. For example, I could type:
systemctl enable [email protected] [email protected]
...to create two service units that will both be automatically started at boot. They both use the same [email protected] service template file for creating the two services (or more accurately, the symlinks that invoke it). Inside that common template, every %i will be substituted with the username that is being used to create the instance. So for one instance, %i = 'joe', for the other %i = 'mary'.
However, there are two processes with distinct PIDs, so how can I make sure that systemd kills the right process when I type systemctl stop [email protected] ?
How do I tell imapfilter where to put the PID for this specific instance? That's where the '-p' option comes in - inside the service template file, I can explicitly tell imapfilter to use a custom path that incorporates the username, e.g. /run/imapfilter/%i.pid
The point of copying the config.lua to somewhere specific to that user is so that the user has a private copy that he/she can modify to include both the credentials of their specific external mail account(s) and custom processing to apply to them. Naturally that private config.lua is unique to the user, and shouldn't be readable or modifiable by anyone else on the system.
Let me dig around to find the systemd template file I was working on, as a concrete example. Two months is a while, I've been working on other things in the meantime.
Yes, the PID functionality might be useful, we can include it.
But I would prefer to not have the "automation" for the config file. Can we revert the 2nd commit, and I'll merge the PR?
Closing this as PID file functionality was merged (with changes): 7e70efd854130fc48ad4ab4cc045e14895137f52