重启后自动启动 Rails 服务器
我希望我的 Rails 服务器在每次重启后自动启动,所以我将以下内容添加到我的 .bashrc 文件中
I'd like my rails server to start automatically after every reboot, so I added the following to my .bashrc file
rvm use 1.9.2
cd /home/user/myapp
rails server
这样,服务器在重新启动后永远不会自动启动,我必须手动启动它.
With that, the server never starts automatically after a reboot, and I have to start it manually.
另外,当我登录启动服务器时,我看到以下消息
Also, when I login to start the server, I see the following message
Using /usr/local/rvm/gems/ruby-1.9.2-p290
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby: symbol lookup error: /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so: undefined symbol: sqlite3_initialize
因此,在我成为超级用户后,我需要在每次重新启动后使用gem install sqlite3"安装 sqlite3,然后才能毫无问题地启动 rails 服务器.
As a consequence, I need to install sqlite3 after every reboot using "gem install sqlite3" after I make myself superuser, and only then I can start the rails server without issues.
$ cat /etc/*-release
CentOS release 5.8 (Final)
$ rails -v
Rails 3.1.1
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
谁能帮我解决这个问题?谢谢
Anyone can please help me overcome this issue? Thanks
推荐答案
安装Apache和Passenger
他们会以更安全、更系统的方式以及现在或多或少成为标准的方式来处理使用服务器启动您的应用程序.
Install Apache and Passenger
They will take care of starting your App with the server in a safer and more systematic way and what is now more or less a standard.
我在 CentOS 6 上使用 Rails 4、Ruby 2.1 时遇到了同样的问题.如果您不熟悉 bash 脚本和 rc、profiles 系统 - 设置 passenger
会更快更容易.
I had the same issue with Rails 4, Ruby 2.1 on CentOS 6. If you're not familiar with bash scripts and the rc, profiles system - it's much faster and easier to setup passenger
.
此外,您选择乘客还有其他原因,包括安全和性能 (www.phusionpassenger.com)
Also, there are other reasons why you would go for passenger, including security and performance ( www.phusionpassenger.com )
这里是我介绍宝石的快速方法.
Here is a quick how-to of what it took me to introduce the gem.
安装 Apache(html 守护进程)和依赖包(如果你还没有的话):
Install Apache (html daemon) and dependency packages (if you don't have them already):
yum 安装 httpd curl-devel httpd-devel
yum install httpd curl-devel httpd-devel
让 Apache 在开机时启动:
Get Apache to start on boot:
chkconfig httpd on
chkconfig httpd on
安装 Phusion Passenger 和依赖包:
Install Phusion Passenger and dependency packages:
宝石安装乘客
yum install curl-devel httpd-devel
gem install passenger
yum install curl-devel httpd-devel
编译环境:
Compile the environment:
passenger-install-apache2-module
passenger-install-apache2-module
在 etc/httpd/conf/httpd.conf 中编辑 Apache 配置文件
Edit the Apache config file in etc/httpd/conf/httpd.conf
取消注释最后包含
NameVirtualHost *:80
的行
将第 4) 点的输出粘贴到文件末尾的任意位置,例如:
Paste the output from point 4) anywhere at the end of the file, eg:
LoadModulepassenger_module/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
PassengerRoot/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41
PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41
PassengerDefaultRuby/usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby
<VirtualHost *:80>
ServerName 1.2.3.4 # www.whatever.com
DocumentRoot /var/www/rails/public # the path to your rails app
<Directory /var/www/rails/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
我总共花了 30 分钟,其中包括几次使用 httpd.conf 的试错,以确保一切正常.
Took me 30 minutes in total, including several trial-errors with the httpd.conf to get everything right.
请注意,安装需要您的机器上至少有 1 GB RAM.
Note that installation requires at least 1 GB RAM on your machine.
相关文章