当我启动 Rails 服务器时自动运行 Faye 服务器

发布于 2024-11-16 15:38:29 字数 367 浏览 2 评论 0原文

目前,Faye 正在使用我的 Rails 3.0.9 应用程序。不过,我的终端中打开了两个单独的选项卡。一种用于 Faye 服务器,一种用于 Rails 服务器。如何集成它们并在 Rails 启动时自动运行 Faye 服务器?

要启动 Faye 服务器,我正在运行:

rackup faye.ru -s thin -E production

faye.ru

require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/faye')
run faye_server

如果您需要更多信息,请告诉我。

I currently have Faye working with my Rails 3.0.9 application. However I have two separate tabs open in my terminal. One for the Faye server, and one for the Rails server. How can I integrate them and automatically run the Faye server when Rails starts up?

To start the Faye Server, I am running:

rackup faye.ru -s thin -E production

faye.ru

require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/faye')
run faye_server

Please let me know if you need any more information.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

め可乐爱微笑 2024-11-23 15:38:29

只需创建一个包含以下内容的初始值设定项:

Thread.new do
  system("rackup faye.ru -s thin -E production")
end

更好的选项:

使用 https://github.com/FooBarWidget/daemon_controller

Simply create an initializer containing:

Thread.new do
  system("rackup faye.ru -s thin -E production")
end

Better option:

Use https://github.com/FooBarWidget/daemon_controller

花桑 2024-11-23 15:38:29

如今,我只需使用 Foreman 即可: https://github.com/ddollar/foreman

创建一个 Procfile,您可以指定需要运行哪些守护进程(可以控制每个守护进程的数量),并将所有内容保留在一个终端窗口中(每个进程都有很好的颜色编码)。如果您的环境基于 debian,它甚至可以导出到 upstart 或 init.d 脚本以进行生产。

一旦你的 Procfile 全部设置完毕,那么你需要做的就是运行:foreman start 然后你就可以开始比赛了。我将它用于 resque 和 faye。

Nowadays, I'd just use Foreman for this: https://github.com/ddollar/foreman

By creating a Procfile, you can specify which daemons need to run (with control for how many of them of each you want), and keeps everything in one terminal window (with great color coding of each process). It can even export to upstart or init.d scripts for production, if your environment is debian based.

Once your Procfile is all set up, then all you need to do is run: foreman start and you're off to the races. I use it for resque and faye.

信仰 2024-11-23 15:38:29

在 Ubuntu 上,您应该使用操作系统的 init 系统 - Upstart。

user@host:~$ cat /etc/init/faye.conf 
description "Faye Upstart script"

start on startup
stop on shutdown

respawn

script
    env RAILS_ENV=production

    exec sudo -u deployuser -i /home/deployuser/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/bin/rackup /var/www/booko.com.au/booko/faye.ru -s thin -E production
end script 

我对调用 Ruby 的方法不满意,因为它会改变。但优点是它会在系统启动时启动,如果它死了或者你杀死它它会重生。

让 Upstart 负责妖魔化流程并确保其持续运行。

On Ubuntu, you should use the operating systems's init system - Upstart.

user@host:~$ cat /etc/init/faye.conf 
description "Faye Upstart script"

start on startup
stop on shutdown

respawn

script
    env RAILS_ENV=production

    exec sudo -u deployuser -i /home/deployuser/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/bin/rackup /var/www/booko.com.au/booko/faye.ru -s thin -E production
end script 

I'm not happy with the method of calling Ruby since it will change. But the advantages are that it will start when the system starts and it will respawn if it dies or you KILL it.

Let Upstart take care of demonising a process and making sure it keeps running.

一萌ing 2024-11-23 15:38:29

我在 config/thin_example.sh 中编写了这个 shell 脚本,

#!/bin/sh

set -e

# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/example/current
PID=$APP_ROOT/tmp/pids/thin.pid
CMD="cd $APP_ROOT; bundle exec rackup -D -P $PID $APP_ROOT/config/faye.ru -s thin -E     production"
AS_USER=deployer
set -u

startme() {
    run "$CMD"
}

stopme() {
    run "pkill -f $PID"
}

run () {
  if [ "$(id -un)" = "$AS_USER" ]; then
    eval $1
  else
    su -c "$1" - $AS_USER
  fi
}

case "$1" in
    start)   startme ;;
    stop)    stopme ;;    
    restart) stopme; startme ;;
    *) echo "usage: $0 start|stop|restart" >&2
       exit 1
       ;;
esac

该脚本是根据 Ryan Bates 在他的 VPS 部署railscast(仅限专业版)

使其可执行

chmod +x config/thin_example.sh

您需要将其符号链接到 init.d (在 chmod +x 'ing 使其可执行之后)

sudo ln -nfs /home/deployer/apps/example/current/config/thin_example.sh /etc/init.d/thin_example

然后,如果您希望它与服务器一起启动,

 sudo update-rc.d thin_example defaults

否则您应该能够 /etc/init .d/thin_example [开始|停止|重新启动]。需要注意的重要一点是,我告诉rackup以守护进程模式(-D)启动并显式设置PID,以便稍后可以杀死它。

I wrote this shell script in config/thin_example.sh

#!/bin/sh

set -e

# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/example/current
PID=$APP_ROOT/tmp/pids/thin.pid
CMD="cd $APP_ROOT; bundle exec rackup -D -P $PID $APP_ROOT/config/faye.ru -s thin -E     production"
AS_USER=deployer
set -u

startme() {
    run "$CMD"
}

stopme() {
    run "pkill -f $PID"
}

run () {
  if [ "$(id -un)" = "$AS_USER" ]; then
    eval $1
  else
    su -c "$1" - $AS_USER
  fi
}

case "$1" in
    start)   startme ;;
    stop)    stopme ;;    
    restart) stopme; startme ;;
    *) echo "usage: $0 start|stop|restart" >&2
       exit 1
       ;;
esac

Loosely modified from the unicorn scripts that Ryan Bates used in his VPS deployment railscast (pro only).

Make it executable

chmod +x config/thin_example.sh

You'll need to symlink it to init.d (after chmod +x 'ing to make it executable)

sudo ln -nfs /home/deployer/apps/example/current/config/thin_example.sh /etc/init.d/thin_example

Then if you want it to startup with the server

 sudo update-rc.d thin_example defaults

Otherwise you should just be able to /etc/init.d/thin_example [start|stop|restart]. An important point to note is that I'm telling rackup to start in daemon mode (-D) and explicitly setting the PID so I can kill it later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文