【问题标题】:Start rails server automatically when ever I start my ubuntu machine当我启动我的 ubuntu 机器时自动启动 rails 服务器
【发布时间】:2011-07-30 15:22:29
【问题描述】:

我有一个 Rails 应用程序,我想在机器启动时自动启动服务器。现在我 cd 到目录,然后输入rails s 命令。如何配置我的机器以在启动时运行我的 Rail 服务器?我正在使用 Ubuntu 和 Rails 3.0.0。

【问题讨论】:

  • 你能分享你的堆栈吗(例如 Apache 2、mongrel 等)?

标签: linux ruby-on-rails-3 shell scripting ubuntu


【解决方案1】:
@reboot /bin/bash -l -c 'cd PATH_TO_PROJECT && rails s'

为我做了诀窍。您可能需要重新加载 RVM 并为此

@reboot /bin/bash -l -c 'cd PATH_TO_PROJECT && source ~/.rvm/scripts/rvm && rvm use ruby-RUBY_VERSION_HERE && rails s'

将达到目的。

【讨论】:

  • 在我的情况下,rvm source /etc/profile.d/rvm.sh 的位置不同,这很有效。谢谢!
【解决方案2】:

您可以为此使用 cron 作业。要添加 cron 作业,请使用命令 crontab -e。你可以定义一个在启动时运行并使用@reboot command 重新启动的 cron 作业。

所以你会有类似的东西:

@reboot cd /home/[path to project] && rails server

【讨论】:

  • 我做了 crontab -e 并添加了你用我正确的路径给出的命令,但它没有工作..还有什么遗漏吗?
  • 您可以随时手动测试命令以查看是否会出错
猜你喜欢
  • 2016-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-24
  • 2013-05-31
  • 1970-01-01
  • 2021-12-07
相关资源
最近更新 更多