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 stored under ROOTDIR/local-services/<name> with a config directory and a data directory. The service starts as a background process with its output redirected to <name>.stdout.log and <name>.stderr.log. The service saves its process ID 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 loads 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 wraparound.
-
install
(**options)¶ Install the service if not already installed.
This checks for the service configuration, but doesn’t start the service.
-
is_installed
()¶ Returns if the service is installed.
-
is_running
()¶ Check if the service is running.
This checks 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 for the service.
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.
The value for lines is either the number of lines from the last to print or None.
-
start
()¶ Starts the service if it’s not already started.
-
status
(withlog=False, lines=None)¶ Return the status of the service.
This checks the state of the process identified by the PID file.
-
stop
()¶ Stop the service if it’s running.
-
uninstall
(clean: bool = False)¶ Uninstall the service.
-