前の月 / 次の月 / 最新

MuraTaka 速記メモ / 2008-08

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12

2008-08-31 Sun

Rails View で呼び出された Action 名を取得する [RubyOnRails]

- Rubyist Magazine - RubyOnRails を使ってみる 【第 4 回】 ActionPack

controller.action_name

2008-08-29 Fri

JavaScript validation (入力チェック) ライブラリを試してみる [JavaScript]

- あるSEのつぶやき: Ajaxライブラリまとめ
入力チェックだけではないが、いろいろとまとめられている。
上記にはないようだが、当初
- JSValidate
を使おうと思っていたのだが、最終的に、
- フォームの入力エラーを吹き出しで教えてくれる JavaScript
を気に入ったのでこちらを使うことに。

2008-08-27 Wed

Rails のサーバとしてpassenger を使ってみる [CentOS][RubyOnRails]

Apache サーバは、CentOS 5.2 で現在パッケージ管理されているバージョンを使う。

# yum info httpd
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 * addons: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
Installed Packages
Name   : httpd
Arch   : i386
Version: 2.2.3
Release: 11.el5_1.centos.3
Size   : 2.8 M
Repo   : installed
Summary: Apache HTTP Server
Description:
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

dev も入れており、現在のインストール状況は以下の通り。
# yum list *httpd*
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 * addons: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
Installed Packages
httpd.i386                               2.2.3-11.el5_1.centos. installed       
httpd-devel.i386                         2.2.3-11.el5_1.centos. installed       
Available Packages
httpd-manual.i386                        2.2.3-11.el5_1.centos. base            
system-config-httpd.noarch               5:1.3.3.3-1.el5        base     

■ Passenger のインストール

# gem install passenger
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed fastthread-1.0.1
Successfully installed rack-0.4.0
Successfully installed passenger-2.0.3
3 gems installed
Installing ri documentation for fastthread-1.0.1...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing ri documentation for rack-0.4.0...
Installing ri documentation for passenger-2.0.3...
Installing RDoc documentation for fastthread-1.0.1...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing RDoc documentation for rack-0.4.0...
Installing RDoc documentation for passenger-2.0.3...
./doc/template/horo.rb:17: warning: already initialized constant FONTS
./doc/template/horo.rb:19: warning: already initialized constant STYLE
./doc/template/horo.rb:213: warning: already initialized constant XHTML_PREAMBLE
./doc/template/horo.rb:221: warning: already initialized constant HEADER
./doc/template/horo.rb:272: warning: already initialized constant FILE_PAGE
./doc/template/horo.rb:300: warning: already initialized constant CLASS_PAGE
./doc/template/horo.rb:338: warning: already initialized constant METHOD_LIST
./doc/template/horo.rb:486: warning: already initialized constant FOOTER
./doc/template/horo.rb:491: warning: already initialized constant BODY
./doc/template/horo.rb:503: warning: already initialized constant SRC_PAGE
./doc/template/horo.rb:531: warning: already initialized constant FR_INDEX_BODY
./doc/template/horo.rb:535: warning: already initialized constant FILE_INDEX
./doc/template/horo.rb:583: warning: already initialized constant CLASS_INDEX
./doc/template/horo.rb:584: warning: already initialized constant METHOD_INDEX
./doc/template/horo.rb:586: warning: already initialized constant INDEX

■ passenger-install-apache2-module を実行

# passenger-install-apache2-module

よきにいろいろとやってくれる。
最後に以下のメッセージを残して終了する。

The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3
   PassengerRuby /usr/local/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.

--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Ruby on Rails application in /somewhere. Add a virtual host
to your Apache configuration file, and set its DocumentRoot to
/somewhere/public, like this:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:

  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/doc/Users guide.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

■ Apache 設定ファイルへの設定の追加

- /etc/httpd/conf/httpd.conf
に上記メッセージの記載通りに追加。
# for Passenger
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/local/bin/ruby

