# node.js process manager provisioning + orchestration(?)

**URL:** <https://forum.ansible.com/t/node-js-process-manager-provisioning-orchestration/14516>\
**Category:** Ansible Project\
**Created:** [February 7, 2014, 2:24am UTC](https://forum.ansible.com/t/node-js-process-manager-provisioning-orchestration/14516 "2014-02-07T02:24:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Walls](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@Nathan\_Walls](https://forum.ansible.com/u/Nathan_Walls)\
**Post date:** [February 7, 2014, 2:24am UTC](https://forum.ansible.com/t/node-js-process-manager-provisioning-orchestration/14516/1 "2014-02-07T02:24:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aiko\_Mastboom](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Aiko\_Mastboom](https://forum.ansible.com/u/Aiko_Mastboom)\
**Post date:** [February 7, 2014, 9:00am UTC](https://forum.ansible.com/t/node-js-process-manager-provisioning-orchestration/14516/2 "2014-02-07T09:00:19Z")

</div>

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](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](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
