I would like to start my node.js app in an ansible playbook. Right now, the final directive looks like this:
- name: start node server
shell: chdir=${app_path} npm start&
The problem is that ansible never returns from this. How can I make it continue?
Forever seems to be the simplest and easiest way of starting and daemonizing Node.js apps. Currently, there's no Ansible module for forever, but you can still use the following plays to install forever and run your app:
- name: "Install forever (to run Node.js app)."
npm: name=forever global=yes state=present
- name: "Check list of Node.js apps running."
command: forever list
register: forever_list
changed_when: false
- name: "Start example Node.js app."
command: forever start /path/to/app.js
when: "forever_list.stdout.find('/path/to/app.js') == -1"
This is completely idempotent, and works great for me. You could program a little forever
module for Ansible to do this stuff for you (like the service
module), but this works for now.
I have a complete example of how to start a Node.js app with Forever and Ansible on Server Check.in's blog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With