Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I manage a Python based daemon on Linux?

I have a working Python based program that I want to run as a daemon. Currently I'm doing it in a very hackish manner of starting it in with screen-d -m name session and killing it with pkill -9 -f name.

Eventually I'm doing to have to move this to the better system we use here (thus I'm not willing to modify the program) but in the interim, I'm looking for a cleaner way to do this.

My current thinking is kick it off as a background task from an inti.d script but how do I write the part to bring it back down?

like image 590
BCS Avatar asked Jun 01 '10 16:06

BCS


2 Answers

On linux there is a start-stop-daemon utility as part of the init.d tools.

It is very flexible and allows different ways for capturing the pid of your server.

There is also a file /etc/init.d/skeleton which can serve as a basis for your own init.d script.

If your target platform is debian based, it makes sense to create a debina package to deploy it as it also helps getting a daemon properly integrated in the rest of the system. And it is not too complicated (if you have done it ten times before ;-)

like image 102
Peter Tillemans Avatar answered Sep 28 '22 16:09

Peter Tillemans


See PEP 3143 -- Standard daemon process library

like image 41
vartec Avatar answered Sep 28 '22 14:09

vartec