Ads 468x60px

Pages

2011年4月26日 星期二

安裝 Remine 及 Migrate Trac to Redmine 之解決 wiki format 的相容問題(二)


繼上一篇安裝及把資料從 Trac 移到 Redmine 之後,除了 wiki format 的錯亂之外,還會發生一些 internal server error 的問題,例如看 wiki page 含有 attachment 時,或是點擊 issue;主要問題是移轉後,redmine 資料庫裡,部份 table 欄位如果有 datetime 的格式時,轉過來後都變成 "0000-00-00 00:00:00". 目前發現有問題的是這些,所以就用以下方式把它們都設定成現在的時間。
mysql> update attachments set created_on=now();

mysql> update issues set created_on=now(), updated_on=now();

mysql> update wiki_content_versions set updated_on=now();

mysql> update journals set created_on=now();
附帶問題發生時的錯誤訊息,及發現問題的方法:
/home/m/share/htdocs/redmine/log/production.log
ActionView::TemplateError (undefined method `<=>' for nil:NilClass) on line #2 of app/views/wiki/_content.rhtml:
1: 
2: <%= textilizable content, :text, :attachments => content.page.attachments %> 3:
app/helpers/application_helper.rb:504:in `parse_inline_attachments' app/helpers/application_helper.rb:502:in `gsub!' app/helpers/application_helper.rb:502:in `parse_inline_attachments' app/helpers/application_helper.rb:458:in `send' app/helpers/application_helper.rb:458:in `textilizable' app/helpers/application_helper.rb:457:in `each' app/helpers/application_helper.rb:457:in `textilizable' app/helpers/application_helper.rb:477:in `parse_non_pre_blocks' app/helpers/application_helper.rb:456:in `textilizable' app/views/wiki/_content.rhtml:2:in `_run_rhtml_app47views47wiki47_content46rhtml_locals_content_object' app/views/wiki/show.rhtml:30:in `_run_rhtml_app47views47wiki47show46rhtml' app/controllers/wiki_controller.rb:80:in `show' public/dispatch.fcgi:24 Rendering /home/m/share/htdocs/redmine/public/500.html (500 Internal Server Error)
修改 app/helpers/application_helper.rb:504, 將 sort_by 拿掉就好了,所以就想說是不是資料庫的問題,改完 DB 之後,果然就好了。所以這支 application_helper.rb 也不必 hack 了。
504 #       attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
505         attachments ||= options[:attachments]
最後是更新 wiki contents 了,請照著 github 上的說明來做。

https://xfalcons@github.com/xfalcons/migrate-trac-to-redmine.git

後續,接下來會試一些好用的 plugins ,到時再分享。

2011年4月18日 星期一

安裝 Remine 及 Migrate Trac to Redmine 之解決 wiki format 的相容問題(一)


Requirements:
  • CentOS 5.x
  • Redmine 1.1.x
  • Ruby 1.8.7
  • RubyGems: 1.3.7
  • Sqlite: 3.6.16 (For migration Trac to Redmine)
  • Rails: 2.3.5
  • Rack: 1.0.1
  • MySQL 5.1 or higher (recommended)
  • openssl + openssl-devel
  • zlib + zlib-devel
官方文件:http://www.redmine.org/projects/redmine/wiki/RedmineInstall


原本想說,直接用現有的 rpm packages 來安裝以上的軟體就好了,可是最新的 ruby rpm 只有到 1.8.5 而已,所以只能用自己 compile 的方式來解決。


0. 安裝 compile 所需要的 packages
# yum install zlib-devel curl-devel expat-devel gettext-devel gcc make
1. 安裝 ruby 1.8.7:
~# cd ~
~# wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p249.tar.gz
~# tar zxvf ruby-1.8.7-p334.tar.gz
~# cd ruby-1.8.7-p334
~/ruby-1.8.7-p334 # ./configure --prefix=/usr
~/ruby-1.8.7-p334 # make
~/ruby-1.8.7-p334 # make install
~/ruby-1.8.7-p334 # which ruby
/usr/bin/ruby
~/ruby-1.8.7-p334 $ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
 3. 安裝 sqlite 3.6.16:
~ # cd ~
~ # wget http://www.sqlite.org/sqlite-amalgamation-3.6.16.tar.gz
~ # tar xvzf sqlite-amalgamation-3.6.16.tar.gz
~ # cd sqlite-3.6.16
~ /sqlite-3.6.16 # ./configure --prefix=/usr
~ /sqlite-3.6.16 # make
~ /sqlite-3.6.16 # make install
~ /sqlite-3.6.16 # sqlite3 -version
3.6.16
4. 安裝 rubygem 1.3.7
~ # wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
~ # tar xvfz rubygems-1.3.7.tgz
~ # cd rubygems-1.3.7
~ /rubygems-1.3.7 # ruby setup.rb
5. 安裝 rails & rack & sqlite3
~ # gem install rails -v=2.3.5
~ # gem install rack -v=1.0.1
~ # gem install i18n -v=0.4.2
~ # gem install sqlite3-ruby
6. 安裝 mysql
~ # yum install mysql-server
~ # yum install mysql.x86_64
~ # yum install mysql-devel
~ # yum install ruby-mysql
~ # gem install mysql
7. 安裝 apache, fcgid(fastcgi)
~ # yum install httpd.x86_64
~ # yum install fcgi.x86_64   
~ # yum install fcgi-devel.x86_64
~ # yum install mod_fcgid.x86_64
~ # gem install fcgi
8. 安裝 redmine
~ # wget http://rubyforge.org/frs/download.php/74419/redmine-1.1.2.tar.gz
~ # tar xvfz redmine-1.1.2.tar.gz
~ # mkdir /var/www
~ # mv redmine-1.1.2 /var/www/redmine
9. 設定 redmine (依照官方說明即可)

2. Create an empty database and accompanying user named redmine for example.
For MySQL:
create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'my_password';
grant all privileges on redmine.* to 'redmine'@'localhost';

3. Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment.
Example for a MySQL database:
production:
  adapter: mysql
  database: redmine
  host: localhost
  port: 3306
  username: redmine
  password: my_password
4. Generate a session store secret.
rake generate_session_store
5. Create the database structure, by running the following command under the application root directory:
RAILS_ENV=production rake db:migrate
6. Insert default configuration data in database, by running the following command:
RAILS_ENV=production rake redmine:load_default_data
7. Setting up permissions
NB: Windows users have to skip this section.
The user who runs Redmine must have write permission on the following subdirectories: files, log, tmp (create the last one if not present).
Assuming you run Redmine with a redmine user:
mkdir tmp public/plugin_assets
sudo chown -R redmine:redmine files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets
8. Test the installation by running WEBrick web server:
ruby script/server webrick -e production
Once WEBrick has started, point your browser to http://localhost:3000/. You should now see the application welcome page.
Note: Webrick is not suitable for normal use, please only use webrick for testing that the installation up to this point is functional. It is not recommended to use webrick for anything other than development. Use one of the many other guides in this wiki to setup redmine to use either passenger (aka mod_rails) or mongrel to serve up your redmine.
9. Use default administrator account to log in:
  • login: admin
  • password: admin
10. 設定 Apache config & fastcgi
# vi /etc/httpd/conf.d/redmine.conf
<VirtualHost *:80>
      ServerName doc1.corp.muchiii.com
      DocumentRoot /home/m/share/htdocs/redmine/public/
      ErrorLog logs/redmine_error_log

      <Directory /home/m/share/htdocs/redmine/public/>
         AllowOverride all
         Options Indexes ExecCGI FollowSymLinks
         Order Deny,Allow
         Deny from all
         Allow from 122.146.2.130 172.17.8.31
      </Directory>
</VirtualHost>
# vi /var/www/redmine/public/.htaccess
<IfModule mod_fcgid.c>
        AddHandler fcgid-script .fcgi
</IfModule>
<IfModule mod_cgi.c>
        AddHandler cgi-script .cgi
</IfModule>
Options  FollowSymLinks  ExecCGI

RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.] )$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
<IfModule mod_fcgid.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
</IfModule>
Save the config and restart your httpd server
# /usr/sbin/service httpd configtest
# /usr/sbin/service httpd restart
Open your browser and hit http://redmine.mydomain.com, use default administrator account to log in.



11. Migrate Trac to Redmine, 轉移 Trac 的 project(sqlite3 格式) 到 Redmine 上。官方文件:http://www.redmine.org/projects/redmine/wiki/RedmineMigrate, 由於預設安裝的 migrate_from_trac.rake 會有一點點小問題(http://www.redmine.org/issues/6868),所以需要手動改一下 source codes (/var/www/redmine/lib/tasks/migrate_from_trac.rake).


The problem seems to be that function Time.fake() has problem to handle when the given input is nil.
class ::Time
    class << self
      alias :real_now :now
      def now
        real_now - @fake_diff.to_i
      end
      def fake(time)
        @fake_diff = real_now - time
        res = yield
        @fake_diff = 0
       res
      end
    end
  end
To solve that issue I modified this function in such way :
class ::Time
    class << self
      alias :real_now :now
      def now
        real_now - @fake_diff.to_i
      end
      def fake(time)
         time = 0 if time.nil? 
        @fake_diff = real_now - time
        res = yield
        @fake_diff = 0
       res
      end
    end
  end
接下來,就照著官方文件的步驟:
1. Run the following command, where test is your Redmine target environment:
rake redmine:migrate_from_trac RAILS_ENV="test"
2. The script (source:trunk/lib/tasks/migrate_from_trac.rake) asks you for your Trac settings:
Trac directory []: /var/trac/myproject
Trac database adapter (sqlite, sqlite3, mysql, postgresql) [sqlite]:
Database encoding [UTF-8]:
Target project identifier []: myproject
Trac directory is the root directory of your Trac environment. Redmine will look in this directory for db/trac.db (if you choose sqlite/sqlite3 database) and the attachments directory.
When using a mysql or postgresql Trac database, the script will ask you for the connection parameters (host, database name, username and password).
Target project identifier is the identifier of the Redmine project in which the data will be loaded (the project is created if not found).
4. The script migrates your data:
Deleting data
Migrating components..............................
Migrating milestones..............
Migrating custom fields.......
Migrating tickets.................................
Migrating wiki...........

Components: 29/30
Milestones: 14/14
Tickets: 1275/1275
Ticket files: 106/106
Custom values: 4409/4409
Wiki edits: 102/102
最後的問題會是 wiki 轉到 redmine 之後,所有的 wiki link 都亂掉了。預計用一個 script 來解決。


待續...

2011年4月15日 星期五

sendmail dead.letter/user unknown 問題 (dead.letter issue)


問題:在主機 a1.corp.xfalcons.com 要送信到 kevin@xfalcons.com,但是 xfalcons.com 的收信主機實際上是 host 在 gmail.com 的。

問題發生的起因:
1. a1.corp.xfs.com 修改主機名稱成 a1.corp.xfalcons.com
2. xfalcons.com 的收信伺服器 host 在 gmail.com 上
3. 而在 /etc/mail/sendmail.cf 裡有這樣的設定
Cwlocalhost
# file containing names of hosts for which we receive email
Fw/etc/mail/local-host-names

# my official domain name
# ... define this only if sendmail cannot automatically determine your domain
#Dj$w.Foo.COM
並且 /etc/mail/local-host-names 檔案裡,包含了
xfalcons.com
這樣的設定結果,造成 sendmail 認為本機是可以收 userXXX@miiicasa.com 的信件,可是我們要的是它送到 gmail 的 miiicasa.com 去。

解決方式:清空 /etc/mail/local-host-names 的檔案,或是寫成真正的主機名稱,如:a1.corp.xfalcons.com

另一解法是說,直接修改 /etc/mail/sendmail.cf 把 #Dj$w.Foo.COM 的註解拿掉,並且把 Foo.COM 改成一個不存在的 domain ,就可以了,或是修改 /etc/mail/sendmail.mc
define(`confDOMAIN_NAME', `mail.example.net')dnl
不過好像有點問題。