perlbrewとextlibなアプリのcronとかdaemontools
perl は system perl じゃなくて perlbrew で入れて、アプリで必要な CPAN モジュールは全てアプリのディレクトリ下の extlib というディレクトリにインストールする方式は個人的にはいい感じだよなぁと思いつつ、cron とか daemontools がいつもどうやるのが正解なのか分からず困ってた。
またセットアップする機会があったので色々考えた結果、こんな感じなら割とすっきりした感じになった。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* * * * * /home/riywo/MyApp/env perl -e 'print "$@"' > /tmp/hoge 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export HOME=/home/riywo | |
cd ~/MyApp | |
source ~/perl5/perlbrew/etc/bashrc | |
perlbrew use perl-5.14.2 | |
export PERL5OPT="-Mlib=./extlib/lib/perl5" | |
export PATH="./extlib/bin:$PATH" | |
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec 2>&1 | |
exec setuidgid riywo \ | |
/home/riywo/MyApp/env \ | |
plackup -r -s Starman --workers 10 -a app.psgi |
env
このファイルがキモで、アプリのディレクトリに移動しつつ、いい感じに perl とか PATH とか@INC を設定して、渡されたコマンドを実行してくれる。
# perl -v
This is perl, v5.8.8 built for x86_64-linux-thread-multi
# ./env perl -v
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux
crontab
あとは上の env を使ってあげるだけ。
daemontools の run
シンプル。
まとめ
だいぶべた書きの項目もあるけど、アプリ毎にちょちょいと作ってあげればいいんじゃないかな!
envdir を使うにはどうすればいいかとかは、今は考えない。