Scenario / Questions
I’m using Ansible to create a pm2 service on a EC2 / Ubuntu instance. Below is the script. When I run it, PM2 is installed and the service is enabled. When I run pm2 list, I don’t the see the service, but I can grep it (ps aux | grep node) and see that it’s running. It also seems like a shadow copy of pm2 is running and loading the app, but I can’t seem to control it.
- hosts: comm sudo: yes tasks: - npm: name=pm2 global=yes - name: configure pm2 to restart on startup shell: pm2 startup ubuntu >& /dev/null chdir=~/ executable=/bin/bash sudo: yes sudo_user: root - command: sudo env PATH=$PATH:/usr/bin pm2 startup ubuntu -u ubuntu sudo: yes - command: /usr/bin/pm2 save - command: /usr/bin/pm2 start /home/ubuntu/something/app.js --name something
Find below all possible solutions or suggestions for the above questions..
This playbook is not idempotent, the
shell task is going to run every time the playbook is run, you need to supply a
creates argument to that task.
In the current version of PM2:
var scriptFile = '/etc/init.d/pm2-init.sh', script = cst.UBUNTU_STARTUP_SCRIPT;
Also, the use of
sudo is redundant, as it is already specified globally above, and the default is to
root, so that’s redundant as well.
Additionally, once there’s an
init script for the service, it would be better to use the
service module to manage it.
Kubernetes Free Online Tutorial, Kubernetes Beginner Tutorial
DevOps Free Online Tutorial, DevOps Beginner Tutorial
Ansible Free Online Tutorial, Ansible Beginner Tutorial
Docker Free Online Tutorial, Docker Beginner Tutorial
Openstack Free Online Tutorial, Openstack Beginner Tutorial
Disclaimer: This has been sourced from a third party syndicated feed through internet. We are not responsibility or liability for its dependability, trustworthiness, reliability and data of the text. We reserves the sole right to alter, delete or remove (without notice) the content in its absolute discretion for any reason whatsoever.