简体   繁体   English

在Rails服务器完全由领班启动之后,如何启动Procfile进程?

[英]How can I start a Procfile process, after the rails server has completely started up with foreman?

I have a rails app that runs on parallel with a ruby script. 我有一个与Ruby脚本并行运行的Rails应用程序。 This is script is a ruby-mqtt subscriber, basically it listens for messages over the mqtt protocol and then interacts with the rails app. 这是一个脚本,是ruby-mqtt订阅者,基本上,它通过mqtt协议侦听消息,然后与Rails应用程序交互。

The problem is that foreman starts this process simultaneously with the rails server and when there are messages being broadcast and the server has not finished it's startup process, the script crashes, and foreman kills the server with it. 问题是,领班与rails服务器同时启动此过程,并且当广播消息且服务器尚未完成启动过程时,脚本崩溃,领班也随之杀死服务器。

This is the example Procfile: 这是Procfile示例:

server: rails s -p 3000 -b 0.0.0.0
mqtt_subscriber: ruby ./mqtt/subscribers/mqtt_subscriber.rb

The current workaround is to run the rails server and when it finishes start up, launch the subscriber from another terminal or using screen. 当前的解决方法是运行rails服务器,并在完成启动后,从另一个终端或使用屏幕启动订户。

Is there a way to run the subscriber processes after the server has completely started through foreman start? 服务器通过工头启动完全启动后,是否可以运行订户进程?

You can use the wait-for-it bash script to wait for a tcp port to become available, before the mqtt subscriber starts 在mqtt订户启动之前,您可以使用wait-it-bash脚本来等待tcp端口可用。

server: rails s -p 3000 -b 0.0.0.0
mqtt_subscriber: wait-for-it.sh -t 0 localhost:3000 -- ruby ./mqtt/subscribers/mqtt_subscriber.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM