genvid.toolbox.LocalService

class genvid.toolbox.LocalService(services_dir='local-services', **kwargs)

Bases: genvid.toolbox.service.ServiceTool

This class wraps a service to be run locally, as a background process.

The service configuration is done under ROOTDIR/local-services/<name> with a config directory and a data directory. The service is started as a background process with its output redirected to <name>.stdout.log and <name>.stderr.log. Its process ID is saved under <name>.pid.

CONFIG_FILE = None

Configuration file of the service.

basedir = None

Base directory to install the service.

configdir = None

Configuration directory for the service.

datadir = None

Data directory for the service.

get_process()

Return a psutil.Process of the service or None if none is found.

This is done by loading the pid from the pidfile. It doesn’t check if the process is the right one and so can be fooled in case of PID warparound.

install(**options)

Install the service if not already installed.

This doesn’t start the service, it just checks for its configuration.

is_installed()

Returns if the service is installed.

is_running()

Check if the service is running.

This is done by checking the state of the process identified by the pidfile.

logerr = None

Standard Error log file of the service.

logout = None

Standard Output log file of the service.

options = None

Options file with which the service will be run.

This file keeps the list of options passed to the install command.

pidfile = None

PID file of the service instance.

print_log(stdout=True, lines=None)

Print the log file for this service.

if lines is not None, he must be the number of the last lines to print.

start()

Starts the service if it’s not already started.

status(withlog=False, lines=None)

Return the status of the service.

This is done by checking the state of the process identified by the PID file.

stop()

Stop the service if it’s running.

uninstall()

Uninstall the service.