Skip to content

keygen-sh/example-python-machine-heartbeats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Example Machine Activation Heartbeats

This is an example of a typical node-locked or floating machine activation flow written in Python, utilizing a machine hearbeat monitor to automatically deactivate the machine in the event that the normal deactivation procedure fails.

Running the example

First up, configure a few environment variables:

# A Keygen activation token for the given license. You can generate an
# activation token per-license via the API or your admin dashboard.
export KEYGEN_ACTIVATION_TOKEN="A_KEYGEN_ACTIVATION_TOKEN"

# Your Keygen account ID. Find yours at https://app.keygen.sh/settings.
export KEYGEN_ACCOUNT_ID="YOUR_KEYGEN_ACCOUNT_ID"

You can either run each line above within your terminal session before starting the app, or you can add the above contents to your ~/.bashrc file and then run source ~/.bashrc after saving the file.

Next, install dependencies with pip:

python3 -m pip install -r requirements.txt

To perform a machine activation, run the program with a license key:

python3 main.py some-license-key-here

The script will use a SHA256-HMAC of your device's machineid for the machine's fingerprint during activation. Upon activation, a heartbeat monitor will be started for the activated machine.

If you exit the process, the machine will be deactivated.

If you kill the process, the heartbeat monitor will automatically deactivate the machine after the heartbeat window has been reached.

Questions?

Reach out at [email protected] if you have any questions or concerns!