LinuxServiceManager
- class openmsistream.services.LinuxServiceManager(*args, **kwargs)
Bases:
ServiceManagerBase
Base class for working with Linux daemons
- Parameters:
service_name (str) – The name of the daemon as installed
service_spec_string (str, optional) – A string specifying which code should be run as a daemon. Could be the name of an OpenMSI Runnable class, or the path to a custom Python code. Custom Services can also specify a
OpenMSIToolbox.Runnable
class name, and/or a function in the file using special formatting like [class_name]=[path.to.file]:[function_name]. Only needed to initially install the daemon.argslist (list, optional) – The list of arguments (as from the command line) to pass to the
OpenMSIToolbox.Runnable
class. Only needed to initially install the daemon.interactive (bool, optional) – if True, a few more messages/prompts will come up telling a user what to do
- property env_var_names
Names of the environment variables used by the service (any environment variables in the command line arguments or config file)
- install_service()
Install the daemon
- start_service()
Start the daemon
- service_status()
Print the status of the daemon
- stop_service()
Stop the daemon
- remove_service(remove_env_vars=False, remove_install_args=False, remove_nssm=False)
Remove the daemon.
- Parameters:
remove_env_vars (bool, optional.) – if True, any environment variables needed by the daemon will be removed.
remove_install_args (bool, optional) – if True, the file listing the arguments used to install the daemon (to make it easier to re-install) will be removed.
remove_nssm (bool, optional) – Not used for Linux daemons.
- classmethod get_argument_parser(install_or_manage=None, class_name_or_spec_string=None)
Return the command line argument parser that should be used
- Parameters:
install_or_manage (str) – Whether the parser used should accept commands for “install”-ing or “manage”-ing the Service/daemon
class_name_or_spec_string (str, optional) – the first argument to the install script, if that’s being run. Used to add subparsers for known Runnable classes or for custom Runnables defined at the time the Service/daemon is being installed.
- Returns:
the
OpenMSIStreamArgumentParser
object that should be used- Return type:
OpenMSIStreamArgumentParser
- Raises:
ValueError – if install_or_manage is neither “install” nor “manage”
- classmethod get_command_line_arguments() Tuple[List[str], Dict[str, Any]]
Return the names of arguments for the logger stream and file levels.
- classmethod get_init_args_kwargs(parsed_args: Namespace) Tuple[List[str], Dict[str, Any]]
Get the list of init arguments and the dictionary of init keyword arguments for this class given a namespace of, for example, parsed arguments.
- Parameters:
parsed_args (argparse.Namespace) – A namespace containing entries needed to determine the init args and kwargs for this class
- Returns:
A list of init args
- Returns:
A dictionary of init kwargs
- property logger
The logger object that the class can use
- reinstall_service()
Install the service using the arguments defined in the service arguments file
- run_manage_command(run_mode, remove_env_vars=False, remove_install_args=False, remove_nssm=False)
Run one of the other functions according to the action given
- Parameters:
run_mode (str) – The string identifying the action(s) that should be taken
remove_env_vars (bool, optional.) – if True, any environment variables needed by the Service/daemon will be removed. Only used when removing the Service/daemon.
remove_install_args (bool, optional) – if True, the file listing the arguments used to install the Service/daemon (to make it easier to re-install) will be removed. Only used when removing the Service/daemon.
remove_nssm (bool, optional) – if True, the NSSM executable will be removed. Only used when removing the Service/daemon.