【发布时间】:2015-04-12 14:17:40
【问题描述】:
我已经绞尽脑汁几天了,已经用尽了我对这个问题的研究。
一点背景知识:我有一个 Rails 应用程序在生产环境中运行良好。我在不同目录下的同一台服务器上添加了一个登台环境。我能够到达临时站点。
我注意到的:
- 我的代码更改(暂存中)在暂存站点上正确显示。
- 我的暂存数据库已成功创建。
问题:
我的临时站点似乎认为它是一个生产站点。我觉得我没有在某处正确设置暂存环境。发生了一些奇怪的事情:
- 写入生产日志
- 它正在使用生产数据库
代码:(我已经替换了实际的域名/IP)
config/deploy.rb
# config valid only for current version of Capistrano
lock '3.3.5'
set :stages, %w(production staging)
set :default_stage, 'staging'
set :repo_url, 'git@github.com:test/test.git'
set :user, 'deploy'
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets public/system/members}
namespace :deploy do
%w[start stop restart].each do |command|
desc 'Manage Unicorn'
task command do
on roles(:app), in: :sequence, wait: 1 do
execute "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
end
end
end
after :publishing, :restart
end
config/deploy/staging.rb
set :rails_env, 'staging'
set :application, 'test_staging'
set :deploy_to, '/var/www/staging.test.co'
set :branch, 'staging'
role :app, %w{deploy@IP_HERE}
role :web, %w{deploy@IP_HERE}
role :db, %w{deploy@IP_HERE}
config/unicorn.rb
if ENV["RAILS_ENV"] == "production"
root = "/var/www/test.co/current"
else
root = "/var/www/staging.test.co/current"
end
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
if ENV["RAILS_ENV"] == "production"
listen "/tmp/unicorn.test.sock"
else
listen "/tmp/unicorn.test_staging.sock"
end
worker_processes 1
timeout 30
[在服务器上] /etc/init.d/unicorn_test_staging
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/var/www/staging.test.co/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E staging"
AS_USER=deploy
set -u
OLD_PIN="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "$1" - $AS_USER
fi
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
run "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;;
upgrade)
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
while test -s $OLD_PIN && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
if test $n -lt 0 && test -s $OLD_PIN
then
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
exit 1
fi
exit 0
fi
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
run "$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo >&2 "Usage: $0 "
exit 1
;;
esac
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: test_dev
host: localhost
pool: 5
username: test
password: password
staging:
adapter: postgresql
encoding: unicode
database: test_staging
production:
adapter: postgresql
encoding: unicode
database: test_production
如果您需要任何其他代码来帮助我在此处找到问题,请告诉我。感谢任何人对此的帮助。
谢谢!
【问题讨论】:
-
config/database.yml 是什么样的?
-
@PhilipHallstrom - 我将我的 database.yml 添加到帖子中。
标签: ruby-on-rails nginx unicorn capistrano3