How can I set PM2 to start the app after the shared directories get mounted? By default pm2 startup
adds script which try to run script right after OS boot, which causes program error (because the folder is not yet mounted by that time).
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
由
翻译强力驱动
问题:
回答1:
you can add the following line in your Vagrantfile
config.vm.provision :shell, :inline => "pm2 start /vagrant/project/server/index.js && pm2 startup", :run => 'always', privileged: false
read about shell provisioning :
- inline (string) - Specifies a shell command inline to execute on the remote machine.
This is where you will enter the command lines as you enter them when you ssh into the box
privileged
(boolean) - Specifies whether to execute the shell script as a privileged user or not (sudo). By default this is "true".
In your case, set to false
so vagrant user will run this command
By default, provisioners are only run once, during the first vagrant up since the last
vagrant destroy
, unless the--provision
flag is set, as noted above.Optionally, you can configure provisioners to run on every
up
orreload
. They will only be not run if the--no-provision
flag is explicitly specified. To do this set therun
option to "always"
setting as always
so it pm2 will kick off anytime your boot your VM
If you want to run multiple commands you can also write it like
config.vm.provision "shell", run: "always", privileged: false, inline: <<-SHELL pm2 start /vagrant/project/server/index.js pm2 startup .... any command that you want to execute .... SHELL