如何将 rails 服务器和机器人与 procfile 和工头一起使用?

How to use rails server and bot with procfile and foreman?

我正在尝试 运行 我的 rails serverslackbot 在两个过程中使用 Procfilegem 'foreman'

但是当我使用 foreman start 时,机器人只是 运行 宁服务器没有启动。我尝试删除 line bot 并尝试仅 运行 web 但在那种情况下,我的服务器也没有启动它只显示 started with pid 1502。但是当我使用 rails s 从另一个终端启动它时,它启动没有问题。我在谷歌上搜索了很多,似乎无法找到解决方案。非常感谢您的帮助。谢谢。

这是我的 Procfile :

web: bundle exec rails server -p $PORT
bot: rails runner -e development slackbot/slack.rb

尝试以下配置:

web: bundle exec rails server -p 3000
bot: rails runner -e development slackbot/slack.rb

然后运行foreman start -f Procfile(或者你添加的文件名)

访问:http://localhost:3000

平时我喜欢用screen命令在后台打开foreman进程,不过这里不需要...好像是:screen foreman start -f Procfile然后直接ctrl+A+D就可以了在后台分离和进程 运行。这对于 SSH 连接很有用,例如 EC2 实例。

听起来您可能需要指定端口,或者设置环境变量 PORT:

export PORT=3000
foreman start

或硬编码Procfile中的端口:

web: bundle exec rails server -p 3000

或删除 -p 选项,在这种情况下将使用默认端口:

web: bundle exec rails server