Search code examples
ubuntupython-2.7daemondebupstart

python script to .deb ubuntu package to install a daemon


I have a python script which runs a daemon-like service, now I created the python package. I created a .deb package from there but I want the script to be run with upstart, but I can't mange to write the files in the /etc/init ubuntu folder automatically when .deb package is installed so that my daemon doesn't have to be started manually on reboot. I don't know if I explained this well, but I don't know how to explain it better...

what I have: python_script.py ->runs a python-daemon

python_script.tar.gz -> python package

what I need:

python.deb -> which install the python script and sets up the upstart for my python scrip so that it runs as a service/daemon


Solution

  • You should look for the debian packaging doc for python, other that can be useful is the stdeb tool, a Python to Debian source package conversion utility.

    For running it as a daemon you need to create a init.d script (you can see how to here, and here a more complete example), you can add the init.d script in the package and then call "update-rc.d myscript defaults" from the postinst script of the python.deb and call "update-rc.d -f myscript remove" from the prerm script.