Udaemon is a light command line tool to help you run a Python application as a background service.
Its purpose is to have a simplified way to deploy a Python script as a service. If you need more flexibility use systemd itself.
Marcos Valderrey - Software Developer - LinkedIn
Linux installation with systemd
and python
.
Clone this repository and you are ready to go!
Create a service definition like the one from the example somewhere. Visit systemd documentation to know more about different ways of setting up the service file according to your needs.
Add the new service to udaemon running:
python udaemon.py add <service-name> /path/to/your/service/<service-name>.service;
The path to your service could be relative to your working directory also, like:
python udaemon.py add <service-name> ./example/example.service;
You could also run udaemon for another location in this way:
python /home/someone/code/udaemon/udaemon.py add <service-name> /path/to/your/service/<service-name>.service;
To remove an added service you must run:
python udaemon.py remove <service-name>;
or
python /home/someone/code/udaemon/udaemon.py remove <service-name>;
You could check the state of the service and the latest logs running:
python udaemon.py status <service-name>;
Quick way to check which services you already deployed to udaemon:
python udaemon.py list;
You could use some of the common verbs on systemctl
through udaemon, but it is not recommendend nor necessary since this wrapper takes care of everything. The aliased commands are:
- Start a service (you should use
add
instead):
python udaemon.py start <service-name>;
- Stop a service (you should use
remove
instead):
python udaemon.py stop <service-name>;
- Enable a service (you should use
add
instead):
python udaemon.py enable <service-name>;
- Disable a service (you should use
remove
instead):
python udaemon.py disable <service-name>;
- Check the status of a service (this is still useful):
python udaemon.py status <service-name>;
Inside example folder there's a heartbeat logger.
Modify the WorkingDirectory
parameter on the example service definition such that it points to the root of this project.
If you want to test udaemon go ahead and run:
python udaemon.py add example.service example/example.service;
To see the heartbeat in action try:
python udaemon.py status example.service;
Also log entries should be written in example/example.log
showing the service is deployed.
To stop and remove the service run:
python udaemon.py remove example.service;