mentat-controller.py

This Mentat module is a script providing Mentat system control functions and features.

This script is implemented using the pyzenkit.zenscript framework and so it provides all of its core features. See the documentation for more in-depth details.

The Mentat system is a collection of many real-time processing and post-processing modules. Launching and managing so many processes would be really tedious work. And that is exactly the use-case for this module. Its purpose is to start/stop/restart all preconfigured real-time message processing modules and enable/disable all preconfigured message post-processing modules (cronjobs).

Usage examples

# Display help message and exit.
mentat-controller.py --help

# Run in debug mode (enable output of debugging information to terminal).
mentat-controller.py --debug

# Run with increased logging level.
mentat-controller.py --log-level debug

# Determine the current status of Mentat system and all of its modules.
mentat-controller.py
mentat-controller.py --command status

# Same as above, only execute and produce output in Nagios plugin compatible
# mode.
mentat-controller.py --command status --nagios-plugin --log-level warning

# Start/stop/restart all configured real-time message processing modules.
mentat-controller.py --command start
mentat-controller.py --command stop
mentat-controller.py --command restart

# Enable/Disable all configured message post-processing modules (cronjobs).
mentat-controller.py --command enable
mentat-controller.py --command disable

# Send signal to all configured real-time message processing modules.
mentat-controller.py --command signal-usr1

# Work with particular modules.
mentat-controller.py --command start --target mentat-storage.py
mentat-controller.py --command stop --target mentat-enricher.py mentat-inspector.py
mentat-controller.py --command signal-usr1 --target mentat-inspector.py

Available script commands

status (default)

Detect and display the status of configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

start

Start configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

stop

Stop configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

restart

Restart configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

enable

Enable configured cron modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All cron modules will be affected by default.

disable

Disable configured cron modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All cron modules will be affected by default.

signal-hup

Send signal HUP to configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

signal-kill

Send signal KILL to configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

signal-usr1

Send signal USR1 to configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

signal-usr2

Send signal USR2 to configured modules. The --target command line option (repeatable) or target configuration file directive enables user to choose which modules should be affected by the command. All modules will be affected by default.

pidfiles-clean

Clean up dangling PID files (files without matching running process).

Custom configuration

Custom command line options

--target module-id

Target module(s) for the current command (repeatable).

Type: string

--nagios-plugin

Execute as Nagios plugin (flag).

Type: bool, default: False

Custom configuration file options

modules

List of real-time message processing modules that should be managed.

Type: list of dicts

cronjobs

List of message post-processing modules that should be managed.

Type: list of dicts

Configuration

The application supports multiple means for adjusting the internal configurations. When appropriate the default values for each configuration is hardcoded in module source code. However there are several options to change the value:

  • Override the internal default value when instantinating the application object by passing different value to object constructor.

  • Pass the different value by configuration file.

  • Pass the different value by command line option.

The configuration values are assigned from the sources mentioned above in that particular order, so the value given by command line option overwrites the value written in configuration file.

Command line options

Configuration can be passed down to application by command line options. These options have the highest priority and will overwrite any other configuration values. Depending on the base object of the application different set of options is available.

Common application options

Following configuration options are available for all applications based on pyzenkit.baseapp:

--help

Display help and usage description and exit (flag).

--debug

Run in debug mode (flag).

Input various status information to stderr.

Type: boolean, default: False

--quiet

Run in quiet mode (flag).

Do not write anything to stdout or stderr.

Type: boolean, default: False

--verbose

Increase application output verbosity (flag, repeatable).

Type: boolean, default: False

--name alternative-name

Alternative name for application instead of default $0.

This value will be used to generate names for log, runlog, pid, status and other application files.

Type: string, default: $0

--config-file file-name

Name of the configuration file.

Type: string, default: autodetected

--config-file-silent

Do not complain in case given configuration file does not exist (flag).

Type: boolean, default: False

--config-dir file-name

Name of the configuration directory.

Type: string, default: autodetected

--config-file-silent

Do not complain in case given configuration directory does not exist (flag).

Type: boolean, default: False

--log-file file-name

Name of the log file.

Type: string, default: autodetected

--log-level level

Logging level [debug, info, warning, error, critical].

Type: string, default: info

--runlog-dir dir-name

Name of the runlog directory.

Type: string, default: autodetected

--runlog-dump

Dump runlog to stdout when done processing (flag).

Type: boolean, default: False

--runlog-log

Write runlog to logging service when done processing (flag)

Type: boolean, default: False

--pstate-file file-name

Name of the persistent state file.

Type: string, default: autodetected

--pstate-dump

Dump persistent state to stdout when done processing (flag).

Type: boolean, default: False

--pstate-log

Write persistent state to logging service when done processing (flag).

Type: boolean, default: False

--action action

Execute given quick action and exit. List of available actions can be displayed with --help option.

Type: string, default: None

--user name-or-id

Name/gid of the system user for process permissions.

Type: string, default: None

--group name-or-id

Name/gid of the system group for process permissions.

Type: string, default: None

Common script options

Following configuration options are available on top of common applicationsoptions for all applications based on pyzenkit.zenscript:

--regular

Operational mode: regular script execution (flag).

Conflicts with --shell option.

Type: boolean, default: False

--shell

Operational mode: manual script execution from shell (flag).

Conflicts with --regular option.

Type: boolean, default: False

--command name

Name of the script command to be executed.

Type: string, default: autodetected

--interval interval

Execution interval. This value should correspond with related cron script.

Type: string, default: daily

--adjust-thresholds

Round-up time interval threshols to interval size (flag).

Type: boolean, default: False

--time-high time

Upper time interval threshold.

Type: float, default: time.time

Configuration files and directories

Configuration can be passed down to application using a combination of configuration file or configuration directory.

The available configuration keys are very similar to command line options and the names differ only in the use of _ character instead of -. However there is a certain set of configuration keys that is available only through command line options and not through configuration file and vice versa.