[英]Start Rails server automatically after boot
I need to cd to a directory and run the 'rails server' command after bootup. 我需要CD到目录并在启动后运行“ rails服务器”命令。 example 例
cd /home/bab/rails/app/ cd / home / bab / rails / app /
then when am in the app directory it runs the rails server command. 然后在应用程序目录中时,它将运行rails server命令。
Can some1 help me with this...using ubuntu 9.10 and rails 3.0.0 有人可以帮我吗...使用ubuntu 9.10和rails 3.0.0
try to add to /etc/rc.local
this: 尝试添加到/etc/rc.local
这个:
ruby /path/to/your/app/script/rails s -P /path/to/your/app/tmp/pids/server.pid -c /path/to/your/app/config.ru -d
But better to use passenger gem
here with Nginx or Apache 但最好在此处将Nginx或Apache用作passenger gem
http://modrails.com/ http://modrails.com/
It is easy to setup and easy to use 易于设置和使用
I've was getting the same error with RVM, ruby, and rails. 我在RVM,ruby和rails中遇到了相同的错误。 My directory is /home/user/rails-project/
. 我的目录是/home/user/rails-project/
。 Putting this in .bashrc
allows me to use the "rvm" command: 将其放在.bashrc
可以使用“ rvm”命令:
source ~/.rvm/scripts/rvm
server$:which rails
: server$:which rails
:
/home/user/.rvm/gems/ruby-2.2.1/bin/rails
The above shows the current rails bin. 上面显示了当前的滑轨箱。
So, the final command in rc.local
is: 因此, rc.local
的最终命令是:
su user-c "source ~/.rvm/scripts/rvm ; cd /home/user/rails-project/ ; /home/user/.rvm/gems/ruby-2.2.1/bin/rails s -d -e production"
You can use this code in rc.local
to debug: 您可以在rc.local
使用以下代码进行调试:
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
Use sudo service rc.local start
for testing without a reboot. 使用sudo service rc.local start
进行测试而无需重新启动。
I was able to accomplish this in the following way: 我能够通过以下方式完成此任务:
create a script "rails.run" with the following line to start the ruby on rails with the desired user and parameters: 用以下行创建一个脚本“ rails.run”,以使用所需的用户和参数在rails上启动ruby:
sudo -H -u <username> bash -c '/home/username/.rbenv/versions/2.2.3/bin/ruby bin/rails server --port=3000 --binding=ip_address -d'
Then add the script in the rc.local file with a simple line such as: 然后,使用简单的行将脚本添加到rc.local文件中,例如:
/home/username/rails.run /home/username/rails.run
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.