流浪汉上的PM2-挂载共享文件夹后启动应用程序 [英] PM2 on vagrant - starting app AFTER shared folder is mounted

查看:81
本文介绍了流浪汉上的PM2-挂载共享文件夹后启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在挂载共享目录后将PM2设置为启动应用程序?默认情况下,pm2 startup添加脚本,该脚本尝试在OS引导后立即运行脚本,这会导致程序错误(因为此时尚未安装该文件夹).

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).

推荐答案

您可以在Vagrantfile中添加以下行

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

了解有关 shell配置的信息:

  • 内联(字符串)-指定要在远程计算机上执行的内联Shell命令.
  • inline (string) - Specifies a shell command inline to execute on the remote machine.

在ssh进入框中时,您将在其中输入命令行的地方输入

This is where you will enter the command lines as you enter them when you ssh into the box

  • privileged(布尔值)-指定是否以特权用户身份执行Shell脚本(sudo).默认情况下,这是"true".
  • privileged (boolean) - Specifies whether to execute the shell script as a privileged user or not (sudo). By default this is "true".

根据您的情况,将其设置为false,以便无业游民的用户运行此命令

In your case, set to false so vagrant user will run this command

默认情况下,除非自上次设置--provision标志起,否则自从最后一个vagrant destroy起的第一个无所事事期间,预配器仅运行一次.

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.

(可选),您可以配置预配器以在每个upreload上运行.仅在显式指定--no-provision标志的情况下,它们才会运行.为此,请将run选项设置为始终"

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"

设置为always,以便在您启动VM时随时启动pm2

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

这篇关于流浪汉上的PM2-挂载共享文件夹后启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