Skip to main content

Ansible module to manage processes via PM2

Project description

Github Actions PyPI version Code style: black

ansible-modules-pm2

Ansible Module to Manage Processes via PM2

  • Manage the state of processes via pm2 process manager
  • Start/Stop/Restart/Reload/Delete applications

Tested on:

  • Host Python: 3.8
  • Target host Python: 2.7, 3.5, 3.6, 3.7, 3.8
  • Ansible: 2.8.10, 2.9.6 (Should work with older versions)

Installation

Install via pip:

pip install ansible-modules-pm2

PM2 package have to be installed to target hosts. For example, add following to your playbook to install pm2 globally:

- npm:
    name: pm2
    global: yes

Usage

Basic usage is similar to service or supervisorctl module: specify the name and its state. To start an app, give either script or config.

Examples

---
- name: Start myapp with process config file, if not running
  pm2:
    name: myapp
    config: /path/to/myapp/myapp.json
    state: started

- name: Start myapp.js, if not running
  pm2:
    name: myapp
    script: /path/to/myapp/myapp.js
    state: started

- name: Stop process named myapp, if running
  pm2:
    name: myapp
    state: stopped

- name: Restart myapp, in all cases
  pm2:
    name: myapp
    state: restarted

- name: Reload myapp, in all cases
  pm2:
    name: myapp
    state: reloaded

- name: Delete myapp, if exists
  pm2:
    name: myapp
    state: absent

- name: Specify pm2 executable path
  pm2:
    name: myapp
    state: started
    config: /path/to/myapp/myapp.json
    executable: /path/to/myapp/node_modules/.bin/pm2

- name: Also specify working directory where running pm2 command
  pm2:
    name: myapp
    state: started
    config: /path/to/myapp/myapp.json
    executable: /path/to/myapp/node_modules/.bin/pm2
    chdir: /path/to/working/directory

Arguments

Parameters Choices Comments
name (required) Name of the application.
Required for all cases to check current status of app
state started (default)
stopped
restarted
reloaded
absent
deleted
started/stopped/absent/deleted are idempotent actions that will not run commands unless necessary.
restarted will always restart the process.
reloaded will always reload.
Note that restarted will fail when the process does not exist (action does not start it automatically).
config Process configuration file, in JSON or YAML format.
Either config or script is required when state=started.
script Executalbe file to start.
Either config or script is required when state=started.
executable Path to pm2 executable.
chdir Change into this directory before running pm2 start command.
When state=started and this option is omitted, use the directory where config or script exists.

License

This software is licensed under GPLv3. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansible-modules-pm2-0.1.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

ansible_modules_pm2-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file ansible-modules-pm2-0.1.0.tar.gz.

File metadata

  • Download URL: ansible-modules-pm2-0.1.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for ansible-modules-pm2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 497a37c4eee46133b34528a11a3bf9637f7bcc2c6300a75543e644e0b9c3fffa
MD5 255b3cbb8a6e67ff7e47879fa3e76918
BLAKE2b-256 010bd052fe448789e51ca4886a9653e7aa0e093a619c1d05758b257a664b0182

See more details on using hashes here.

File details

Details for the file ansible_modules_pm2-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ansible_modules_pm2-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for ansible_modules_pm2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e18eff1379bc32149ca1a92ab8aef78e7c5531eeb7339d25eff68e9df2301e1
MD5 8833e68292d56923e456dc0c98dd9022
BLAKE2b-256 d31278872d9eb96716c8075c4627e1f97961ea38fb8a38669230e9182bdb2bba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page