0

I have a Python program that I start on boot with a service in systemd. It works fine until Unix tries to rotate the system log file, and I get an error: "Journal has been rotated since unit was started. Log output is incomplete or unavailable." (systemctl status) The Python program is dead, and if I reboot, the PI won't come back up to GUI. I have found that if I restart logging, then I can reboot without corruption. (sudo service rsyslog restart). The Python program has limited print statements, so the log file data size should not be too big. what do I need to change to keep the rsyslog system from corrupting my system? Of course, the Python program runs fine from command line.

[Unit]
Description=flow system controller

[Service]
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
ExecStart=/usr/bin/python3 /home/pi/Documents/programs/flow_control.py
Restart=always
RestartSec=10s
KillMode=process
TimeoutSec=infinity

[Install]
WantedBy=graphical.target
  • Your program should not die because of a journal log rotation. The message is a warning not an error. Perhaps something else is logging too much you are running out of disk space. Try sudo journalctl --no-pager -f to see what is being logged in real time. – meuh Jul 8 at 14:24
  • For what do you need Restart=always? It never helps to "fix" a buggy service and may confuse systemd in case of restarting a buggy service. Also the other settings may confuse systemd. Why do you configure the service for graphical output when only using text output with print statements in python3? – Ingo Jul 9 at 17:59
  • You are right that always is a bad idea. I sometimes use graphical elements in my python3 in addition to print statements. I think meuh is correct in that something else was causing the error. – smclaugh5 Aug 12 at 14:09
1

The python PRINT statement is really designed for interactive use / debugging and I do not use it for none-interactive programs.

I use my own wrapper around the Python logging module and create my own log file that is rotated under my control. My wrapper has a few functions:

  • Creation / appending of the log-file
  • Layout of messages to a standard format
  • Handling of different error levels
  • Optional output to the console during debugging
  • Driven by an INI file or command line option for debug messages

If you do not want to change the program to use the logging module, then you could look to redirect STDOUT (where the print comes through) to your own file when the program is called:

python3 myprogram.py > file.log

or

python3 myprogram.py >> file.log

The first will overwrite the file while the second will create the file if it’s not present or append to the file if it exists. A Google search on redirection in Linux will give many tutorial such as this one with lots of details.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.