It would be nice to provide a systemd timer file for daily schedule of logwatch.
Arch Linux, for example, currently symlinks /usr/share/logwatch/scripts/logwatch.pl into /etc/cron.daily/ - which is simple, but obviously requires cron.
See https://bugs.archlinux.org/task/56357
The service and timer declarations are under the
schedulerdirectory. Theinstall_logwatch.shscript has a--systemdoption to install them, rather than the cron file.oh, sry, didn't know (I should have checked more thoroughly, first ...). This issue can be closed then. Thanks
Current logwatch .service file is strange and purpose less.
By default it sends output to systemd which in turn will send output back to journal.
It would be strange that logwatch runs everyday .. parses log files and sends the report back to logs!! (journal) instead of sending an email to root (the cron default behaviour)
I would suggest replacing
ExecStart=/usr/sbin/logwatch
with
ExecStart=/usr/sbin/logwatch --output mail
Then functionality will become same as that of cron.
Please consider
Last edit: Amish 2019-09-20
I disagree. You configure that with
Output = mailinside/etc/logwatch/conf/logwatch.conf. No reason to send mail (to whom?) by default. The user / administartor should configure the email address where the logwatch report should be send. Leaving stdout as the default is ok. Forcing the user to use mail output is wrong. And what if someone wantsOutput = file... Also what if someone actually wants to have logwatch report show in journal. You configure the behavior inlogwatch.confnot inside systemd service.Last edit: Kamil Cukrowski 2019-09-26
Putting
Output = mailin default as logwatch.conf means that even when I run it on command line, it sends a mail, which may not always be desired.systemd.timer is meant to be a replacement for cron. (That is the purpose of this feature request). By default cron sends email to root. So we can expect similar functionality from logwatch systemd.timer. And logwatch.conf by default uses
MailTo = root. See/usr/share/logwatch/default.conf/logwatch.confThat's not very likely to be a general choice. Anyone who wants the log report go back to journal logs can create a systemd.service overide file and not the other way around.
I would instead say that forcing user to send logs to journal is wrong!
Any software should pick defaults that would be most common used. Since by default cron file sent an email, we can expect same from systemd.service file.
I see the discrepancy between cron and systemd timer as the source. But I think, changing the systemd timer is wrong, because: Command line options superseed config file options.
Thus, the systemd timer should not give any command line options (else you must edit the systemd timer file to change logwatch's default behaviour - editing /etc/logwatch/conf/logwatch.conf will not suffice). OTOH changing the cron file to not force mail (while breaking running systems) is ok IMHO, because you can always configure it via logwatch.conf (which should probably be done in the file that gets shipped by default).
I find the argument "I cannot see log output on stdout" invalid, because on command line you can do whatever you want - this is the realm of command line options: Use them to get the desired output format and whatnot.
Just imagine people, who like html formatted output via mail, but not on stdout - should they overwrite the systemd timer or simly change a line in logwatch.conf (which they may need to edit anyways to set a useful recipient, mail program, etc).
Last edit: Erich Eckner 2019-09-26
There is another option which satisfies all cases by modifying systemd service file (
logwatch.service) as follows.The file,
/etc/logwatch/systemd.conf, may or may not exist. A minus (-) sign infront of filename makes sure that it is not an error if file does not exist.Anyone who wants a different option can create that file (
/etc/logwatch/systemd.conf) and put something like this:EXEC_OPTIONS="--output mail"This way they dont need to change defaults of logwatch.conf but can have separate defaults for systemd.timer (automatic daily runs).
Note that addition of
EnvironmentFiledoes not change the current behaviour that Kamil and Erich expects, so I expect that it is fine with them.Last edit: Amish 2019-09-26
Thanks for the discussion, and the proposed solution. I implemented with some changes:
LOGWATCH_OPTIONS. While not dictated by systemd, it seems to be the most common syntax in other systemd unit files.EnvironmentFileentries. Following the usual Logwatch scheme, the/usr/share/default.confdirectory contains the Logwatch defaults, and they can be customized in/etc/logwatch/conf/systemd.conf. The first of these files is only installed if theinstall_logwatch.shscript is run with the--systemdoption. The second file, if needed, would need to be created by the user, as is common with all the files in that directory.LOGWATCH_OPTIONSis being set to"--output mail --mailto root". The thinking being that it most closely approximates the behaviour of the default cron installation. When running it interactively, it behaves as the default logwatch invocation - in that case, it does not use the systemd files, and in the absence of any options, the default output is stdout. (Unlike specifying--outputin logwatch.conf, it which case it would have affected running it interactively as well.)Thank you very much for the implementation.
However in my opinion,
--mailto rootshould not be made default inLOGWATCH_OPTIONS.Because:
--output mailis specified. So it is redundant.rootand I will have to change mailto at two places. (logwatch.conf as well as systemd.conf)So simply putting
LOGWATCH_OPTIONS="--output mail"should be sufficient.If for some reason, user wants different email address (one for daily systemd e-mails and one for command line) then they can add
--mailto foo@bar.comin systemd.confThank you very much for implementing this.
Just for the record, the related commits are linked here:
https://sourceforge.net/p/logwatch/git/ci/014fed6375a57d94a2d568b1cf2a835d7113c8f5/
https://sourceforge.net/p/logwatch/git/ci/02349abdbdb746ffa34a17c5ae793b5e861bd47d/
https://sourceforge.net/p/logwatch/git/ci/e8ca7f728e01e156324a3acd5517b3292a051b94/
In summary, anyone can customize systemd.service behaviour as per their wish by editing systemd.conf file.