You are not logged in.

#1 2016-06-22 11:35:18

whoops
Member
Registered: 2009-03-19
Posts: 891

[solved]How deal with noisy programs in systemd services?

Hi!


I still haven't really gotten used to systemd / journal stuff... I'm using "syncthing" as an example here. By default it generates a lot of "INFO" messages that I don't want to end up in my journal. I couldn't find a setting to change log level for the program, so I took a look at the service.

I can thing of several solutions, but they're all kind of clumsy...

The service file is owned by the package, so I guess I'm not supposed to change it. It's probably not a good idea to make a copy and try to cram a "grep" in there somehow... because... future updates...?

I could simply use a different way to start syncthing etc and pipe the output trough grep and wherever I want... but that kind of solution is sort of the reason why I haven't gotten used to systemd yet in the first place and if I continue like that, I'll just end up writing - bit by bit - what basically amounts to my very own crappy / glitchy version of the old init system / logger chain etc...


What's the proper way to deal with log spam by services now?

Last edited by whoops (2016-06-24 14:27:02)

Offline

#2 2016-06-22 13:17:15

syg00
Member
Registered: 2006-01-11
Posts: 31

Re: [solved]How deal with noisy programs in systemd services?

You can't - welcome to systemd. Have a read of this recent thread, it may work for you.
There is probably some argument to keep all the rubbish - it can always be searched later in need.

Offline

#3 2016-06-22 13:59:34

ooo
Member
Registered: 2013-04-10
Posts: 1,637

Re: [solved]How deal with noisy programs in systemd services?

whoops wrote:

The service file is owned by the package, so I guess I'm not supposed to change it.

You can copy the service file to /etc/systemd/system/, and edit it there. It will take precedence over the service file installed with the package. See https://wiki.archlinux.org/index.php/sy … unit_files

I think you could just redirect the output to e.g. /dev/null one way or another. There's also '-logfile' option for syncthing that may be helpful.

Offline

#4 2016-06-22 20:30:12

whoops
Member
Registered: 2009-03-19
Posts: 891

Re: [solved]How deal with noisy programs in systemd services?

The logfile option logflags options only allow to choose a file as output for everything and change the timestamp format... as far as I can tell, there isn't an option to set loglvl.

The "/etc/systemd/system/" option looks more useful than I thought tough - I totally overlooked how versatile those things are, thanks!


Created /etc/systemd/system/syncthing@.service.d/nospam.conf:

[Service]
ExecStart=
ExecStart=/bin/sh -c '/usr/bin/syncthing -no-browser -no-restart -logflags=0 | grep -v "INFO: "'

and "reenable"d + restarted the service. Almost looks like that does the tricks. I'm not sure yet about the "sh -c" workaround though - syncthing has:

SuccessExitStatus=3 4
RestartForceExitStatus=3 4

... and I'm guessing "bash -c" will swallow those, which means syncthing probably won't restart if it crashes? Or does bash just forward a "1" if syncthing fails and everything will work?

Offline

#5 2016-06-22 20:45:27

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [solved]How deal with noisy programs in systemd services?

man bash wrote:

Bash  itself  returns  the  exit  status  of the last command executed, unless a syntax error occurs, in which case it exits  with  a  non-zero   value.

but also

The return status of a pipeline is the exit status of the last command, unless the pipefail option is enabled.  If  pipefail  is  enabled,  the pipeline's  return  status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands  exit  success‐fully.

so you may want to try (also changing sh to bash to make use of this feature)

ExecStart=/bin/bash -c 'set -o pipefail; syncthing -no-browser -no-restart -logflags=0 | grep -v "INFO: "'

Last edited by Raynman (2016-06-22 20:46:17)

Offline

#6 2016-06-24 14:26:45

whoops
Member
Registered: 2009-03-19
Posts: 891

Re: [solved]How deal with noisy programs in systemd services?

Tested it for a while and it seems to work great, thanks!

Offline

Board footer

Powered by FluxBB