You need to store the state of the daemon somewhere, and also take measures to start the daemon with several processes at the same time.
The situation is complicated by the fact that inside gunicorn there are no primitives to solve this problem. So you need to contact any third-party service in each process to find out if the cleaning daemon is running or not. If the daemon is not running, then the responsible process needs to protect some storage from the state of the daemon (for example, using flock ), then start the cleaning daemon, wait for the successful launch, write the state to the global variable , unlock.
import simpleflock with simpleflock.SimpleFlock("/tmp/dircleaner"): # Запускаем демона # Отмечаем в файле или в БД что демон запущен pass
In the worst case, you will, in fact, in one part of the program, limit yourself to running into just one thread at the time the daemon starts. This means that all processes on the server will wait for one until he reports on the successful launch of the daemon. Bonus to this solution are various options for race condition and other heisenbags.
In addition, you need somewhere to track the correct operation of the purge daemon. What if it falls with an error because the disk has run out of logs? What if the parent process is killed by an OOM Killer ? What if ...? This is a whole separate problem that they know how and how to solve such programs as Supervisor.
Is it really necessary to hammer nails with a screwdriver?
cron'om, somesupervisоrd,gunicorn, etc. Want to clickrun, so that everything is ready and everything. :) - faoxis