- 安装thin
gem 'thin'
- 运行rackup
rackup config.ru
- 当然,需要设置环境变量为 production
set :environment, :production
- 启动命令的复杂形式
rackup -s thin config.ru -P tmp/rack.pid -E production -D
- 可以写一个rake来做这些事情
namespace :server do desc "start server" task :start do cmd = "rackup -s thin config.ru -P tmp/rack.pid -E production -p 9191 -D" system("#{cmd}") end desc "stop server" task :stop do path = File.expand_path("..", __FILE__) file_path = File.join(path, "tmp/rack.pid") if File.exist?(file_path) then File.open(file_path) do |file| pid = file.read system("kill -9 #{pid}") end FileUtils.rm file_path end end desc "restart server" task :restart => [:stop, :start] end