Menu

#14 systemd timer

Future Release
closed
nobody
None
5
2019-11-01
2019-09-18
No

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

Discussion

  • Bjorn

    Bjorn - 2019-09-18

    The service and timer declarations are under the scheduler directory. The install_logwatch.sh script has a --systemd option to install them, rather than the cron file.

     
  • Erich Eckner

    Erich Eckner - 2019-09-19

    oh, sry, didn't know (I should have checked more thoroughly, first ...). This issue can be closed then. Thanks

     
  • Amish

    Amish - 2019-09-20

    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
  • Kamil Cukrowski

    Kamil Cukrowski - 2019-09-26

    I would suggest replacing

    I disagree. You configure that with Output = mail inside /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 wants Output = file... Also what if someone actually wants to have logwatch report show in journal. You configure the behavior in logwatch.conf not inside systemd service.

     

    Last edit: Kamil Cukrowski 2019-09-26
  • Amish

    Amish - 2019-09-26

    You configure that with Output = mail inside /etc/logwatch/conf/logwatch.conf

    Putting Output = mail in default as logwatch.conf means that even when I run it on command line, it sends a mail, which may not always be desired.

    No reason to send mail (to whom?) by default

    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.conf

    what if someone actually wants to have logwatch report show in journal

    That'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.

    Forcing the user to use mail output is wrong

    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.

     
  • Erich Eckner

    Erich Eckner - 2019-09-26

    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
  • Amish

    Amish - 2019-09-26

    There is another option which satisfies all cases by modifying systemd service file (logwatch.service) as follows.

    [Service]
    Type=oneshot
    EnvironmentFile=-/etc/logwatch/systemd.conf
    ExecStart=/usr/sbin/logwatch $EXEC_OPTIONS
    

    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 EnvironmentFile does 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
  • Bjorn

    Bjorn - 2019-10-27

    Thanks for the discussion, and the proposed solution. I implemented with some changes:

    • The variable is called LOGWATCH_OPTIONS. While not dictated by systemd, it seems to be the most common syntax in other systemd unit files.
    • There are now two EnvironmentFile entries. Following the usual Logwatch scheme, the /usr/share/default.conf directory contains the Logwatch defaults, and they can be customized in /etc/logwatch/conf/systemd.conf. The first of these files is only installed if the install_logwatch.sh script is run with the --systemd option. The second file, if needed, would need to be created by the user, as is common with all the files in that directory.
    • The default for LOGWATCH_OPTIONS is 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 --output in logwatch.conf, it which case it would have affected running it interactively as well.)
     
    👍
    2
  • Amish

    Amish - 2019-10-28

    Thank you very much for the implementation.

    However in my opinion, --mailto root should not be made default in LOGWATCH_OPTIONS.

    Because:

    1. It is anyway the default when --output mail is specified. So it is redundant.
    2. If I want to change my mailto address, I would most likely change in logwatch.conf file instead. So it applies globally to all the emails that come via Logwatch. But systemd.service file will still continue to send email to root and 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.com in systemd.conf

     
  • Bjorn

    Bjorn - 2019-11-01
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB