genvid.toolbox.LocalService
- class genvid.toolbox.LocalService(services_dir=None, **kwargs)
Bases:
ServiceTool
This class wraps a service to be run locally as a background process.
The service configuration is stored under
services_dir/name
with aconfig
directory and adata
directory. The service starts as a background process with its output redirected toname.stdout.log
andname.stderr.log
. The service saves its process ID undername.pid
.Default value for
services_dir
is~/.genvid
.Changed in version 1.39.0: Change the default value for
services_dir
to~/.genvid
- basedir
Base directory to install the service.
- configdir
Configuration directory for the service.
- datadir
Data directory for the service.
- logdir
Log directory for the service.
- backupdir
Backup directory for the service.
- CONFIG_FILE
Configuration file of the service.
- pidfile
PID file of the service instance.
- logout
Standard Output log file of the service.
- options
Options file for the service.
This file keeps the list of options passed to the install command.
- is_installed()
Returns if the service is installed.
- install(reconfigure=False, **options)
Install the service if not already installed.
This checks for the service configuration, but doesn’t start 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.
- is_running()
Check if the service is running.
This checks the state of the process identified by the pidfile.
- print_log(lines: Optional[int] = None)
Print the log file for this service.
Changed in version 1.27.0: Removed stdout boolean flag as both logerr and logout are now written to them same folder.
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.
Changed in version 1.29.0: Add check for other running instances of the same service.
- stop()
Stop the service if it’s running.
- status(withlog=False, lines=None)
Return the status of the service.
This checks the state of the process identified by the PID file.