unicorn web server 는 ruby 로 개발된 웹서버로 rails app 을 deploy 하는데 유용한 제품이며 gitlab 도 unicorn 을 사용하고 있다.

redmine 도 rails app 이므로 production 환경에서는 webrick 보다는 unicorn 이나 apache httpd나 Nginx용 Phusion Passenger 등을 사용하여 deploy 를 많이 하고 있다.

redmine 설치후 unicorn 으로 deploy 하는 방법을 정리해 본다.

Unicorn 설치

root 사용자로 gem 을 이용하여 system 전체에서 사용할 수 있게 하는 방법 과 일반 사용자 권한으로 rails app에 설치하는 두가지 방법이 있다.

root 로 설치(gem 사용)

gem install unicorn
CODE

 

일반 사용자로 설치(bundle 사용)

  1. redmine 설치 디렉터리로 이동한다. (Ex: cd /home/redmine/redmine-2.4)
  2. 에디터로 Gemfile.local 을 열어서 다음 내용을 추가한다.

    Gemfile.local

    group :unicorn do
      gem "unicorn", '~> 4.6.3'
      gem 'unicorn-worker-killer'
    end
    RUBY
  3. bundle 명령어로 vendor/bundle 에 설치한다.

    bundle install --path vendor/bundle
    CODE

 

유니콘 설정

  1. unicorn 설치 디렉터리에서 unicorn.conf.rb 파일을 찾아서 config/unicorn.rb 로 복사한다.

    cp ./vendor/bundle/ruby/2.0.0/gems/unicorn-4.6.3/examples/unicorn.conf.rb config/unicorn.rb
    CODE
  2. config/unicorn.rb 를 에디터로 열어서 app 경로 및 port 를 수정한다.

    # Help ensure your application will always spawn in the symlinked
    # "current" directory that Capistrano sets up.
    working_directory "/home/redmine/redmine-2.4.5/" # available in 0.94.0+
     
    # listen on both a Unix domain socket and a TCP port,
    # we use a shorter backlog for quicker failover when busy
    ##listen "/tmp/.unicorn.sock", :backlog => 64
    listen 8080, :tcp_nopush => true
    
    # feel free to point this anywhere accessible on the filesystem
    pid "/home/redmine/redmine-2.4.5/tmp/pids/unicorn.pid"
    # By default, the Unicorn logger will write to stderr.
    # Additionally, ome applications/frameworks log to stderr or stdout,
    # so prevent them from going to /dev/null when daemonized here:
    stderr_path "/home/redmine/redmine-2.4.5/log/unicorn-stderr.log"
    stdout_path "/home/redmine/redmine-2.4.5/log/unicorn-stdout.log"
    CODE

유니콘으로 레드마인 실행

redmine 디렉터리에서 다음 명령어로 실행

  1. unicorn 실행

    bundle exec unicorn_rails -D -c config/unicorn.rb -E production
    CODE
  2. 구동 성공/실패 여부를 log/unicorn-stderr.log 를 통해 확인한다.

    tail -f  log/unicorn-stderr.log
    CODE
  3. 브라우저로 연결하여 redmine 이 정상 동작하는지 확인한다.

유니콘 구동 스크립트

유니콘을 시작하고 중지하는 과정을 쉘 스크립트로 작성(https://gist.github.com/lesstif/dfaf6ea79aacaefcb273)

 

루비 온 레일스 어플리케이션 디플로이 방법으로는 그외에 apache 나 Nginx 내에서 모듈로 동작하는 Phusion Passenger 와 JBoss AS 위에 JRuby 를 올린 Torquebox 가 있다.

Torquebox 는 레드햇이 개발하는 제품으로 JBoss 를 모든 어플리케이션의 디플로이 플랫폼화하려는 전략의 일환이 아닐까 생각된다.

Ref