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.
Adding additional info:
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 ?
Question: What is the recommended approach for packaging and deploying a Python code on CentOS/RHEL?
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, 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
Is your code pure python?
What python 3rd party packages do you need?
Are they available from EPEL?
For background; I run a number of python programs as services on my systems.
In production I have supported large scale deployments on Centos with python code in RPMs.
Yes, it only contains python (No C/C++).The python version is 3.8 for Rhel Systems, and for centos it might be either 3.4 or 2.7 (we are yet to decide foe cent os)
3rd party packages: Requests, Pydantic, stevedore
I’m not sure whether these packages are available in EPEL (I have to Google it).
You are saying that you setup the python env and run your rpms in it even in large scale deployment?
The problem for me is,
A few systems don’t have internet connections.
And, Rhel 7.x pkg manager has python up to 3.6, But our code is developed using py3.8, If we go with RPM route, then we have to create a venv with py3.8 to run the service which is complex. Am I correct?
That’s why, I’m looking for a option to deploy the python code as a single file to the target machines and install that package and run it
We poackaged everything as RPMs and installed into site-packages for packages and into app folder for the apps themselves. No need for venv’s.
RHEL 7 has 3.8 and 2.7 I recall.
RHEL 4! I have not seen as old a system. It was bad enough on Centos6.
I’m guessing you can only realistically use python 2.7.
But does RHEL 4 have 2.7? Or is it an older python 2?
Build for unsupported RHEL is going to be hard.
There is a mock build env for RHEL 7, but all the others are 8+.
Does you organisation have a plan to get on to supported OS?
There was a requests for 2.7 not sure about Pydantic, stevedore.
If you are connecting to the internet then using old verison of python and requrest may put your system at risk.
Assume you have a py package developed usig py3.8, but your rhel has py3.6, What would you do to use your py3.8 package without modifying it? And, Your system doesn’t have internet connection
Will you deploy it as a application? Will building the package with PyInstaller/pex be helpful?
Maybe, I share a scenario,
Our App is a background service which must run all the time eventhough the python3 is uninstalled accidentally, Or, if someone upgrades the python3 version,
If we go with source code approach, this scenario will fail, right?
How to mitigate this scenario?
If i have the priviliges or if the systems are owned by our company, then I would have upgraded the OS and just run it as a py program itself.
Since We are providing service to other companies, that’s where the issue is, they aren’t willing to upgrade their OS to the latest one
That’s why, we are planning to deliver it with what they currently have