weareinteractive.pm2

Ansible weareinteractive.pm2 Role

Build Status Galaxy GitHub Tags GitHub Stars

weareinteractive.pm2 is an Ansible role that:

  • Installs pm2
  • Manages JSON applications
  • Configures the service

Installation

You can install it using ansible-galaxy:

$ ansible-galaxy install weareinteractive.pm2

Or you can add it to your requirements.yml:

- src: weareinteractive.pm2

Alternatively, clone it using git:

$ git clone https://github.com/weareinteractive/ansible-pm2.git weareinteractive.pm2

Dependencies

  • Requires Ansible version 2.4 or higher.
  • Node.js must be installed, for example, using the weareinteractive.nodejs role.

Note:

This role has been moved from franklinkim.pm2 to weareinteractive.pm2 because Ansible Galaxy now supports organizations.

Variables

Here are the default variables you can find in defaults/main.yml:

---
# pm2_cmds:
#   - run: sendSignal             # pm2 command name
#     args: SIGUSR2 my-app        # optional arguments to pass
#     path: /var/www/myapp        # optional change directory path
#     ignore_errors: yes          # optional: do not fail on pm2 errors
#     env:                        # optional: environment settings
#       NODE_ENV: production
# pm2_apps:
#   - run: pm2.json               # you can also run a .js file like app.js
#     cmd: start                  # optional command to run on the app
#     args: --name console_error  # optional arguments to pass
#     path: /var/www/myapp        # optional change directory path
#     env:                        # optional: environment settings
#       NODE_ENV: production
# pm2_post_cmds:
#   - run: save                   # pm2 command name
#     args:                       # optional arguments to pass
#     path: /var/www/myapp        # optional change directory path
#     ignore_errors: yes          # optional: do not fail on pm2 errors
#     env:                        # optional: environment settings
#       NODE_ENV: production
#

# List of commands to run
# These will be executed before managing apps
pm2_cmds:
  # Note: delete all apps initially on every run so only configured apps exist
  - run: delete all
# Default environment to run commands
pm2_cmds_default_env: {}
# List of post commands to run
# These will be executed after managing apps
pm2_post_cmds: []
# Default environment to run post commands
pm2_post_cmds_default_env: {}
# List of paths to JSON app declarations
pm2_apps: []
# Default environment to run apps
pm2_apps_default_env: {}
# Default command to run on the apps
pm2_apps_default_cmd: start
# Delete all apps initially on every run
pm2_apps_delete_all: yes
# Install Upstart
pm2_upstart: yes
# Start on boot
pm2_service_enabled: yes
# Service name for the startup system
pm2_service_name: pm2-init.sh
# Current state can be started or stopped
pm2_service_state: started
# Version
pm2_version:
# User to run pm2 commands
pm2_user: "{{ ansible_user_id }}"
# Startup platform
pm2_platform:

Handlers

These handlers are defined in handlers/main.yml:

---

- name: restart pm2
  service:
    name: "{{ pm2_service_name }}"
    state: restarted
  when: pm2_upstart and pm2_service_state != 'stopped'

- name: reload pm2
  service:
    name: "{{ pm2_service_name }}"
    state: reloaded
  when: pm2_upstart and pm2_service_state != 'stopped'

- name: update pm2
  shell: pm2 update
  when: pm2_upstart and pm2_service_state != 'stopped'

Usage

Here is an example playbook:

---

- hosts: all
  become: yes
  roles:
    - weareinteractive.pm2
  vars:
    # For Vagrant
    # pm2_upstart: yes
    # pm2_user: vagrant
    # pm2_service_name: pm2-vagrant
    # For Docker
    pm2_user: root
    pm2_upstart: no # No service support within Docker
    # Common
    pm2_cmds:
      - run: delete
        args: console_error
        ignore_errors: yes
    pm2_apps:
      - run: apps.json
        path: "/etc/ansible/roles/weareinteractive.pm2/tests"
        cmd: startOrGracefulReload
      - run: console_error.js
        args: --name console_error
        path: "/etc/ansible/roles/weareinteractive.pm2/tests/apps"
        cmd: start
        env:
          NODE_ENV: dev
    pm2_apps_default_env:
      NODE_ENV: production

Testing

To run tests, clone the repository and use:

$ git clone https://github.com/weareinteractive/ansible-pm2.git
$ cd ansible-pm2
$ make test

Contributing

To contribute, please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.

Note: To update the README.md file, please install and run ansible-role:

$ gem install ansible-role
$ ansible-role docgen

License

Copyright (c) We Are Interactive under the MIT license.

Informazioni sul progetto

Installs pm2 and manages apps

Installa
ansible-galaxy install weareinteractive.pm2
Licenza
mit
Download
30.6k
Proprietario