SensuGO Agent and Backend Logging

Hey,
It sounds like you are not familiar with systemd’s journal and the journalctl facility. But this isn’t a linux forum, so I’ll refrain from diving into a lesson on using journalctl and try to show you how you can modify the systemd managed service to produce log files like you’ve stated.

If you want to customize the systemd service unit for sensu-agent, first create an overrides directory for it:

/etc/systemd/system/sensu-agent.service.d

Any configuration you put into that directory will override provided settings in the vendor package provided service unit. If you edit the vendor package provided service unit, you risk losing your edits on package upgrade. The overrides directory concept in systemd is so much better than some sysvinit implementations, it really helps to keep local mods separate from vendor tested/support scripting for troubleshooting later. Essentially every part of the systemd service configuration is overridable.

Now create a file like:

/etc/systemd/system/sensu-agent.service.d/redirect-logs.conf

Name doesn’t matter so much, name it something that helps you remember why its there.
This is the file were we are going to add systemd service configuration options or override the running executable script as needed to run sensu-agent however we want.

Okay, first option if your systemd is new enough to support it (systemd 240 I believe), you can specify
exactly what files you want to redirect stdout and stderr to, and set them up to append.
Here’s the doc reference:
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardError=

Here’s the content of my redirect-logs.conf

[Service]

StandardOutput=append:/var/log/sensu/sensu-agent.log
StandardError=append:/var/log/sensu/sensu-agent.log

Once you add the file you’ll need to do a systemctl daemon-reload to have systemd pick up the new config, and then restart the sensu-agent service.
After that you should have the sensu-agent.log getting populated and the journal should be pretty bare.

If that doesn’t work you can use the same override config file to replace the ExecStart= with a bash script wrapper lilke…

ExecStart=/bin/sh -c '/usr/sbin/sensu-agent start 2>&1 >> /var/log/sensu/sensu-agent.log' 

Again don’t edit the vendor provided service unit, use the override directory to make sure package upgrades don’t overwrite your overrides.