PM2 on vagrant - starting app AFTER shared folder is mounted

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

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 or reload. They will only be not run if the --no-provision flag is explicitly specified. To do this set the run 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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!