0

每次我重新启动一个 linux 机器时,我都必须运行rails s以在 dev env 中启动一个 rails 应用程序。

有没有办法在linux重新启动时自动启动给定的rails应用程序?

我认为该解决方案接近于在生产环境中运行应用程序。

我从未在生产站点中运行过应用程序。

更新 1

我在谷歌上搜索了更多关于这个问题的信息,发现了一些离我很近的东西 我怎样才能让“rc.local”在启动时运行?.

我的/etc/rc/local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/home/askar/.rvm/rubies/ruby-2.1.2/bin/ruby /home/askar/work/rails/smn/bin/rails s

exit 0

$ ls -al /etc/rc.local

-rwxr-xr-x 1 root root 423 Jul 23 12:41 /etc/rc.local

我能够运行:

$/etc/rc.local &

但是当我尝试运行以便在下次启动时自动启动时:

sudo /etc/init.d/rc.local start

它给了我错误:

Could not find rake-10.2.1 in any of the sources
Run `bundle install` to install missing gems.
4

3 回答 3

1

您需要运行像 Apache 或 Nginx 这样的真实 Web 服务器和像 Passenger 这样的 ruby​​ 连接器。这样做要容易得多rail s。正如您所怀疑的那样,这就像设置登台或生产服务器。

有很多关于如何做到这一点的好教程,特别是对于 Linux。

于 2014-07-22T01:29:39.113 回答
0

您只需要添加 bash 命令:

cd path/to/rails/project; rails s

登录脚本,例如您的~/.bashrc文件。每次您登录到您的 linux 机器时,登录脚本都会启动您的 rails 服务器。在 OSX 中,您将向 LaunchAgents 添加一个登录项。

于 2014-07-22T01:34:28.543 回答
0

您还可以查看诸如 Prax https://github.com/ysbaddaden/prax之类的东西 ,它是 Pow for OSX 的纯 ruby​​ 替代品,它允许您将其作为机架代理运行并在 sitename.dev 上访问您的站点。我比 rails 更喜欢这个,因为您可以轻松地让多个链接到它的站点按名称访问它们,而不必担心端口等。

于 2014-07-22T01:34:55.523 回答