本文的目的是尽可能浅显的介绍Ruby + Passenger的使用。如果想深入了解Passenger,可参考后续相关章节。
本人通过有无Passenger启动Rubyf服务来入门Passenger
准备Ruby程序
# 此项目是本人在github上提交的Ruby demo程序
git clone https://github.com/testcara/ROR_Blog.git
安装Gem包
# check the Gemfile and install the Gems
# enter the dir
cd ROR_Blog
# confirm whether it is has the 'passenger'
cat Gemfile | grep -r -i 'passenger'
# install packages without production mode
bundle install --without production
直接启动服务
# start the service
rails s
# then open the http://localhost:3000 to check the main page of the application
验证进程
# check the ruby related process
ps aux | grep ruby
# we will see there is only one ruby process ‘rails’
确认log
# check the log files under the 'log' dir
ll log
# then we can see there is no passenger*.log
# add passenger to Gemfile
echo 'gem "passenger", require: "phusion_passenger/rack_handler"' >> Gemfile
# confirm the passenger existing in the 'passenger'
cat Gemfile | grep 'passenger'
# install Gemfiles including the 'passenger'
bundle install --without production
# kill the 'rails s' to free the 3000 port
# start passenger service
passenger start
# check the ruby related process
ps aux | grep ruby
# then we would see one ruby process 'passenger'
# check the log files under the 'log' dir
ll log
# then we can see there is one passenger*.log
以上可见,
通过Passenger启动Ruby程序是非常简单的。Ruby on Rails框架提供了内嵌的服务器工具。这些服务器工具可以和rails server命令进行交互。rails server不是一个应用服务器, 仅仅是启动应用和应用服务器的wrapper。如果Gemfile中指定了Passenger,则rails server会启动Passenger而不是默认服务器,如果没有Passenger,则会启动默认应用服务区。
通常在生产环境中,我们不会直接使用rails s起启动服务,而使用Passenger等应用服务器的原因。