Redmineをpumaで動かそう!

Redmineをpumaで動かそう!

pumaのインストール

$ gem install puma

Redmineの設定

config/puma.rbを以下の内容で作成する

app_root = '/opt/redmine' #パスは適宜

directory app_root
environment 'production'
pidfile "#{app_root}/tmp/pids/puma.pid"
state_path "#{app_root}/tmp/pids/puma.state"
bind "unix:#{app_root}/tmp/sockets/redmine.socket"
activate_control_app

その他設定に関しては本家の説明を https://github.com/puma/puma

Gemfileにpumaを追記する

gem "puma"

以上で設定は完了。

Pumaの起動

# export RAILS_ENV=production
# /usr/local/bin/bundle exec puma -C /opt/redmine/config/puma.rb

systemdに仕込む場合のサンプル

/etc/systemd/system/redmine.serviceを作成

[Unit]
Description=Redmine Puma Server

[Service]
WorkingDirectory=/opt/redmine
Environment=RAILS_ENV=production
SyslogIdentifier=redmine
PIDFile=/opt/redmine/tmp/pids/puma.pid
ExecStart=/usr/local/bin/bundle exec puma -C /opt/redmine/config/puma.rb
Restart=always

[Install]
WantedBy=multi-user.target
# systemctl enable redmine
# systemctl start redmine

nginxの設定サンプル

upstream redmine {
  server unix:/opt/redmine/tmp/sockets/redmine.socket;
}
  (中略)

  location @redmine {
    (中略)
    proxy_pass http://redmine;
  }

UNIX SocketではなくTCPでバインドしたい場合は、pumaの起動オプションで-b(--bind)でポート指定すればよい。

ExecStart=/usr/local/bin/bundle exec puma -b tcp://127.0.0.1:9292 -C /opt/redmine/config/puma.rb