Redirect output from python script with systemd

Hi all,

I need to redirect an output from python script that runs as a systemd service. I have tried to redirect its output in Exec statement without luck. I have tried to use StandardOutput and StandardError options also, but outpu log goes to /var/log/messages.

Any tip?



Re: Redirect output from python script with systemd

By Jonathan Billings at 07/07/2018 - 16:36

On Jul 7, 2018, at 3:28 PM, C. L. Martinez < ... at gmail dot com> wrote:
Ideally, you should be using python’s “logging” library[1] to write to a file if you don’t want it going to the journal. But if you must make systemd handle it, use StandardOutput=file:/path/to/logfile[2]. Make sure your service has access to that file to write.

You can’t use shell redirects in Exec lines since systemd units aren’t shell scripts. You can, of course have the service include:
Exec=/use/bin/bash -c “pythonscript > /var/log/script.log”

1. <a href="" title=""></a>
2. <a href="" title=""></a>

Jonathan Billings < ... at negate dot org>