バーチャルホストの設定と Rails コンテンツの場所を指定する。
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin hoge@example.com
    DocumentRoot /opt/app/rails_contents_root/public
    ServerName app1.example.com
    ErrorLog logs/app1-error_log
    CustomLog logs/app1-access_log combined
</VirtualHost>

以上。

■ Rails アプリの実行ユーザについて

Rails アプリケーションが動作するユーザは、$RAILS_ROOT/config/environment.rb のオーナーとなるようだ。



■ 参考

- Install Phusion Passenger (a.k.a. mod_rails / mod_rack)
  本家
- Redmine.JP Apache上でRuby on Railsアプリケーションを動かす/Passenger(mod_rails for Apache)の利用
- Passenger(mod_rails)設定メモ - Hello, world! - s21g

Postfix::携帯へのメールフォワード [CentOS]

~/.forward に携帯へ転送を行うため、アドレスを記載しておく。

mbox 方式と、Maildir 方式で書き方が違う。

Maildir 方式は、

~/MailDir
転送先メールアドレス
- Postfixの ~/.forward の書き方

Postfix::info@mydomain にメールが届かない [CentOS]

info に送っているものが何故か root に設定してあるメールアドレスに送られてくる。はて?
ログは以下の通り。

Aug 27 21:03:05 localhost postfix/local[12445]: 9A3AF34803A: to=<target@example.co.jp>, orig_to=<info@example.co.jp>, relay=local, delay=0.04, delays=0.03/0.01/0/0, dsn=2.0.0, status=sent (delivered to maildir)

原因は、
- /etc/aliases
info:          postmaster
なるほど、既に alias がきられてたってことか。
コメントアウトしておく。

CentOS サーバを用意する3::Postfix インストール [CentOS]

CentOS 5.2 にはデフォルトで sendmail が入っている。
これを Postfix に入れ替える。

■ スポール、キューの削除

# /usr/bin/mailq
/var/spool/mqueue is empty
                Total requests: 0
空なのでそのまま。
空で無い場合には、
# /usr/sbin/sendmail -q
で空にしておく。

■ sendmail の停止と自動実行の解除

# service sendmail stop
sm-client を停止中:                                        [  OK  ]
sendmail を停止中:                                         [  OK  ]

# chkconfig --list sendmail
sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@hoge ~]# chkconfig sendmail off
[root@hoge ~]# chkconfig --list sendmail
sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off

■ Postfix をパッケージでインストール

# yum list postfix
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 * addons: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
base                      100% |=========================| 1.1 kB    00:00     
updates                   100% |=========================|  951 B    00:00     
addons                    100% |=========================|  951 B    00:00     
extras                    100% |=========================| 1.1 kB    00:00     
Available Packages
postfix.i386                             2:2.3.3-2.1.el5_2      updates 
# yum install postfix
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 * addons: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package postfix.i386 2:2.3.3-2.1.el5_2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 postfix                 i386       2:2.3.3-2.1.el5_2  updates           3.6 M

Transaction Summary
=============================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 3.6 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): postfix-2.3.3-2.1. 100% |=========================| 3.6 MB    00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: postfix                      ######################### [1/1] 
postfix: fatal: config variable inet_interfaces: host not found: localhost

Installed: postfix.i386 2:2.3.3-2.1.el5_2
Complete!

■ MTA を切り替える

# alternatives --config mta

2 プログラムがあり 'mta' を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2

■ エイリアスの設定

# diff -u /etc/aliases /etc/aliases.org 
--- /etc/aliases        2008-08-27 17:52:08.000000000 +0900
+++ /etc/aliases.org    2005-04-26 01:48:42.000000000 +0900
@@ -93,4 +93,4 @@
 decode:                root
 
 # Person who should get root's mail
-root:          hoge@example.com
+#root:         marc

設定を反映。
# postalias /etc/aliases
postalias: fatal: config variable inet_interfaces: host not found: localhost
むっ?fatal が出ている。
これって yum でのインストールの時も出ているものだ。
/etc/aliaes.db のタイムスタンプは更新されている。
・・・一回ここはこのままとしておく。

■ main.cf の修正

