Re: The saga of wrestling with systemd (was) Re: logrotate options?

Peter Pentchev <[email protected]> Sun, 23 Jan 2022 21:11:19 +0200
Newsgroups gmane.mail.fetchmail.user
Message-ID <Ye2oV6WsM4xnM/[email protected]>
On Sun, Jan 23, 2022 at 01:35:52PM -0500, Joe Acquisto-j4 wrote:
> > On Thu, Jan 20, 2022 at 11:34:26AM +0200, Peter Pentchev wrote:
> > [snip]
> >> directory if necessary). Something like this works for me (note that
> >> I do not have a logfile directive in my fetchmail config file, so
> >> it will send its output to the standard output stream by default):
> >> 
> >>   [roam@straylight ~]$ cat ~/.config/systemd/user/fetchmail.service 
> >>   [Unit]
> >>   Description=Run fetchmail in daemon mode.
> >>   Documentation=man:fetchmail(1)
> >>   After=network-online.target
> >>   Wants=network-online.target
> >>   
> >>   [Service]
> >>   Type=simple
> >>   ExecStartPre=-fetchmail -ve200
> >>   ExecStart=fetchmail -ve25 -Nd120
> >>   ExecStop=fetchmail --quit
> >>   KillMode=process
> > 
> > ...and of course, I forgot two lines that are kind of important:
> > 
> > [Install]
> > WantedBy=default.target
> > 
> > G'luck,
> > Peter
> > 
> > -- 
> 
> Thanks to all.
> 
> This is how I achieved success (getting Fetchmail to start and stop in systemd world that is):

It's great that you got it running! Congratulations!
(yes, I know that fighting with systemd service and unit definition
 files for the first time... or sometimes even for the fifteenth time...
 may be, um, exhausting. There is some logic to them, but it takes
 a while to get used to it)

If I may make a couple of comments to what you showed below...

> [Unit]
> Description=remote-mail retrieval utility runin daaemon mode

A couple of typos there ("runin", "daaemon"), but I guess they won't
affect the operation of the service :)

> After=network.target
> Wants=network.target
> 
> [Service]
> Type=simple
> EnvironmentFile=/root/.fetchmailrc

Hm. This one looks a bit weird to me. I don't think that your
.fetchmailrc file is indeed in the "variable=value" format that systemd
would expect for a file to read environment variables from. Also,
I don't think that your .fetchmailrc file even contains environment
variable settings...

Does it work if you remove this line? If so, then I think you may want
to remove it.

> #User=fetchmail
> #ExecStart=/usr/lib/fetchmail-systemd-exec
> ExecStart=/usr/local/bin/fetchmail -v
> #-Nd120

This will only work if your .fetchmailrc file already contains
a "set daemon ..." line and also a "nodetach" line. Otherwise, systemd
will be kind of surprised when fetchmail creates a separate daemon
process in the background and the fetchmail process that systemd started
decides to exit since it has done its part of the work (started
the daemon process in the background). If your .fetchmailrc file has
the "set daemon" and "nodetach" lines, then yeah, this will work.

I personally prefer to keep those options out of the configuration file
so that I may invoke fetchmail by hand sometimes to fetch a couple of
messages and exit, but that's me. If you decide to remove them from
your configuration file, then you'd have to pass them here (as I did
with the -N and -d120 command-line parameters).

> ExecStop=/usr/local/bin/fetchmail -q
> KillMode=process
> #RestartSec=1
> 
> [Install]
> WantedBy=multi-user.target
> ---------------------------------------------
> 
> Thanks again to all.

Glad to have been of assistance! Of course, feel free to come back with
any further questions or issues that you may have with running fetchmail
under systemd (in case somebody objects to discussing such topics on
this list, personal e-mail is also fine).

G'luck,
Peter

-- 
Peter Pentchev  [email protected] [email protected] [email protected]
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

_______________________________________________
Fetchmail-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fetchmail-users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAmHtqFEACgkQZR7vsCUn
3xP2lw/7B7TeFOaPb/CoZjNQ73X/8NhJ06al8qGljxhWH6mvdIArS21A50Y4rqd/
ZnH3/6UEAUGLiscaT7Atgu7B/8pZ6xzBRBvd82JF264hMJxM7o2lofqxgKr7XopM
UKnJAd7PMadmV6onji1jkIbr8NrTHShddcqf7p2QVM1ynE4xoMxJU4YgICppMReK
lYGG0SJ4hClIGcAkbC0t358MyS205wg1CKVi1N60E7v1WgZn7g2KrZnKb0tAnz+C
CHCsECLvuGx61+9kts2Sif7S2I2IghBCrRBDLRXtGJMgJ5o7DQAs+BCkGtGyi/RA
SOrmUN6TqCSaRqR9H2dfGDMo9D4FyyVBJMQzIxLfHmvblYvhgFiHuQqxaPOrGaUR
DGExn6gaMe0xc/VDO6Y8zc0WXTvUQzON0k3zvHGK6IXkgO1eb0Oa+EnX2AFO++ju
mNCdvUjfefhk7/a97fRL1NHSEl3pkggRzJ6oU/kyDYwQ7fWgkNdHPdJzW/dsWJUL
yTKnDoYjnGJPfDW36j6dIKvSIysI6W6wmoKXJGEu4YtkNondEr8ftxjj+LCoqKrG
aAHcRWFr0sxKryNdPaurJZwN+Pf9iBA4CZtE0PzaFcj64g9F6zG81oBdZ3Ez7PkM
da+C/6UFdDU0BoQ88Uo+w4L42gJjIABq3+aqM6lfGVD1puAI8pk=
=ugco
-----END PGP SIGNATURE-----