ハマったところメモ2(capistrano, qpsmtpd)

capistrano

第1回 インストール - Capistrano 入門 - Ruby on Rails with OIAX
を見ながら config/deploy を編集。
cap deploy で、サーバにファイルがデプロイ&更新が反映されるようにしました。

  • shared_path 内に共通で使わせたいディレクトリを作られるように shared_children を設定し、その1つの lib/ にアリポジトリのファイルをコピー&他のディレクトリにsymlinkするようにした
  • plackup側では shared/lib/ の更新がされると再起動されるように -r オプションをつけて起動しておく)

こんな感じ↓

set :shared_children, %w(lib logs sessions uploads)

namespace :deploy do
    task :setup, :expect => { :no_release => true } do
        dirs  = [deploy_to, releases_path, shared_path]
        dirs += shared_children.map { |d| File.join(shared_path, d) }
        run "mkdir -p #{dirs.join(' ')}"
        run "chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
    end

    desc "**symlink to the shared directories."
    task :symlink, :expect => { :no_release => true } do
        run <<-CMD
        cp -r #{latest_release}/* #{shared_path}/lib &&
        ln -nfs #{shared_path}/uploads #{shared_path}/lib/public/images/user &&
        ln -nfs #{shared_path}/sessions #{shared_path}/lib/sessions &&
        ln -nfs #{shared_path}/logs #{shared_path}/lib/logs
        CMD
      end
end

参考

メール投稿の環境を作る qpsmtpd

qpsmtpd の導入
$ apt-get install qpsmtpd

自分の場合はpostfixを既に動かしているので、そちらでのport25のlistenするのを止めます。
(/etc/postfix/master.cf の以下をコメントにする)

#smtp      inet  n       -       -       -       -       smtpd
設定

ubuntuのapt-getで入れているので、まず以下で設定。

$ dpkg-reconfigure qpsmtpd 

listenさせるアドレスに、127.0.0.1 の他、サーバのローカルIPアドレスを指定。
あとは言われたとおり設定すれば大丈夫な気がします。

/etc/qpsmtpd 以下にあるファイルで設定.
plugins の以下をコメントにする

# install-time Debian default
#$include /etc/qpsmtpd/debian-queue-method

relayclients でローカルIPアドレスを追加する

# accept from localhost:
127.0.0.1
# accept from 192.168.0.0/16:
# 192.168.
192.168.

再起動

/etc/init.d/qpsmtpd restart

これで外部から telnet でport25につないでみて、応答があればとりあえず動作は完了。

プラグイン

http://e8y.net/blog/2007/07/07/p186.html を参考にして、プラグインを書く.
/usr/share/qpsmtpd/plugins 以下にファイルを追加し, /etc/qpsmtpd/plugins から呼び出させる。
自分のアプリの場合は、 mail_post.pl を実行してSTDINへメール内容を渡すように作っていたので、そんな処理を書きました。
/usr/share/qpsmtpd/plugins/twinp の内容(github)