C. L. Martinez
2018-Jul-07 19:28 UTC
[CentOS] 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? Thanks. -- Greetings, C. L. Martinez
Jonathan Billings
2018-Jul-07 21:36 UTC
[CentOS] Redirect output from python script with systemd
On Jul 7, 2018, at 3:28 PM, C. L. Martinez <carlopmart at gmail.com> wrote:> 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? >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. https://docs.python.org/2/library/logging.html 2. https://www.freedesktop.org/software/systemd/man/systemd.exec.html ? Jonathan Billings <billings at negate.org>