A process manager in Python.
Project description
Process manager in Python
Launches and manages processes according to a set of specifications, shuts them down in bulk on request. Useful for test environments without inherent cleanup.
Usage
To use, place a configuration file in the target directory. The configuration file is a json file (by default, pymanager.json, but it can be changed with the -f or –file switch) following a specified structure.
You may also launch the process manager as a daemon. Pass the -d or –daemon switch to do this.
Concepts
The manager works with two kinds of objects: processes and verifiers.
A single process is an entry which is launched by the manager. The amount of processes cannot currently be changed during execution, however, any process may be restarted at will. Currently, this manipulation can only be done via the exposed HTTP interface, but a command line tool with persistence is planned.
A verifier is an instance of a Verifier object that may be attached to processes. The goal of verifiers is to check if the process managed to achieve a desired state - for example, in a testing environment of an HTTP service, testing cannot proceed until the service starts its listening process. In other scenarios, a certain process may be required to finish running and exit with a 0 status code before another process may be ran.
There are two verifiers built into the manager, the HttpOkVerifier from the http_verifier module, which verifies by periodically querying a specified URL and passes if a 200 OK is returned; and the ExitedVerifier from the exited_verifier module, which passes if the attached process exits with the provided status code within the given timeframe.
Additional verifiers may be loaded through the modules directive in the configuration file. The only requirement is that all verifier classes must extend the Verifier base class provided by pymanager.
Configuration
Below is the expected structure of a pymanager file.
{
"modules": {
"pymutils.http_verifier": {
"verifiers": ["HttpOkVerifier"]
}
},
"http": {
"enabled": true,
"port": 5001
},
"keep-alive": true,
"processes": {
"test": {
"executable": "python3",
"arguments": ["test.py", "-v", "-t"],
"options": {
"suppress_output": false
},
"verifier": {
"type": "pymutils.http_verifier.HttpOkVerifier",
"arguments": {
"url": "http://google.com"
}
}
}
}
}
modules
All verifiers loaded used must be loaded in the modules section. The key of the verifiers is the import to load (ex. http_verifier), and the list under the key verifiers contains the list of classes to add to the verifier registry.
http
The application exposes an HTTP interface for convenient manipulation and data exchange. To flip the switch, add
“enabled”: true
in the HTTP object in the configuration. The port by default is 5001, which may be modified using the port option.
The available HTTP endpoints currently are:
GET /
Lists all processes managed by the application, including the status, the internal ID and the process ID or exit code, which ever applicable.
GET /status
Returns the state of the application. If the status is ‘running’, it is safe to assume that all processes are in their desired state.
POST /restart/<id>
Restarts the process with the internal ID <id>. The application gives a few seconds for the process to gracefully terminate. If the process cannot gracefully terminate within the given timeframe, it is forcibly terminated before starting it up again.
DELETE /
Shuts down the application asynchronously. The request will return and the graceful termination period will begin. By default, 10 seconds are allowed for each process to terminate gracefully before forceful termination, this time period can be modified though - see below.
keep_alive
By default, the pymanager process terminates if all processes are terminated. You can override this behaviour and keep the manager process running by setting keep-alive to true. This is useful if one or more processes can be restarted later without requiring the other processes which are defined.
graceful_time
The graceful_time option may be specified to control the amount of time given for each subprocess to terminate gracefully before forceful termination.
default_shell
The default_shell option defines the default shell to use for environment file operations and for processes with the ‘shell’ option set to true. This option defaults to ‘true’, which is the user default shell.
processes
Each process is an entry in the list of processes. A process requires an executable and arguments. The executable is, naturally, require and the arguments must be provided even if the process takes no arguments - in that case, as an empty list.
Optionally, options may be passed to the process launcher. Currently recognized options: * suppress_output, if set to true, the output of the process will not be displayed on standard output. By default, all process output is displayed. Mutually exclusive with suppress_output. * working_directory; if present, the working directory of the process is modified to the path provided. The path may be relative or absolute. Note that when searching for the executable, this working directory is not considered, and the executable will be searched for relative to the directory where you launched pymanager. * redirect_output specifies a filename. The file will receive all output generated by the process. Mutually exclusive with suppress_output. * environment_file specifies a filename. This file will be sourced and the resulting environment will be used as the environment for the process. This is a potentially dangerous operation, use with care. * shell may be ‘true’ or the name of a command to run as a shell (eg. bash, sh, zsh, etc.). If shell is simply set to true, the default_shell option from global settings will be used. Shell defaults to false, which means no shell is spawned under the process.
A process may also include a verifier. If the verifier key is present, the type must be provided. The type of the verifier must be loaded in the modules section and takes the form of ‘module.classname’. Optionally, you may provide a dictionary of arguments to pass to the keyword arguments of the initializer function of the verifier.
messages
Optionally, a list of message types (strings) may appear in the configuration under the key ‘messages’. This controls the verbosity of the output from the application. By default, no additional output is displayed. Currently, the following options are available:
process.exit - display message when a controlled process exits, along with the return code.
verifier.fail - display messages about verifier attempts failing.
verifier.verbose - display all (debug) messages from verifier, implies all other verifier options.
Signal response
The application will respond to SIGINT, SIGTERM and SIGQUIT the same way as if a DELETE / request was issued to its HTTP endpoint.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pymanager-0.2.6.1.tar.gz
.
File metadata
- Download URL: pymanager-0.2.6.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 446fea30376c08ee952ee6c51dd4c0ba05957e9f2f3847b33502473d8a0c94bb |
|
MD5 | 3d6d936e37df4d8ed680d9f37847ce8d |
|
BLAKE2b-256 | fd10ffaefc3200358a3934de7a758416d9ea7221b5d47d03ffec37a676d26526 |
File details
Details for the file pymanager-0.2.6.1-py3.4.egg
.
File metadata
- Download URL: pymanager-0.2.6.1-py3.4.egg
- Upload date:
- Size: 35.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06141bd1821f7cc28fa7d0f06cd4a336bb228df334a44b8b91d6215f918d9df6 |
|
MD5 | 75323810db766ced9fa2daf9fd80282a |
|
BLAKE2b-256 | 34bd8bc0f24e9368b0aec200d6ee7e6d4c3bed59f6c3345bd4764c849db1d970 |
File details
Details for the file pymanager-0.2.6.1-py3-none-any.whl
.
File metadata
- Download URL: pymanager-0.2.6.1-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7ad906fbd503cc75164c3128d33c4cada0357a210e1cb803552213d51f00f11 |
|
MD5 | 1a78f7396981ab5800b7a4218d2f2111 |
|
BLAKE2b-256 | 7d7ebe8cd05ca3329c3983addfa26efcce332573faba026e8ef2c6878f73497b |