- Papa-Net(パパネット)
に詳しい。

■ Postfix の起動/停止確認

# /etc/init.d/postfix start
Starting postfix:                                          [  OK  ]
[root@lhoge ~]# /etc/init.d/postfix stop 
Shutting down postfix:                                     [  OK  ]

/var/log/maillog でログは確認できる。

■ サービスへの登録

# chkconfig postfix on
[root@hoge ~]# chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off

■ 不正中継のチェック

- 第三者中継チェック RBL.JP
にてチェックを行う。
問題無し。

2008-08-25 Mon

Yum の運用 [CentOS][Yum]

- リポジトリの更新

# yum check-update
- インストールされている全パッケージのアップデート
# yum update

- ThinkIT 第3回:運用管理を各種ツールで自動化 (1/3)

2008-08-24 Sun

テーブルの rename [RubyOnRails]

ちょいと設計ミス。
テーブル名を変えたいのだが、どうするのか?

class RenameOldTableName < ActiveRecord::Migration
  def self.up
    rename_table :old_table_name, :new_table_name
  end

  def self.down
    rename_table :new_table_name, :old_table_name
  end
end
モデルとの関連で DB を作り直す時に問題が発生する可能性もある。
- Agile Web Development with Rails
  - Chapter 16 Migrations
    - 16.3 Managing Tables
      - Renaming Tables
      - Problems with rename_table
参照。

2008-08-15 Fri

AcitveRecord メモ [RubyOnRails]

■ has_many 関連モデルの登録

・dept.employees << Employee.new(:name => 'taka')
・dept.employees.build(:name => 'taka')
・dept.employees.create(:name => 'taka')

- build は新しいオブジェクトを作成して関連に追加するが、DB への保存は行わない。
- create は新しいオブジェクトを作成して関連追加した上で、DB への保存も行う。
- dept が DB に保存されていない状態であればいずれも DB への保存は行われない。

2008-08-12 Tue

Subversion リポジトリのバックアップと戻し [Subversion]

$ svnadmin dump /home/svn_rep > svn_rep_backup_`date +%Y%m%d`
$ svnadmin create /home/svn/svn_rep
$ svnadmin load /home/svn/svn_rep < svn_rep_backup_20050401

2008-08-10 Sun

Parallels Desktop 3.0 for Mac 8/31 まで半額の 5,985円 [Tool][Mac]

- Parallels Desktop 3.0 for Mac -パラレルズ・デスクトップ-

2008-08-09 Sat

読みたい本::サーバ/インフラを支える技術 ~スケーラビリティ、ハイパフォーマンス、省力運用 [Books]

[24時間365日] サーバ/インフラを支える技術 ~スケーラビリティ、ハイパフォーマンス、省力運用 (WEB+DB PRESS plusシリーズ) (WEB+DB PRESSプラスシリーズ)
安井 真伸 横川 和哉 ひろせ まさあき 伊藤 直也 田中 慎司 勝見 祐己
技術評論社
売り上げランキング: 31

ウィルコムの料金コース変更とダイアルアップの接続契約の解除 [生活]

- ウィルコムのリアルインターネットプラスの解約を行う。 (2,000/月)
- au one net にてダイアルアップのアクセスポイントの契約を行っていたのでこれも解除(980/月)

2008-08-06 Wed

radio_button_tag と observe_field での組み合わせはまともに動かない? [RubyOnRails]

Google 先生に聞いてまわっていたが、どうもそうらしい?
HTML タグの input radio の onclick イベントに remote_function を書いて回避する。

render :action オプションの注意点 [RubyOnRails]

レスポンスに使いたいテンプレートが同じコントローラの別のアクションと同名のテンプレートである時には render の :action オプションを使用して表示する。

render :action => 'edit'

この時の注意点。
- :action という名前ではあるが、実際にアクションから実行される訳ではない!
  あくまでの render 対象のテンプレートを指定してるだけ。
- デフォルトではレイアウトが適用されている。

2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12

最終更新時間: 2009-10-14 00:22