node.js process manager provisioning + orchestration(?)

Hi all,

I’m responsible for prepping some node.js services for provisioning + orchestration. Along the way, the engineering team passed along a default of pm2.

Looking at how it’d be provisioned, it’d be more interesting than a coworker and I particularly care for. Our goal is to have an /etc/init.d script to allow us to start/stop/restart through the service module. pm2 seems to want a bit more handholding to do its magic, so it’s not feeling like a particularly good fit.

I’m wondering if anyone on list has experience provisioning + orchestrating node.js services through Ansible and, if so, what particular node.js or agnostic process managers were used.

Thanks in advance,

Nathan L. Walls

Hi Nathan,

We are working on a nodejs stack with pm2

So far we came up with writing a pm2 module for managing processes.
far from finished but working rudimentary:
https://gist.github.com/aikomastboom/8859290

We are using nave to install node on our environments
https://github.com/isaacs/nave/blob/master/nave.sh

below tasks can probably be cleaned a lot, for us, at this time, it does what it needs to do:

  • name: install nave
    copy: src=nave.sh dest=/usr/bin/nave mode=0755
    sudo: yes

  • name: get and store the nave prefix path for future reference
    shell: nave use {{node_version}} npm config get prefix 2>/dev/null
    register: raw_nave_prefix
    sudo: no

  • name: set string value for nave prefix
    set_fact:
    nave_prefix: “{{raw_nave_prefix.stdout}}”
    sudo: no

  • name: get and store the node path for future reference
    shell: nave use {{node_version}} env 2>/dev/null |grep NODE_PATH |sed -e ‘s/NODE_PATH=//’
    register: node_path
    sudo: no

  • name: set the various paths
    set_fact:
    npm_binary: “{{nave_prefix}}/bin/npm”
    sudo: no

  • name: ensure pm2 installed
    npm: executable={{npm_binary}} name=pm2 state=present global=yes
    sudo: no

  • name: ensure a dump exists before creating init script
    action: pm2.py command=dump persist=true use_nave=true node_version={{node_version}}

  • name: installing pm2 to init.d
    raw: HOME={{home}} PATH={{ansible_env.PATH}}:{{home}}/.nave/installed/{{node_version}}/bin pm2 startup {{ansible_distribution}} -u {{user}}
    sudo: yes