チケットのアサインをあらかじめログインユーザーにする

%REDMINE%/app/controllers/issues_controller.rbをエディタで開く。
build_new_issue_from_paramsメソッド(文字列"def build_new_issue_from_params")を探す。
build_new_issue_from_paramsメソッド内で
@issue.author = User.currentという記述の行を探す。
上記の行の直後に以下の記述を追加。
@issue.assigned_to ||= User.current

Redmineでリポジトリの情報を定期取得したい

RAILS_ROOTで下記コマンドを実行する。
うちの場合だと、RAILS_ROOT は /var/lib/redmine

# ruby script/runner "Repository.fetch_changesets" \ -e production

実行してみたらwarningがでてきた。
rails のバージョンが 2.3.5 で rubygems のバージョンが 1.3.6 以降の時に起こる」らしい。
気にしなくてもいいみたい。バージョンあがったら消えるみたいだ。

実際の運用例をいくつか

(例1)/etc/crontabに記述して一定間隔ごとに自動的に取得するようにする。

これは30分単位

 */30 * * * * root cd /var/lib/redmine && ruby script/runner "Repository.fetch_changesets" -e production
(例2)コミットと同時にリポジトリの情報を取得する

参考URL
小技(0.9): コミットと同時にリポジトリの情報を取得する | Redmine.JP Blog

Subversionのpost-commitスクリプトでコミットごとに例1のスクリプトを実行する。
post-commitの中身は↓の感じ。

#!/bin/sh
REPOS="$1"
REV="$2"

# 以下は実際には改行無しで1行で記述
/usr/local/bin/ruby -ropen-uri -e 'open("http://Redmineサーバ/sys/fetch_changesets?key=APIキー")'

# wgetがインストールされていれば以下のようにしてもよいです
# /usr/bin/wget -q -O /dev/null http://Redmineサーバ/sys/fetch_changesets?key=APIキー

APIキーはRedmineの設定を見ればわかるはず。

      • -

今回は例2でやってみた。
post-commitを作成するのだが、post-commit.tmplがあるのでそれを参考にする。
templateがあるところに配備すればおっけーのはず。
対象リポジトリのhooksディレクトリに作る。

#!/bin/sh
REPOS="$1"
REV="$2"

# 以下は実際には改行無しで1行で記述
/usr/local/bin/ruby -ropen-uri -e 'open("http://Redmineサーバ/sys/fetch_changesets?key=APIキー")'


自動取得するようになったので、リポジトリ開くたびにコミットを自動取得するのチェックをはずしました。

logrotateでログを管理する

production.logは放っておくとどんどん肥大化する
ということで、logrotateをすることにしました。


(Redmineのインストールディレクトリが/var/lib/redmineの場合)

