'Remove contents of the supervisord logfile on every reboot

Is there a way by which on every reboot, we can empty the contents of logfile mentioned in "stdout_logfile" in supervisord config?

The logfile "worker.log" should be cleared on every reboot. When I put it in reboot to remove the logfile, the log gets removed but the supervisor process already started will stop logging anything in the file.

[program:prog]
command=/bin/bash /home/ubuntu/worker.sh 
directory=/home/ubuntu
user=ubuntu
autostart=true
autorestart=true
stdout_logfile=/home/ubuntu/worker.log
stdout_logfile_maxbytes=0
redirect_stderr=true


Solution 1:[1]

I could not find a way. So, used a hack mentioned in link below: https://stackoverflow.com/a/58954517/2782670

Disabled autostart in supervisord conf.

autostart=false

Created a shell script which will remove the file on reboot in crontab. Also will start the supervisor program.

#!/bin/bash

rm /home/ubuntu/worker.log
sudo supervisorctl start prog

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bgth