Skip to main content
# jasper-sys [![Build Status](https://travis-ci.org/fabiocody/jasper-sys.svg?branch=master)](https://travis-ci.org/fabiocody/jasper-sys)


## Overview

Jasper is a system designed to supervise your programs that need to be kept running.
For example, let's say you have a set of scripts for your smart home system. Of course you don't want these scripts to stop working, otherwise your smart home system would act weirdly, or not work at all. Jasper can help you keep the scripts running and you can also set up some custom actions to be executed when the state of a process changes (e.g. for notification or logging).


## Installation

Execute this in a terminal window. Since Jasper is written to work only with Python 3.4+, you have to use the right version of `pip` (normally `pip3` should work).
```
sudo pip3 install jasper-sys
```


## Get started

Every program that has to be controlled by Jasper is called __module__. To get started, you have to create a JSON file to store all of your modules information. Since you're going to pass the file path to the program, you can name it whatever you want, and place it wherever you like.
Here's an example of what it should look like

```json
{
"module_name": {
"command": "/path/to/executable arg1 arg2",
"start_on_boot": true,
"restart_on_crash": true
}
}
```

In the `command` field you have to enter the complete call to your program, as if you were calling it from a terminal window (full paths are highly recommended). The `start_on_boot` and `restart_on_crash` fields indicate respectively if you want your program to be started as soon as Jasper starts, and if you want your program to be restarted when it crashes.

Next, you're going to create a script to get everything up and tuned the way you want.
Here's an example

```python
from jaspercore import JasperCore
from datetime import datetime

def log_restart(module):
'''Log a message when a module restarts'''
with open('/path/to/logfile', 'a') as f:
f.write('{0} - {1} restarted.'.format(datetime.now(), module))

def log_start_failure(module):
'''Log a message when a module fails to start'''
with open('/path/to/logfile', 'a') as f:
f.write('{0} - {1} failed to start.'.format(datetime.now(), module))

callback_table = {
'restart': log_restart,
'exec_fail': log_start_failure
}

JasperCore('/path/to/modules.json', callback_table=callback_table, start_all=True)
```

The `JasperCore` class is the main interface to Jasper system. All you need to do to start the system is calling it. The class takes 4 arguments:
- `modules_file <str>`: the path to the JSON file;
- `callback_table <dict> (optional)`: dictionary of type {str: function} (see below for more information);
- `start_all <bool> (optional, default=False)`: flag to indicate if you want all your enabled modules to be started when the system starts;
- `restarts_no <int> (optional, default=-1)`: maximum number of restarts for each module (-1 = inf).


### Callback table

You can provide some callbacks to be executed at certain points of a module's lifecycle. Every callback needs to be a function taking only one argument, i.e. the module name.
The available callback entries are:
- `start`: executed when a module starts;
- `restart`: executed when a module restarts;
- `stop_restart`: executed when you reach the maximum number of restarts;
- `exec_fail`: executed when the module fails to start.

You don't have to create a callback for every available entry, just the ones you need. The listed entries must be used as the keys of the dictionary you're going to provide to the `JasperCore` class.


## jasperctl

`jasperctl` is a remote interface to the core system.
If you are on the machine Jasper core is running, simply type `jasperctl` in a terminal window. If you are on a remote machine, type `jasperctl -c host` to connect to the remote Jasper core.
Once you are connected to a Jasper core session, you can
- check which modules are running and which are not;
- start/stop modules.


## Contribution

If you like to contribute, please open an issue.

Metadata

Release files for jasper-sys 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jasper-sys 0.2.4
File Size Uploaded Provenance Actions
jasper-sys-0.2.4.tar.gz 6.3 kB Without provenance Details for jasper-sys-0.2.4.tar.gz

Release files / jasper-sys-0.2.4.tar.gz

Download URL jasper-sys-0.2.4.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d7006589571f40b7cb5708c995179bb68ae37fe48f96ab343fea6614d62a28b1
BLAKE2b-256 checksum
How to use checksums
6340ce4624b4db9e13a3d680d8b13ac54b96a527646b6172715a85158d655e13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for jasper-sys 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page