设置Thin,Bundler和Ubuntu

我有一个非常简单的Ruby应用程序,它使用Thin和Bundler,我需要把它粘在一个Ubuntu盒子上。

我已经尽可能在服务器上安装Ruby,Bundler等,但是在运行应用程序本身时遇到了麻烦。

本质上,我需要一个很好的方式,通过capistrano启动,停止和重新启动应用程序。

我的init.d脚本看起来很像这样:

DAEMON=/home/ubuntu/apps/my_app/shared/bundle/ruby/1.8/bin/thin SCRIPT_NAME=/etc/init.d/thin CONFIG_PATH=/etc/thin # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 case "$1" in start) cd /home/ubuntu/apps/my_app/current && bundle exec thin start -d -C /etc/thin/my_app.yml ;; stop) cd /home/ubuntu/apps/my_app/current && bundle exec thin stop -d -C /etc/thin/my_app.yml ;; restart) cd /home/ubuntu/apps/my_app/current && bundle exec thin restart -d -C /etc/thin/my_app.yml ;; *) echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2 exit 3 ;; esac 

这导致:

 /home/ubuntu/apps/my_app/shared/bundle/ruby/1.8/gems/thin-1.3.1/lib/thin/daemonizing.rb:51:in `daemonize': uninitialized constant Thin::Daemonizable::Daemonize (NameError) 

从服务器上的应用程序根运行sudo bundle exec thin start工作得很好(虽然不是守护进程)。

因此,我怎么能设置这个应用程序,以便它可以作为守护进程启动,并可以通过init.d脚本/监控等控制?

你可以创buildbinstubs。 使用这些init脚本应该像其他任何。 瘦只是需​​要 – damonize作为参数,如果你没有在你的thin.yaml指定它。 使用thin install精简为您生成一个init脚本

BUNDLE INSTALL –BINSTUBS

如果在bundle install(1)中使用–binstubs标志,Bundler将自动创build一个目录(默认为app_root / bin),该目录包含捆绑包中所有可用的可执行文件。

在使用–binstubs之后,bin / rspec spec / my_spec.rb与bundle rspec spec / my_spec.rb相同。

http://gembundler.com/man/bundle-exec.1.html

基于这些function,这对我的作品:

 bundle install --binstubs ./bin/thin install /etc/init.d/thin start