I installed pm2 in Vagrant using the latest ubunty/trusty64 box. I installed NodeJS v4.4.0 and NPM 2.14.20 using NVM. I use pm2 version 1.0.2.
I have 5 node scripts running in fork mode. I originally started them using
pm2 start --name [service_name] [path_to_script]
I then saved the configuration using:
pm2 save
And next I generated the startup script:
sudo pm2 startup ubuntu -u vagrant
I see the following output:
[PM2] Generating system init script in /etc/init.d/pm2-init.sh
[PM2] Making script booting at startup...
[PM2] -ubuntu- Using the command:
su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"
Adding system startup for /etc/init.d/pm2-init.sh ...
/etc/rc0.d/K20pm2-init.sh -> ../init.d/pm2-init.sh
/etc/rc1.d/K20pm2-init.sh -> ../init.d/pm2-init.sh
/etc/rc6.d/K20pm2-init.sh -> ../init.d/pm2-init.sh
/etc/rc2.d/S20pm2-init.sh -> ../init.d/pm2-init.sh
/etc/rc3.d/S20pm2-init.sh -> ../init.d/pm2-init.sh
/etc/rc4.d/S20pm2-init.sh -> ../init.d/pm2-init.sh
/etc/rc5.d/S20pm2-init.sh -> ../init.d/pm2-init.sh
[PM2] Done.
At this point all scripts run properly.
Next when I reboot the VM and use pm2 list I see the following output:
โโโโโโโโโโโโโโโโโโโฌโโโโโฌโโโโโโโฌโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโโโ
โ App name โ id โ mode โ pid โ status โ restart โ uptime โ memory โ watching โ
โโโโโโโโโโโโโโโโโโโผโโโโโผโโโโโโโผโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโค
โ movindev_data โ 0 โ fork โ N/A โ errored โ 0 โ 0 โ 0 B โ disabled โ
โ movindev_wmts โ 1 โ fork โ N/A โ errored โ 0 โ 0 โ 0 B โ disabled โ
โ movindev_wrs โ 2 โ fork โ N/A โ errored โ 0 โ 0 โ 0 B โ disabled โ
โ movindev_was โ 3 โ fork โ N/A โ errored โ 0 โ 0 โ 0 B โ disabled โ
โ movindev_portal โ 4 โ fork โ N/A โ errored โ 0 โ 0 โ 0 B โ disabled โ
โโโโโโโโโโโโโโโโโโโดโโโโโดโโโโโโโดโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโ
As you can see all nodejs processes quit with an errored state. Viewing the logs at /home/vagrant/.pm2/pm2.log shows the following exception:
2016-03-22 14:02:49: Error: spawn node ENOENT
at exports._errnoException (util.js:870:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickDomainCallback (node.js:397:17)
Interestingly enough when I do pm2 restart all all scripts start properly. This only goes wrong after a reboot.
Does anyone know what I can do to fix this?
I faced issue like this also.
This issue related to the vagrant folder mounting.
I prefer use provision:
https://www.vagrantup.com/docs/cli/provision.html
config.vm.provision "shell", path: "your_script_path_in_your_localmachine", run: "always", privileged: true
it works for me.
Well described solution is available here:
http://stackoverflow.com/questions/38202390/pm2-on-vagrant-starting-app-after-shared-folder-is-mounted
Most helpful comment
I faced issue like this also.
This issue related to the vagrant folder mounting.
I prefer use provision:
https://www.vagrantup.com/docs/cli/provision.html
it works for me.