Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 547
Anze Avatar asked Feb 17 '23 02:02

Anze


2 Answers

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.

like image 183
Cesar Avatar answered Feb 18 '23 14:02

Cesar


If you are using Ubuntu standard way to create deb package all you need to do is to place package-name.upstart in debian folder.

dh_installinit is a debhelper program that is responsible for installing upstart job files or init scripts with associated defaults files into package build directories, and in the former case providing compatibility handling for non-upstart systems.

See dh_installinit.

I find building a Debian package from Bazaar branch to be the easiest way to create deb package.

See Packaging New Software as well.

I used such approach to create Gearman Job Server set of packages. Placing gearman-job-server.upstart was sufficient.

like image 32
Goran Miskovic Avatar answered Feb 18 '23 14:02

Goran Miskovic