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.