Skip to content

Latest commit

 

History

History
112 lines (81 loc) · 3.11 KB

README.md

File metadata and controls

112 lines (81 loc) · 3.11 KB

Udaemon

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.

Author

Marcos Valderrey - Software Developer - LinkedIn

Requirements

Linux installation with systemd and python.

Installation

Clone this repository and you are ready to go!

Usage

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.

Creating a new service

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;

Removing a 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>;

Checking service state

You could check the state of the service and the latest logs running:

python udaemon.py status <service-name>;

Listing added services

Quick way to check which services you already deployed to udaemon:

python udaemon.py list;

Alias

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:

  1. Start a service (you should use add instead):
python udaemon.py start <service-name>;
  1. Stop a service (you should use remove instead):
python udaemon.py stop <service-name>;
  1. Enable a service (you should use add instead):
python udaemon.py enable <service-name>;
  1. Disable a service (you should use remove instead):
python udaemon.py disable <service-name>;
  1. Check the status of a service (this is still useful):
python udaemon.py status <service-name>;

Example

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;