Closed 4everinbeta closed 8 years ago
Hi, no, haven't tested it on centos 7. But seems that on c7 the service pm2-init.sh
doesn't exist. can u log into your centos 7 box and see how they named the service... maybe just pm2
!?
Looks like it's correct. Apparently, in centos 7 you need to reload the systemd daemon after creating/modifying the script.
I'm actually not entirely sure what service.yml does for me. If I do not run that step, when I log into the system the service is started and enabled. Am I missing something? (I apologize for my ignorance.)
will have a look at that on the weekend cause i'm currently on the road
service.yml
ensures the state of the service. i.e. if you want it to be running and started on reboot.
so is everything running then as expected or are you still getting the above error!? I tested centos 7 and it looks like the service name pm2-init.sh
is working...
BTW: have you set pm2_startup
to centos
?
Thanks Franklin. Everything is working well with service.yml commented-out in main. For some reason I have yet to determine, That one command fails. I still want to dig into it farther, but that will have to wait until I get this project complete. And yes, I did change that var to centos. Also tried systemd. Same result.
Thank you very much for you help!
On Mon, Feb 22, 2016 at 3:06 AM, franklin notifications@github.com wrote:
service.yml ensures the state of the service. i.e. if you want it to be running and started on reboot. so is everything running then as expected or are you still getting the above error!? I tested centos 7 and it looks like the service name pm2-init.sh is working...
BTW: have you set pm2_startup to centos?
— Reply to this email directly or view it on GitHub https://github.com/weareinteractive/ansible-pm2/issues/8#issuecomment-187105752 .
ok, I'll close this one then for now. Please reopen if you find sth new.
If you're using systemd
you'll need to change the service name that has been added, see #9
Hi @franklinkim, @4everinbeta, and anyone having this issue with Centos 7:
I am customizing this playbook for Centos 7 as well and wanted to chip in the couple of changes I had to make:
The service created is actually with the name form pm2-{{pm2_user}}
in systemctl. Which in most cases will be equivalent to pm2-{{ansible_user_id}}
since in defaults we set pm2_user: {{ansible_user_id}}
. In our case, this will be pm2-centos
or pm2-vagrant
when we are testing on Vagrant.
If the task fails in the service.yml, it will still create the above service as long as all previous steps succeed.
To make the service task pass in service.yml, I simply set this in defaults/main.yml:
# service name for startup system
pm2_service_name: pm2-{{ ansible_user_id }}
That's one way to make the service.yml playbook pass.
The other minor problem was in install.yml with the Install startup script step
. Since I am not running the playbook as root, I am using a workaround for setting startup script for pm2 and I changed the last step into two steps:
- name: Get the default node version
shell: >
node --version
register: pm2_default_node_version
- name: Installing startup script
command: "sudo env PATH=$PATH:{{ pm2_user_home.stdout }}/.nvm/versions/node/{{pm2_default_node_version.stdout}}/bin pm2 startup systemd -u {{ pm2_user }} --hp {{ pm2_user_home.stdout }}"
Everything works on centos 7 with these two changes for me. @franklinkim 🥇 Thank you for the great playbook!
@Cryptophobia thanks for sharing!
I also needed a small workaround (Ubuntu 16.04). When requesting the systemd services on the target host with 'systemctl list-unit-files | grep enabled' I found out the name for me was: pm2-{{pm2_user}}.service. I updated pm2_service_name accordingly and it started working. The differences might have to do with the options for pm2 startup? http://pm2.keymetrics.io/docs/usage/startup/ Mine was using systemd. It might become more consistent when specifying one type at install.yml like systemd? command: "pm2 startup systemd -u {{ pm2_user }} --hp {{ pm2_user_home.stdout }}"
@thomasBla : Yes, I think when installing the pm2 startup scripts it will be best to specify the type of startup daemon: like systemd
for example:
- name: Installing startup script
command: "sudo env PATH=$PATH:{{ pm2_user_home.stdout }}/.nvm/versions/node/{{pm2_default_node_version.stdout}}/bin pm2 startup systemd -u {{ pm2_user }} --hp {{ pm2_user_home.stdout }}"
I have recently begun an upgrade to centos 7 from an amazon-linux flavor of centos 6. When I run this ansible role I now receive the following error that I do not receive on 6:
fatal: [127.0.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "systemd could not find the requested service \"'pm2-init.sh'\": "}
I'm trying to find what the difference is. Wondering if you have tested against centos 7 yet? If I find the resolution in the meantime I will post it here.