Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to package a Python daemon with setuptools

How do you package a Python app with setuptools so that when it's installed (e.g. via setup.py or pip), it places a daemon script in the appropriate location, starts it, and marks it to automatically start at boot time?

In my case, my code only works with Linux, so I only care about installing the daemon in Linux environments (specifically Ubuntu).

I've found several posts describing how to easily create Python daemons, but I can't seem to find anything describing how you'd install them in a production environment so that they'd be treated as any other normal daemon or service.

I know Ubuntu and some other distros keep their daemons in /etc/init.d, and I know how to use setuptools to copy files to specific locations on the filesystem, so would it be safe to copy or symlink my script to /etc/init.d and then run chkconfig to set it's runtime, or is there a more safe distribution-neutral way of installing daemons?

like image 801
Cerin Avatar asked Mar 15 '12 15:03

Cerin


People also ask

How do I import setuptools in Python?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.

What is Python setuptools package?

Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). It includes: Python package and module definitions. Distribution package metadata.

Does Python include setuptools?

the setuptools is not part of the python vanilla codebase, hence not a vanilla modules. python.org installers or mac homebrew will install it for you, but if someone compile the python by himself or install it on some linux distribution he may not get it and will need to install it by himself.


1 Answers

This would be better handled by creating an appropriate package for the distro (in the case of Ubuntu, a .deb) since you can't guarantee the location of the startup scripts across distros. For example, arch linux uses /etc/rc.d/. Also, copying to locations like that will require root access (which I don't believe is necessarily required to install python packages) and may not be easily reversible when uninstalling.

I would suggest that you create a normal setupttools installation and then package it into a deb with a link to /etc/init.d.

like image 103
aquavitae Avatar answered Sep 21 '22 02:09

aquavitae