Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby on Rails | Webric ServerをDeamonで起動、終了する

概要

Webric ServerをDeamonで起動、終了する

詳細

Webric ServerをDeamonで起動、終了します

設定

サーバー起動用bash

start.bash
※-dのオプションがデーモン起動

#!/bin/bash
bundle exec rails s -d -e production
サーバー起動用rakeタスク

start.rake

desc 'start rails'
task :start do
  list = open('| bash start.bash') {|msg| msg.gets}
end
サーバー終了用rakeタスク

stop.rake

desc 'stop rails'
task :stop do
  pid_file = 'tmp/pids/server.pid'
  pid = File.read(pid_file).to_i
  Process.kill 9, pid
  File.delete pid_file
end
実行例

起動

bundle exec rake start

終了

bundle exec rake stop