воскресенье, 23 декабря 2012 г.

Запуск Unicorn+RVM на FreeBSD

cd /www/itservice
rvm wrapper 1.9.3@itservice itservice unicorn

создает враппер совместимый с rc.d

Пришлось поправить ссылку на git:

sudo ln -nfs /usr/local/bin/git /usr/bin/git

как описано здесь:

http://ficial.wordpress.com/2011/07/13/phusion-passenger-fixing-no-such-file-or-directory-git-ls-files/

 

в итоге в rc.d

#
# Add the following lines to /etc/rc.conf to enable unicorn:
# unicorn_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable unicorn
# unicorn_profiles (str): Set to "" by default.
# Define your profiles here.
# unicorn_flags (str): Set to "" by default.
# Extra flags passed to start command.

. /etc/rc.subr

name="unicorn"
rcvar=`set_rcvar`

pidfile="/www/itservice/shared/pids/unicorn.pid"

unicorn_flags="-c /www/itservice/current/config/unicorn/colo.rb -E production -D"
start_cmd="unicorn_start"

command="/usr/local/rvm/bin/itservice_unicorn"
#pidprefix="/var/run/unicorn"

[ -z "$unicorn_enable" ] && unicorn_enable="NO"

load_rc_config $name
unicorn_start() {
echo "Starting ${name}"
${command} ${unicorn_flags}
}

extra_commands="reload"
sig_reload="USR2"

run_rc_command "$1"

 

и в config/unicorn/colo.rb

deploy_to = "/www/itservice"
app_path = "#{deploy_to}/current"
shared_path = "#{deploy_to}/shared"
pid_file = "#{shared_path}/pids/unicorn.pid"
socket_file= "#{shared_path}/pids/unicorn.sock"
rails_root = "#{deploy_to}/current"
# Set unicorn options
worker_processes 1
preload_app true
timeout 180
listen "127.0.0.1:9000"
# listen socket_file

# Spawn unicorn master worker for user apps (group: apps)
user 'nexus', 'nexus'

# Fill path to your app
working_directory app_path

# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

# Set master PID location
pid "#{shared_path}/pids/unicorn.pid"

before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect!

old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end

after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end

Комментариев нет:

Отправить комментарий