Rails 中带有 .env 文件的 Foreman 条件过程
Foreman conditional process with .env file in Rails
我在 Ruby 上的 Rails 应用程序上使用工头 gem 来启动我的不同进程。
在 .env 文件中,我声明了一些布尔变量来决定我是否要 运行 一个进程。
我希望能够启用或禁用«maildev»,这是一个在本地处理电子邮件的 nodejs 应用程序。如果布尔值是 true,它工作得很好,但如果将它更改为 false,工头在启动时崩溃。
这是工头的踪迹:
13:20:17 web.1 | started with pid 6583
13:20:17 mailer.1 | started with pid 6584
13:20:17 mailer.1 | ====== Maildev server not launched ======
13:20:17 mailer.1 | exited with code 0
13:20:17 system | sending SIGTERM to all processes
13:20:17 web.1 | terminated by SIGTERM
我的 .env 文件:
RACK_ENV=development
START_MAILDEV=false
我的 Procfile:
# Rails server
web: bin/procfile/web
# Mail server
mailer: bin/procfile/maildev
bin/procfile/maildev:
#!/bin/sh
if [[ "$RACK_ENV" == 'development' ]]; then
if [[ "$START_MAILDEV" == "true" ]]; then
maildev
echo "====== Maildev server launched ======"
else
echo "====== Maildev server not launched ======"
fi
fi
有人知道我的代码有什么问题吗?
谢谢!
您的代码没有问题,但是当您的一个进程退出时,echo
会立即退出,Foreman 会关闭所有其余进程。
Foreman 批准的 运行 只有一些流程的方法是 the -c
flag。
-c, --concurrency
Specify the number of each process type to run. The value passed in should be in the format process=num,process=num
在你的情况下,
foreman start -c web=1
如果你有很多进程并且你想 运行 它们全部 除了一个 ,有一个特殊的 all
关键字,然后你可以覆盖你不想要的那个。
foreman start -c all=1,maildev=0
我在 Ruby 上的 Rails 应用程序上使用工头 gem 来启动我的不同进程。 在 .env 文件中,我声明了一些布尔变量来决定我是否要 运行 一个进程。
我希望能够启用或禁用«maildev»,这是一个在本地处理电子邮件的 nodejs 应用程序。如果布尔值是 true,它工作得很好,但如果将它更改为 false,工头在启动时崩溃。
这是工头的踪迹:
13:20:17 web.1 | started with pid 6583
13:20:17 mailer.1 | started with pid 6584
13:20:17 mailer.1 | ====== Maildev server not launched ======
13:20:17 mailer.1 | exited with code 0
13:20:17 system | sending SIGTERM to all processes
13:20:17 web.1 | terminated by SIGTERM
我的 .env 文件:
RACK_ENV=development
START_MAILDEV=false
我的 Procfile:
# Rails server
web: bin/procfile/web
# Mail server
mailer: bin/procfile/maildev
bin/procfile/maildev:
#!/bin/sh
if [[ "$RACK_ENV" == 'development' ]]; then
if [[ "$START_MAILDEV" == "true" ]]; then
maildev
echo "====== Maildev server launched ======"
else
echo "====== Maildev server not launched ======"
fi
fi
有人知道我的代码有什么问题吗?
谢谢!
您的代码没有问题,但是当您的一个进程退出时,echo
会立即退出,Foreman 会关闭所有其余进程。
Foreman 批准的 运行 只有一些流程的方法是 the -c
flag。
-c, --concurrency
Specify the number of each process type to run. The value passed in should be in the format process=num,process=num
在你的情况下,
foreman start -c web=1
如果你有很多进程并且你想 运行 它们全部 除了一个 ,有一个特殊的 all
关键字,然后你可以覆盖你不想要的那个。
foreman start -c all=1,maildev=0