0

In a Python daemon, I redirect the STDOUT and STDERR to some file with two-fork mode:

os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())

Start the daemon and the STDOUT can redirect to my specified file in /var/demo/stdout.

But if I make the daemon module as an Linux service via Systemd, the service file like:

[Unit]
Description=demo
After=network.target

[Service]
Type=forking
WorkingDirectory=/opt/demo/
ExecStart=/bin/bash -c '/anaconda3/bin/python3 -m scheduler.run start'
PIDFile=/var/run/demo.pid
SyslogIdentifier=Demo
User=root

[Install]
WantedBy=multi-user.target

The STDOUT seems does not redirect to the file /var/demo/stdout. Service type set to forking and ExecStart command has been tested and it can worked as expected.

So the only question is why the STDOUT can not redirect to a normal file if the Python module runs as an Linux service.

lssbq
  • 73
  • 2
  • 12
  • I checked the redirect normal file and find it already opened in the Python daemon process(PID is 14384):`#fuser stdout /var/log/demo/stdout: 14384` But there is nothing sent to the file. – lssbq Mar 13 '18 at 11:06
  • Possible duplicate of [How to redirect output of systemd service to a file](https://stackoverflow.com/questions/37585758/how-to-redirect-output-of-systemd-service-to-a-file) – CristiFati Mar 13 '18 at 13:28

0 Answers0