/var/lib/redmine/log/*log {
    missingok      # ファイルが存在しなくてもエラーにしない
    notifempty     # 
    copytruncate   # ログを別名でコピーした後、元のファイルの内容を空にする
    compress       # 古いログを圧縮して保存する
}


スクリプトの確認

# logrotate -d /etc/logrotate.d/redmine

エラーがなければ強制実行

# logrotate -f /etc/logrotate.conf

/var/lib/redmine/log/配下を確認して、production.log.数字ができていればオッケー。
crontabのweeklyで動くので、必要に応じて実施時間を変更しておく。

Redmineを入れた話

1人プロジェクトのため、Redmineを入れてみた。
チケット駆動でやるっていうのをやりたかったし、Linux管理の勉強にもなるかと思って。
インストール手順は下記記事のお世話になりました。
Redmine 1.1をCentOS5.5にインストールする手順 | Redmine.JP Blog

入れる前の環境
最終的に目指す環境

サブディレクトリでRedmineを実行するようにApacheは設定する。

必要なパッケージのインストール

開発ツール(Cコンパイラ等):

# yum groupinstall "Development Tools"

or

# yum -y install gcc

Toolsだと、subversionとかもバージョン上がってしまう。
gccだけいれたほうがいい。

メモ

[開発ツール群を削除]

# yum groupremove "Development Tools"

インストールつづき

RubyとPassengerのビルドに必要なヘッダファイルなど:

# yum install openssl-devel readline-devel zlib-devel curl-devel

MySQLとヘッダファイル:

# yum install mysql-server mysql-devel

Apacheのヘッダファイル
httpdは入っているのでいれなかった。

# yum install httpd-devel

Complete!って出るまで延々インストール

Rubyのインストール

ダウンロード
Download — Ruby Enterprise Edition

/usr/local/src に コピー

# cd /usr/local/src

解凍

# tar xzvf ruby-enterprise-1.8.7-2011.03.tar.gz

インストーラの実行

# ./ruby-enterprise-1.8.7-2011.03/installer --dont-install-useful-gems --no-dev-docs
	Welcome to the Ruby Enterprise Edition installer
	This installer will help you install Ruby Enterprise Edition 1.8.7-2011.03.
	Don't worry, none of your system files will be touched if you don't want them
	to, so there is no risk that things will screw up.

	You can expect this from the installation process:

	  1. Ruby Enterprise Edition will be compiled and optimized for speed for this
	     system.
	  2. Ruby on Rails will be installed for Ruby Enterprise Edition.
	  3. You will learn how to tell Phusion Passenger to use Ruby Enterprise
	     Edition instead of regular Ruby.

	Press Enter to continue, or Ctrl-C to abort.

	Checking for required software...

	 * C compiler... found at /usr/bin/gcc
	 * C++ compiler... found at /usr/bin/g++
	 * The 'make' tool... found at /usr/bin/make
	 * The 'patch' tool... found at /usr/bin/patch
	 * Zlib development headers... found
	 * OpenSSL development headers... found
	 * GNU Readline development headers... found
	--------------------------------------------
	Target directory

	Where would you like to install Ruby Enterprise Edition to?
	(All Ruby Enterprise Edition files will be put inside that directory.)
	インストール先(Target Directory)の入力
	[/opt/ruby-enterprise-1.8.7-2011.03] : /usr/local/
	・・・・
	Enjoy Ruby Enterprise Edition, a product of Phusion (www.phusion.nl) :-)

RubyGems1.4.2のインストール

Ruby Enterprise Editionと共にインストールされるRubyGems1.5.2ではRedmineが実行できないので
RubyGemsを1.4.2にダウングレードします。

# gem update --system 1.4.2
	Updating rubygems-update
	Fetching: rubygems-update-1.4.2.gem (100%)
	Successfully installed rubygems-update-1.4.2
	Installing RubyGems 1.4.2
	RubyGems 1.4.2 installed
	File not found: README
# gem --version

1.4.2 とでればおっけー。

Rack 1.0.1のインストール

# gem install rack -v=1.0.1

i18n 0.4.2のインストール

# gem install i18n -v=0.4.2

RubyMySQLドライバーのインストール

# gem install mysql

No definition for next_result と延々でるが気にしなくてよいらしい。

MySQLの設定

configファイルをコピーする

cp -p /usr/share/mysql/my-small.cnf /etc/my.cnf

configファイルの編集

# vi /etc/my.cnf
	# The MySQL server
	[mysqld]
	port            = 3306
	socket          = /var/lib/mysql/mysql.sock
	skip-locking
	key_buffer = 16K
	max_allowed_packet = 1M
	table_cache = 4
	sort_buffer_size = 64K
	read_buffer_size = 256K
	read_rnd_buffer_size = 256K
	net_buffer_length = 2K
	thread_stack = 128K
	# adding 2011-04-12
	default-character-set=utf8

	# Don't listen on a TCP/IP port at all. This can be a security enhancement,
	# if all processes that need to connect to mysqld run on the same host.
	# All interaction with mysqld must be made via Unix sockets or named pipes.
	# Note that using this option without enabling named pipes on Windows
	# (using the "enable-named-pipe" option) will render mysqld useless!
	#
	#skip-networking
	server-id       = 1

	# Uncomment the following if you want to log updates
	#log-bin=mysql-bin

	# Disable Federated by default
	skip-federated

	# Uncomment the following if you are NOT using BDB tables
	#skip-bdb

	# Uncomment the following if you are using InnoDB tables
	#innodb_data_home_dir = /var/lib/mysql/
	#innodb_data_file_path = ibdata1:10M:autoextend
	#innodb_log_group_home_dir = /var/lib/mysql/
	#innodb_log_arch_dir = /var/lib/mysql/
	# You can set .._buffer_pool_size up to 50 - 80 %
	# of RAM but beware of setting memory usage too high
	#innodb_buffer_pool_size = 16M
	#innodb_additional_mem_pool_size = 2M
	# Set .._log_file_size to 25 % of buffer pool size
	#innodb_log_file_size = 5M
	#innodb_log_buffer_size = 8M
	#innodb_flush_log_at_trx_commit = 1
	#innodb_lock_wait_timeout = 50

	[mysqldump]
	quick
	max_allowed_packet = 16M

	[mysql]
	no-auto-rehash
	# Remove the next comment character if you are not familiar with SQL
	#safe-updates
	# adding 2011-04-12
	default-character-set=utf8

	[isamchk]
	key_buffer = 8M
	sort_buffer_size = 8M

	[myisamchk]
	key_buffer = 8M
	sort_buffer_size = 8M

MySQLの起動および自動起動の設定

# /etc/init.d/mysqld start
# chkconfig mysqld on

/etc/my.cnf への設定が反映されていることの確認(UTF-8になっていること)

# mysql -uroot
mysql> show variables like 'character_set%';	
	+--------------------------+----------------------------+
	| Variable_name            | Value                      |
	+--------------------------+----------------------------+
	| character_set_client     | utf8                       |
	| character_set_connection | utf8                       |
	| character_set_database   | utf8                       |
	| character_set_filesystem | binary                     |
	| character_set_results    | utf8                       |
	| character_set_server     | utf8                       |
	| character_set_system     | utf8                       |
	| character_sets_dir       | /usr/share/mysql/charsets/ |
	+--------------------------+----------------------------+
	8 rows in set (0.00 sec)

rootユーザーのパスワード変更・匿名ユーザー削除

# mysql -uroot	
mysql> use mysql;	
mysql> update user set password=password('パスワード') where user = 'root';	
mysql> delete from user where user = '';	
mysql> flush privileges;	
mysql> exit;	

Redmine用データベースとユーザーの作成

# mysql -uroot -p	
mysql> create database db_redmine default character set utf8;	
mysql> grant all on db_redmine.* to user_redmine identified by 'パスワード';	
mysql> flush privileges;	
mysql> exit;	

Redmineのインストール

redmine 1.1.2 ダウンロード
http://rubyforge.org/frs/?group_id=1850

/usr/local/src に転送

解凍

# tar zxvf redmine-1.1.2.tar.gz

Redmineの配置先のディレクトリを決定し、そこへ展開したファイルを移動します。
例えば、/var/lib/redmine を配置先とする場合、以下のようにします。

# mv redmine-1.1.2 /var/lib/redmine

database.ymlの設定

# cd /var/lib/redmine/config
# cp -p database.yml.example database.yml
# vi database.yml
	# MySQL (default setup).

	production:
	  adapter: mysql
	  database: db_redmine
	  host: localhost
	  username: user_redmine
	  password: パスワード
	  encoding: utf8

email.ymlの設定

今回メール使っていないが、枠だけ作成

# cp -p email.yml.example email.yml
# vi email.yml
	production:
	  delivery_method: :smtp
	  smtp_settings:
	    address: localhost
	    port: 25
	    domain: serverdomain
	    #authentication: :login
	    #user_name: "redmine@example.net"
	    #password: "パスワード"

Redmineの初期設定とデータベースのテーブル作成

セッションデータ暗号化用鍵の生成とテーブル作成

# cd /var/lib/redmine
# rake generate_session_store
# rake db:migrate RAILS_ENV=production

※もし、rakeコマンドがないといわれたら

# gem install rake --remote

Passengerのインストール

# gem install passenger

PassengerのApache用モジュールのインストール

# passenger-install-apache2-module --snippet
# vi /etc/httpd/conf.d/passenger.conf
	# Passengerの基本設定。
	# passenger-install-apache2-module --snippet を実行して表示される設定を使用。
	# 環境によって設定値が異なりますので以下の3行はそのまま転記しないでください。
	#
	LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.6/ext/apache2/mod_passenger.so
	PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.6
	PassengerRuby /usr/local/bin/ruby


	# Passengerが追加するHTTPヘッダを削除するための設定。
	#
	Header always unset "X-Powered-By"
	Header always unset "X-Rack-Cache"
	Header always unset "X-Content-Digest"
	Header always unset "X-Runtime"

	# 必要に応じてPassengerのチューニングのための設定を追加。
	#
	PassengerMaxPoolSize 20
	PassengerMaxInstancesPerApp 4
	PassengerPoolIdleTime 3600
	PassengerUseGlobalQueue on
	PassengerHighPerformance on
	PassengerStatThrottleRate 10
	RailsSpawnMethod smart
	RailsAppSpawnerIdleTime 86400
	RailsFrameworkSpawnerIdleTime 0

	RailsBaseURI /redmine

worker MPMに切り替えるをやっていない。必要であればやる。

# /etc/init.d/httpd restart

Apache上のPassengerでRedmineを実行するための設定

# chown -R apache:apache /var/lib/redmine
# ln -s /var/lib/redmine/public /var/www/html/redmine
# /etc/init.d/httpd configtest

Syntax OK

# /etc/init.d/httpd graceful

起動確認

http://domain/redmine

画面が表示されればオッケー!

あとは、

  • ユーザー作成
  • プロジェクト作成
  • カテゴリ作成
  • チケット作成
  • subversion連携

Data Pumpを使ってimport

パラメータファイルに全部おしこめている。

impdp user/password@sid parfile=impdp_param.txt


impdp_param.txtの中身

directory=DATA_DUMP_DIR
dumpfile=data.dump
logfile=impdp.log
content=data_only
remap_schema=(user:user2)
table_exists_action=truncate

スキーマとテーブルがあったときのアクションは要注意。