tDiary 2.1.4からgit版4.1.1へアップグレード
tDiary 2.1.4からgit版4.1.1へアップグレード
概要
tDiaryを2.1.4から4.1.1へ上げる。Rubyを1.9へ上げるうえに、あれこれパッケージをいれないといけない。また、td2ファイルのEUC to UTF-8自動変換も動いているようだが文字化けするので、自分で変換する必要がある。
環境
- Debian 7.7 (Wheezy)
- Ruby 1.8
- Apache 2.2 suexec
方針
git版tDiaryを入れる。後々できるだけ楽にアップグレードできるようにする。
準備
Ruby 1.9とパッケージを入れる。 Rubyのパッケージはgemで入れる。 Rubyパッケージをbundleで入れると必要なパッケージが一発で入ってお手軽だが、~/.bundleに入るのでApache suexecで動く気がせずパス。
# -- (rootで実行する) apt-get install ruby1.9 update-alternatives --set ruby /usr/bin/ruby1.9.1 apt-get install libsqlite3-dev gem install bundler gem install rake --version '10.4.2' gem install mime-types --version '2.4.3' gem install mini_portile --version '0.6.1' gem install nokogiri --version '1.6.5' gem install test --version '0.6.2' gem install rack-test --version '0.6.2' gem install xpath --version '2.0.0' gem install capybara --version '2.4.4' gem install ffi --version '1.9.6' gem install childprocess --version '0.5.5' gem install rest-client --version '1.6.7' gem install docile --version '1.1.5' gem install simplecov-html --version '0.8.0' gem install simplecov --version '0.9.1' gem install tins --version '0.13.2' gem install term-ansicolor --version '1.2.2' gem install coveralls --version '0.7.2' gem install diff-lcs --version '1.2.5' gem install jasmine-core --version '2.1.3' gem install phantomjs --version '1.9.7.1' gem install jasmine --version '2.1.0' gem install launchy --version '2.4.3' gem install pit --version '0.0.7' gem install power_assert --version '0.2.2' gem install racksh --version '1.0.0' gem install redcarpet --version '3.2.2' gem install rspec-support --version '3.1.2' gem install rspec-core --version '3.1.7' gem install rspec-expectations --version '3.1.2' gem install rspec-mocks --version '3.1.3' gem install rspec --version '3.1.0' gem install rubyzip --version '1.1.6' gem install websocket --version '1.2.1' gem install selenium-webdriver --version '2.44.0' gem install sequel --version '4.17.0' gem install sqlite3 --version '1.3.10' gem install test-unit --version '3.0.8' gem install rack --version '1.6.0'
Webブラウザで接続するとServer Errorになるときはrubyモジュールが不足している可能性がある。 そのときはコマンドとしてindex.rbを実行すると必要なモジュールとバージョンがわかる。 (bundle listコマンドでもわかる模様)
tDiary導入
tDiary本体は/home/httpd/tdiary-coreへ設置する。 コンテンツとCGIは各ユーザの~/public_html/tdiaryへ設置して、これ以外のファイルはシンボリックリンクで済ませる。 CGIもシンボリックリンクで済ませたいところだが、 suexecではシンボリックリンクのCGIを許さないようなので実体のファイルとして設置する。 tDiary自身をgemで入れることもできるが、tdiary serverとApacheとの連携がよくわからないのでパス。
# -- (www-dataユーザで) # -- gitで取り出す。ここで cd /home/httpd/ git clone https://github.com/tdiary/tdiary-core.git # -- plugin設置用 mkdir -p /home/httpd/tdiary-plugin # -- (実行ユーザで) cd ~/public_html mkdir tdiary cd tdiary mkdir data mkdir images mkdir tmp cp -p /home/httpd/tdiary-core/dot.htaccess .htaccess cp -p /home/httpd/tdiary-core/tdiary.conf . ln -s /home/httpd/tdiary-core/index.rb . ln -s /home/httpd/tdiary-core/Gemfile . ln -s /home/httpd/tdiary-core/js . ln -s /home/httpd/tdiary-core/lib . ln -s /home/httpd/tdiary-core/misc . ln -s /home/httpd/tdiary-core/spec . ln -s /home/httpd/tdiary-core/theme . ln -s /home/httpd/tdiary-core/views . # -- suexec対策 chgrp -R users .
index.fcgi
#!/usr/bin/env ruby load '/home/httpd/tdiary-core/index.fcgi'
update.rb
#!/usr/bin/env ruby require '/home/httpd/tdiary-core/update'
/home/<ユーザ名>/public_html/tdiaryディレクトリは下記のようになる。
drwxr-sr-x 6 <ユーザ名> users 4096 Jan 2 15:45 . drwxr-sr-x 14 <ユーザ名> www-data 4096 Jan 2 12:33 .. -rw-r--r-- 1 <ユーザ名> users 990 Jan 2 11:41 .htaccess lrwxr-xr-x 1 <ユーザ名> users 31 Jan 2 11:59 Gemfile -> /home/httpd/tdiary-core/Gemfile -rw-r--r-- 1 <ユーザ名> users 3184 Dec 31 20:36 Gemfile.lock drwxr-s--- 15 <ユーザ名> users 4096 Jan 2 15:41 data drwxr-sr-x 13 <ユーザ名> users 4096 Jan 1 01:20 images -rwxr-xr-x 1 <ユーザ名> users 63 Jan 2 15:28 index.fcgi lrwxr-xr-x 1 <ユーザ名> users 32 Jan 2 15:29 index.rb -> /home/httpd/tdiary-core/index.rb lrwxr-xr-x 1 <ユーザ名> users 26 Jan 2 11:59 js -> /home/httpd/tdiary-core/js lrwxr-xr-x 1 <ユーザ名> users 27 Jan 2 11:59 lib -> /home/httpd/tdiary-core/lib lrwxr-xr-x 1 <ユーザ名> users 28 Jan 2 11:59 misc -> /home/httpd/tdiary-core/misc lrwxr-xr-x 1 <ユーザ名> users 28 Jan 2 11:59 spec -> /home/httpd/tdiary-core/spec drwxr-sr-x 2 <ユーザ名> users 4096 Jan 1 00:22 static -rw-r--r-- 1 <ユーザ名> users 20611 Dec 31 17:34 tdiary.conf lrwxr-xr-x 1 <ユーザ名> users 29 Jan 2 11:59 theme -> /home/httpd/tdiary-core/theme drwxr-s--- 2 <ユーザ名> users 4096 Dec 31 20:44 tmp -rwxr-xr-x 1 <ユーザ名> users 62 Jan 2 15:41 update.rb lrwxr-xr-x 1 <ユーザ名> users 29 Jan 2 11:59 views -> /home/httpd/tdiary-core/views
プラグインの設置
下記のプラグインを/home/httpd/tdiary-pluginディレクトリへ設置する。
- image_ex.rb
- count_age.rb
コンテンツの引っ越し
imageディレクトリの画像ファイルとdataディレクトリのデータファイルを引っ越す。 dataディレクトリのファイルはEUC to UTF-8化する必要あり。 td2ファイルは自動変換してくれることになっているが、やってみたところマルチバイト文字が完全に文字化けしてしまうのでやむなし。
EUC to UTF-8スクリプト(/tmp/e2u.sh)
#!/bin/sh # usage: sh /tmp/e2u.sh 20*/*.td2 for f in $* ; do # -- 元ファイルのファイル名末尾に.eucを付加する。 mv $f $f.euc # -- EUC to UTF-8変換 nkf -E -w $f.euc | sed -e 's/TDIARY2.00.00/TDIARY2.01.00/' > $f done
コンテンツの引っ越し
# -- (実行ユーザ) cd ~/public_html/tdiary cp -pR <もとのtDiaryディレクトリ>/images . cp -pR <もとのtDiaryディレクトリ>/data . cd data # -- EUC to UTF-8変換 find . -type f | xargs sh /tmp/e2u.sh # -- 内容がUTF-8になっていることを確認する。 # -- 元ファイルを削除 find . -name "*.euc" | xargs rm
.htaccess
~/public_html/tdiary/.htaccessをstatic htmlに対応し、また必要なコンテンツのみアクセス可とするように設定する。
# -- tdiary .htaccess for users # -- static contents (with html_anchor.rb plugin) RewriteEngine On RewriteBase /~<ユーザ名>/tdiary RewriteCond %{REQUEST_URI} ^\/~<ユーザ名>\/tdiary\/([0-9]{4}|[0-9]{6}|[0-9]{8}|[0-9]{8}-[0-9]+)\.html$ RewriteCond /home/<ユーザ名>/public_html/tdiary/static/%1.html -f RewriteRule .* /~<ユーザ名>/tdiary/static/%1.html [L,PT] RewriteRule ^index\.html$ index.fcgi [L,PT] RewriteRule ^([0-9]{4}|[0-9]{6}|[0-9]{8}|[0-9]{8}-[0-9]+)\.html$ index.fcgi?date=$1 [L,PT] # -- hide except contents <Files ~ ".*"> deny from all </Files> <Files ~ "\.(js|png|gif|css|jpg|html)$"> deny from all allow from all </Files> <Files ~ "^$"> deny from all allow from all </Files> <Files ~ "(index.fcgi|index.rb)"> deny from all allow from all </Files> # -- update.rb requires authentication <Files update.rb> Deny from all Allow from 192.168.0. AuthName "tDiary" AuthType basic Require user <ユーザ名> Satisfy any </Files>
tdiary.confの設定
- ~/public_html/tdiary/tdiary.confにimage_ex.rb, count_age.rbプラグイン関連の設定を追加する。
- プラグイン読み込みパスを追加する。
# -- sp @options['sp.path'] = ['/home/httpd/tdiary-core/misc/plugin','/home/httpd/tdiary-plugin/']
プラグインの有効化
WebブラウザからtDiaryを開き、設定画面で下記のプラグインを有効化する。
- image_ex.rb
- count_age.rb
- category.rb -- カテゴリデータを再生成すること。
- html_anchor.rb
そのほか
- Rubyを1.9へ上げてしまったが、VikiwikiはRuby 1.9に対応しないので、1.8を使うようにVikiwikiのindex.rbの1行目ででruby1.8を使うに変更する。
- DebianでRubyを使うときにAPTとgemとどっちで管理していいんだかよくわからん。
- 静的なhtmlファイルを保存する仕掛けを入れていて、Apacheの設定でも静的ファイルがないときだけCGIを呼び出すようにしかけていたが、index.rbとupdate.rbがずいぶん変わっていて、コレもパス。
- つぎからは/home/httpd/tdiary-coreを更新するだけでいいはず。
参考
先人の業績を寄せ集めて実現できております。
- tDiary を gem でインストール可能にした http://www.machu.jp/diary/20130507.html#p01
- 負荷対策:静的 HTML 化 http://tmaeda.s45.xrea.com/td/20041106.html
- Apache + fcgi + tDiary + rbenvでgithubさきっちょを追いかける環境を一旦整理 http://www.tamoot.net/d/20130822.html