個人用 nginx + redmine 立てました

Pocket

手順がいろいろ合ってメモしきれなかったけど

ansibleで作ったzabbixのものとさくらのクラウドにあるredmineを使ってインストールしました
さくらのクラウドにあったスタートアップスクリプトをそのまま流せばインストールされるのですが
apacheは嫌なのでnginxに変更します

ということでさくらのクラウドにあるredmineのシェルの後に以下を追記するか
流し終わってから追加すればredmine + nginx + unicornの設定になると思います

#---------START OF apache -> nginx---------#
sleep 5s
service httpd stop

echo 'gem "unicorn"' >> /var/lib/redmine/Gemfile.local
cd /var/lib/redmine && bundle install

cat <<EOT > /var/lib/redmine/config/unicorn.rb
worker_processes 1

timeout 60

listen File.expand_path("tmp/sockets/unicorn.sock", ENV['RAILS_ROOT'])

pid File.expand_path("tmp/pids/unicorn.pid", ENV['RAILS_ROOT'])

stdout_path File.expand_path("log/unicorn.stdout.log", ENV['RAILS_ROOT'])
stderr_path File.expand_path("log/unicorn.stderr.log", ENV['RAILS_ROOT'])

preload_app true
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true

before_fork do |server, worker|
  # In preload_app true, this setup is indispensable.
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!

  # The old process is terminated with USR2 signal.
  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

after_fork do |server, worker|
  # In preload_app true, this setup is indispensable.
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
EOT

cd /var/lib/redmine && bundle exec unicorn_rails -c config/unicorn.rb -D -E production
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum -y install nginx
rm -f /etc/nginx/conf.d/default.conf

cat <<EOT > /etc/nginx/conf.d/redmine.conf
upstream redmine {
  server unix:/var/lib/redmine/tmp/sockets/unicorn.sock;
}

server {
  listen 80;
  server_name localhost;

  location / {
    root /var/lib/redmine/public;

    if ( -f \$request_filename ) { break; }

    proxy_set_header X-Real-IP  \$remote_addr;
    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto \$scheme;
    proxy_set_header Host \$http_host;
    proxy_pass http://redmine;
  }
}
EOT

service nginx start
# unicorn stop command
# kill -quit 'cat /var/lib/redmine/tmp/pids/unicorn.pid'

#---------END OF apache -> nginx---------#

redmineで管理したいものはいろいろあったので色々楽しみです
あとかなり大変だったのがredmineのバックログのプラグインを入れたり初期設定をしたりしたこと
一回やったらもうやりたいくないレベルで面倒ですね
あと今回は一人だからロール管理とか結構楽だったんですけど
これが複数で開発したりするから設定してね とかだったりすると設定大変そうだなぁと思いました まる

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください