「Redmine」の版間の差分
(→unicornの起動) |
|||
| (同じ利用者による、間の6版が非表示) | |||
| 33行目: | 33行目: | ||
RAILS_ENV=production rake db:migrate | RAILS_ENV=production rake db:migrate | ||
RAILS_ENV=production REDMINE_LANG=ja rake redmine:load_default_data | RAILS_ENV=production REDMINE_LANG=ja rake redmine:load_default_data | ||
| + | </pre> | ||
| + | FreeBSF 11.1にすると fdatasync のエラーが発生する。<br> | ||
| + | sqlite3を下記のようにportsからいれてロックしておき。 | ||
| + | <pre> | ||
| + | portsnap fetch | ||
| + | portsnap extract | ||
| + | whereis sqlite3 | ||
| + | (cd into that directory) | ||
| + | make deinstall | ||
| + | make install clean ALLOW_UNSUPPORTED_SYSTEM=true | ||
| + | pkg lock sqlite3 | ||
</pre> | </pre> | ||
データ配置フォルダの作成 | データ配置フォルダの作成 | ||
| 63行目: | 74行目: | ||
stderr_path File.expand_path("log/unicorn.stderr.log", @dir) | stderr_path File.expand_path("log/unicorn.stderr.log", @dir) | ||
</pre> | </pre> | ||
| − | + | === サブディレクトリの設定 === | |
redmineをトップレベルで動かす気はないので、サブディレクトリで動くようにする。<br> | redmineをトップレベルで動かす気はないので、サブディレクトリで動くようにする。<br> | ||
/usr/local/www/redmine/config.ru を以下のように書き換える。 | /usr/local/www/redmine/config.ru を以下のように書き換える。 | ||
| 93行目: | 104行目: | ||
kill -9 `cat /var/run/unicorn.pid` | kill -9 `cat /var/run/unicorn.pid` | ||
</pre> | </pre> | ||
| + | |||
| + | === 自動起動設定 === | ||
| + | /etc/rc.conf に以下の記述を追加 | ||
| + | <pre> | ||
| + | redmine_enable="YES" | ||
| + | </pre> | ||
| + | /etc/local/etc/rc.d/redmineを下記のように修正 | ||
| + | <pre> | ||
| + | #!/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" | ||
| + | </pre> | ||
| + | |||
== nginxの設定 == | == nginxの設定 == | ||
/usr/local/etc/nginx/nginx.conf がnginxの設定ファイル。<br> | /usr/local/etc/nginx/nginx.conf がnginxの設定ファイル。<br> | ||
| 100行目: | 186行目: | ||
server unix:/var/run/unicorn.sock; | server unix:/var/run/unicorn.sock; | ||
} | } | ||
| − | <pre> | + | </pre> |
ここで指定するパスはunicornの設定で作ったsockファイルを指定する。 | ここで指定するパスはunicornの設定で作ったsockファイルを指定する。 | ||
| + | |||
| + | server ブロックに以下の内容を追加し、redmineのフォルダを指定する。 | ||
| + | <pre> | ||
| + | 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; | ||
| + | } | ||
| + | </pre> | ||
| + | |||
| + | ついでにbasic認証もかけておく。<br> | ||
| + | 以下のコマンドで /usr/local/etc/nginx/.htaccess に認証ファイルを作成する。<br> | ||
| + | apacheをいれていないので、portsから htpasswd.pyをインストールする。 | ||
| + | <pre> | ||
| + | cd /usr/ports/security/py-htpasswd | ||
| + | make install | ||
| + | </pre> | ||
| + | .htpasswdを作成する。 | ||
| + | <pre> | ||
| + | htpasswd.py -c -b /usr/local/etc/nginx/.htaccess username password | ||
| + | </pre> | ||
| + | さっき書いたlocationに以下の内容を追加する。 | ||
| + | <pre> | ||
| + | auth_basic "Restricted"; | ||
| + | auth_basic_user_file /usr/local/etc/nginx/.htaccess; | ||
| + | </pre> | ||
| + | |||
| + | 設定が終わったらnginxを起動する。 | ||
| + | <pre> | ||
| + | nginx | ||
| + | </pre> | ||
| + | すでに動いているなら再起動。 | ||
| + | <pre> | ||
| + | nginx -s reload | ||
| + | </pre> | ||
2018年5月5日 (土) 05:00時点における最新版
目次
インストール
パッケージインストール
パッケージをインストールする。めんどくさいので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