1

I have a systemd (v249) service (my-script.service) which is run every minute by another systemd timer (my-script.timer). Everything's working fine. But systemd logs (to it's journald & thence to /var/log/syslog) the following 2 lines saying that it started and then stopped it:

Aug 11 11:46:37 hostname1 systemd[1]: Started my-scripts.
Aug 11 11:46:37 hostname1 systemd[1]: my-scripts.service: Deactivated successfully.

Is there anyway to disable this logging message for this .service/.timer? Nearly all the time there is no output to log (the script starts up, checks if it has anything to do, then exits in the common case of nothing to do). These log messages are useless, and worsen the signal to noise ratio of my logs.

I am relatively new to systemd, this might be a simple question.

Amandasaurus
  • 30,211
  • 62
  • 184
  • 246

1 Answers1

2

The criticality of log messages can be, as you may find in the documentation of journald

emerg (lowest log level, only highest priority messages), alert, crit, err, warning, notice, info, debug (highest log level, also lowest priority messages)

EDITED - changed the default criticality with a lower with "the default criticality value with a higher"

You can configure the default criticality of your service and the maximum criticality value you want to see in the logs editing the unit file. So, if you configure the default criticality value with a higher value than the maximum criticality (highest priority has 0 value, debug priority has a value of 7), the messages for the starting and the ending of the service wouldn't be displayed in the logs

EDITED - Changed the level representation with numbers

[Service]
...
LogLevelMax=1
SyslogLevel=2

You should produce logs in your service with a higher priority (with a lower priority value) than LogLevelMax (see Systemd for Developers III)

EDITED - ADDED EXAMPLE

I have made a new trivial service /root/Bin/test.bash that produces logs with Level 1 (alert)

#! /bin/bash
echo "<1>Done"

I have created a new unit (/etc/systemd/system/jmr.service):

[Unit]
Description=JMR test

[Service]
ExecStart=/root/Bin/test.bash
LogLevelMax=1
SyslogLevel=2

[Install]
WantedBy=multi-user.target

After that, I reconfigure systemd and restart the service two times

# systemctl daemon-reload
# systemctl start jmr.service
# systemctl start jmr.service

I can see that the logs only show the message "Done" (nothing in between the two logs)

# journalctl -u jmr.service | tail -n 2
ago 16 19:09:10 enreda test.bash[415488]: Done
ago 16 19:11:42 enreda test.bash[415620]: Done
J.M. Robles
  • 865
  • 6
  • 9
  • I tried this approach, but it hasn't solved my issue (I think). My problem is not with the log message _from my service_, but the 2 log messages _from systemd_ saying that it is starting the service (& then that the service has succeeded). I don't think this configuration changes _the systemd_ log messages, does it? – Amandasaurus Aug 15 '22 at 12:27
  • I tested myself in my computer that solution. I have created a unit /etc/systemd/system/jmr.service that did echo "<1>Done" (to produce logs with level 1). I programmed LogLevelMax=1 and SyslogLevel=2 (after that, you know, you must execute systemctl daemon-reload). When I execute the service (systemctl start jmr.service) and consult the logs (journalctl -u jmr.service) I see only the log of "Done". I am going to edit the response to reproduce exactly that – J.M. Robles Aug 16 '22 at 17:13
  • Sorry, re-reading my response, I have seen that the example is ok, but the text not. Edited once again – J.M. Robles Aug 16 '22 at 17:44
  • I was able to see the correct behaviour on my debian desktop with your test service, but *not* on the ubuntu server I was looking at. *But*, the [systemd CHANGELOG](https://github.com/systemd/systemd/blob/98f3e84342dbb9da48ffa22bfdf122bdae4da1c6/NEWS#L1927-L1931) tells me this feature was added in systemd v249. I have v245 on the servers. I will have to wait. Thanks for your tips – Amandasaurus Aug 24 '22 at 08:59