Redmine
目次
インストール
パッケージインストール
パッケージをインストールする。めんどくさいのでpkgでさくっといれる。
pkg install redmine pkg install rubygem-unicorn pkg install nginx
redmineの設定
データベースの設定
firebirdは使えなかったので、とりあえず、sqliteで使用する。
データーベースの設定ファイル /usr/local/www/redmine/config/database.yml に以下の内容を記述する。
production: adapter: salite3 database: db/redmine.sqlite encoding: utf8 development: adapter: sqlite3 database: db/redmine_dev.sqlite
秘密鍵の作成と初期データの投入
Redmineのディレクトリ(/usr/local/www/redmine)で作業を行う。
秘密鍵の作成
rake generate_secret_token
DBの初期化
sh RAILS_ENV=production rake db:migrate RAILS_ENV=production REDMINE_LANG=ja rake redmine:load_default_data
FreeBSF 11.1にすると fdatasync のエラーが発生する。
sqlite3を下記のようにportsからいれてロックしておき。
portsnap fetch portsnap extract whereis sqlite3 (cd into that directory) make deinstall make install clean ALLOW_UNSUPPORTED_SYSTEM=true pkg lock sqlite3
データ配置フォルダの作成
mkdir -p tmp tmp/pdf public/plugin_assets chown -R www:www files log tmp public/plugin_assets chmod -R 755 files log tmp public/plugin_assets
稼働確認
webrickで稼働確認をする。以下のコマンドを実行し、稼働させたうえでブラウザでアクセスする。 -b オプションを抜かすとループバックアドレスにbindされてしまい、外部からブラウザで確認できないので注意。
ruby bin/rails server webrick -e production -b 0.0.0.0
unicornの設定
nginx連携のために、unicornの起動スクリプトを記述する。
ファイルは /usr/local/www/redmine/config/unicorn.rb とする。
@dir = "/usr/local/www/redmine"
worker_processes 1
working_directory @dir
#nginxに渡すソケットの設定。wwwの下に置くものではないので/varに
listen "/var/run/unicorn.sock"
pid "/var/run/unicorn.pid"
preload_app true
stdout_path File.expand_path("log/unicorn.stdout.log", @dir)
stderr_path File.expand_path("log/unicorn.stderr.log", @dir)
サブディレクトリの設定
redmineをトップレベルで動かす気はないので、サブディレクトリで動くようにする。
/usr/local/www/redmine/config.ru を以下のように書き換える。
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
# もともとの設定。トップレベルでの起動になる。
#run RedmineApp::Application
# 環境変数であたえられたディレクトリごとに起動するようにする。
if ENV['RAILS_RELATIVE_URL_ROOT']
map ENV['RAILS_RELATIVE_URL_ROOT'] do
run RedmineApp::Application
end
else
run RedmineApp::Application
end
unicornの起動
以下のコマンドでunicornをデーモンで起動する。--path で指定したパスがrailsのルートフォルダになる。
unicorn_rails -c config/unicorn.rb -E production -D --path /redmine
止める場合は
kill -9 `cat /var/run/unicorn.pid`
自動起動設定
/etc/rc.conf に以下の記述を追加
redmine_enable="YES"
/etc/local/etc/rc.d/redmineを下記のように修正
#!/bin/sh
# $FreeBSD: branches/2018Q2/www/redmine/files/redmine.in 430493 2017-01-03 18:25
:44Z swills $
# PROVIDE: redmine
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Add the following line to /etc/rc.conf[.local] to enable redmine
#
# redmine_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable redmine.
# redmine_flags (str): Custom additional arguments to be passed
# to redmine.
# redmine_user (str): User account to run thin with. (default: www)
# redmine_group (str): Group to run thin with. (default: www)
. /etc/rc.subr
name="redmine"
rcvar=redmine_enable
load_rc_config $name
extra_commands="status"
start_cmd=redmine_start
stop_cmd=redmine_stop
status_cmd=redmine_status
redmine_enable=${redmine_enable:-"NO"}
redmine_base=${redmine_base:-"/usr/local/www/redmine"}
if [ -r /var/run/unicorn.pid ]; then
redmine_pid=`cat /var/run/unicorn.pid`
fi
PATH=${PATH}:/usr/local/bin
redmine_start()
{
cd ${redmine_base} && bundle exec unicorn_rails -c config/unicorn.rb -E
production -D --path /redmine
echo "${name} started"
}
redmine_stop()
{
if [ "x" == "x${redmine_pid}" ]; then
echo "${name} not running?"
else
kill -9 ${redmine_pid}
rm /var/run/unicorn.pid
echo "${name} stoped"
fi
}
redmine_status()
{
if [ "x" == "x${redmine_pid}" ]; then
echo "${name} is not running."
else
echo "${name} is running as pid ${redmine_pid}."
fi
}
run_rc_command "$1"
nginxの設定
/usr/local/etc/nginx/nginx.conf がnginxの設定ファイル。
httpブロックに以下の内容を追加し、unicornのソケットと連携できるようにする。
upstream redmine{
server unix:/var/run/unicorn.sock;
}
ここで指定するパスはunicornの設定で作ったsockファイルを指定する。
server ブロックに以下の内容を追加し、redmineのフォルダを指定する。
location /redmine/ {
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 Host $http_host;
proxy_pass http://redmine;
}
ついでにbasic認証もかけておく。
以下のコマンドで /usr/local/etc/nginx/.htaccess に認証ファイルを作成する。
apacheをいれていないので、portsから htpasswd.pyをインストールする。
cd /usr/ports/security/py-htpasswd make install
.htpasswdを作成する。
htpasswd.py -c -b /usr/local/etc/nginx/.htaccess username password
さっき書いたlocationに以下の内容を追加する。
auth_basic "Restricted";
auth_basic_user_file /usr/local/etc/nginx/.htaccess;
設定が終わったらnginxを起動する。
nginx
すでに動いているなら再起動。
nginx -s reload