I’ve developed a Python-based background service that performs periodic data uploads and file processing. It’s built with multiple modules/packages and runs persistently in the background on CentOS/RHEL systems.
I’m currently managing it with a systemd unit file and using a virtual environment, but I’m exploring more robust, scalable ways to deploy it cleanly across systems.
Question: What is the recommended approach for packaging and deploying a Python service on CentOS/RHEL?
You could package your application in an RPM, but that is going to require some effort. You’d have to learn how RPM packaging works and you may have to maintain several RPMs.
A simpler approach is a container + Podman Quadlet. Quadlet lets you run containers with Podman under systemd. Start with ubi9/python-312 container, install your application, push your container to Quay, and then run your container as a Quadlet.
I’m using py3.8 and my service should run as root to track some activities.
And, some of our Rhel/centos servers doesn’t support py3.8 by default, it can install upto py3.6 using package managers, so we are manually installing python3.8 using the zip files and setting up the env for testing it.
We would like to deploy it as a bg service which should run always, what’s your recommendation ?
If we use containers, we can’t access root level information without providing permissions which requires manual intervention, Is my understanding correct? In future, we are planning to automate the deployment as well
If we build rpm using ubuntu (one of the linux servers), is it possible to use it in other OS like RHEL/CENTOS?
Use a fedora/rhel/centos system to build your rpms it the easiest method.
Ubuntu lacks all the needed tooling to build first class rpm packages.
With 100 servers I would definitely use rpms.
I did exactly that at my previous job.
As you noticed containers makes doing root level activities difficult.
You might like to ask questions about packaging over on https://discussion.fedoraproject.org/ where the expertise on Fedora/rhel/centos hangs out and helps people.
I would definitely continue to use systemd. Whatever form of scalability you need, it should be able to incorporate the creation of that unit file, and then systemd will manage all the details.
It’s up to you. You can run containers with no namespace isolation at all. For example Toolbx containers use the approach to give special containers access to the users home directory, X11/Wayland session, D-Bus, and SSH agent.
If I use the RPM build file (which is my Python package), do I still need to set up the Python environment on the target machine? To run the RPM file?
AFAIK, it’s Yes. So, can it be installed and used as a standalone service? That is, I don’t want to perform any Python env setup on my target machine, move the build file, install and run it
People with the expertise to tell you how to package for RPM are on https://discussion.fedoraproject.org/
It is where the developers that support python on rhel/centos/fedora are.