The pyservice is responsible for creating a "container" to run services in, and tools to manage that container. The container is itself a service based on a class called
Process, which is intended to model the running process that contains the service. The pyservice initializes the process to daemonize then the process takes an application service to run.
To install pyservice just download pyservice.py and place it in your project directory. There are no dependencies other than the Python Standard Library.
How to start to use
The example of simple process
import os import time import pyservice class SimpleProcess(pyservice.Process): pidfile = os.path.join(os.getcwd(), 'tests/run/simple_process.pid') logfile = os.path.join(os.getcwd(), 'tests/log/simple_process.log') def run(self): time.sleep(10)
To run this process as service you just need to type in command line
$ python -m pyservice tests.processes.simple_process.SimpleProcess start
The "ControlInterface" class models the commands you can use to start or control a daemonized service. This is exposed via one command line utilities "pyservice" which have the entry point defined in this module.
The runner module and command line utilities are completely optional. You can always just write your own Python script or console command that takes your application service.
Where does it used?
- start−stop−daemon is used to control the creation and termination of system-level processes. Using one of the matching options, start−stop−daemon can be configured to find existing instances of a running process.
- How do I get my program to act like a daemon?
- PEP: 3143, Standard daemon process library
- Building a python daemon process
- Creating a daemon the Python way (Python recipe)
For testing purpose
coverage libraries are required
$ pip install nose $ pip install coverage