Re: Redirect output from python script with systemd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Jul 7, 2018, at 3:28 PM, C. L. Martinez <carlopmart@xxxxxxxxx> 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@xxxxxxxxxx>
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]


  Powered by Linux