unicornとunicorn_railsのオプションの違い
unicorn
とunicorn_rails
はほとんど同じ挙動をして、
application serverを立ち上げてくれますが、一部オプション指定の意味が違います。
ちょっとハマったので書いておくことにします。
結論
unicorn
のオプション-E
はRACK_ENV
を設定unicorn_rails
のオプション-E
はRAILS_ENV
を設定
参考: http://unicorn.bogomips.org/
経緯1
Capistrano 3を導入しまして、unicornを使っていたので無邪気に
を使っていました。(僕の環境では0.3.2) 普通に動かしていたんですが、muninがunicornのmemory statusをうまく取得できていないようでした。
該当のmuninのplugin
pluginに目をちゃんと通すとわかるんですが、
def memory_usage result = { :master => {master_pid => nil}, :worker => {} } ps_output = `ps auxw | grep unicorn_rails` ps_output.split("\n").each do |line|
なるほど。unicorn_rails
でgrepしてます。
ということで、よく調べてみると、sepastian-capistrano3-unicorn
のデフォルトでは
unicorn
を使ってunicornプロセスを起動していて、このままではこのunicorn_memory_status
に引っかからないわけです。
ということで、unicorn立ち上げをunicorn_rails
を通して実行する必要があるわけですがこれはわけなく行えます。
sepastian-capistrano3-unicorn
は、unicorn_bin
というパラメータを用意してまして、これのデフォルトがunicorn
になっているわけなので、ここを変更する。
RAILS_ROOT/config/deploy.rbに下記記述を追記します。
set :unicorn_bin, ->{"unicorn_rails"}
(ラムダで囲んでんのは特に深い意味は無いんですが、評価時にいろいろ変更するようなモノが多いので念のため標準的にこうするようにしています。)
とここで世界は平和に終ると思っていました。
経緯2
unicornの時の-E
パラメータがRACK_ENV
であるということは理解していたので、RAILS_ENV
をunicorn実行前に設定するようにしてたわけです。
こんな感じで
RAILS_ENV=hogehoge; unicorn -E development .....
僕はVM上でrailsを動かすコトが多くて、vm
というRAILS_ENVをつくっていました。
しかしunicorn_rails
に変更してみたら、僕のVMで急にunicornが立ち上がらなくなりました。
RAILS_ENV=vm; unicorn_rails -E development .....
どうも、dababase.ymlにadapterの指定がない的なエラーがはかれていて、おかしーなーと思ったんです。 と、ここで気付きました。
-E
オプションが、RAILS_ENVを上書いていることを。
んで、下記をみた
なるほどね。
以上!
Variable, subroutine, and package names have to be in CamelCase
criticってこんなのってあるの?
Variable, subroutine, and package names have to be in CamelCase at line 12, column 5. (no explanation). (Severity: 5)
えーー。
Perl deleteの挙動を確認
Perlのdelete関数の挙動を確認してみた。
想定通りですた。
#!/usr/bin/Perl use strict; use warnings; use utf8; use Data::Dumper; my $test = +{ a => 1, b => 'b', c => +{ d => 2, e => 'e', f => +{ g => 3, h => 'h', }, }, }; my $c = $test->{c}; my $f = $test->{c}->{f}; print '# $test hash ############' . "\n"; print Dumper $test; print "\n"; print '# $c hash ###############' . "\n"; print Dumper $c; print "\n"; print '# $f hash ###############' . "\n"; print Dumper $f; print "\n"; print '# delete $test->{c}->{f}->{h}; #' . "\n"; delete $test->{c}->{f}->{h}; print "\n"; print '# $test hash ############' . "\n"; print Dumper $test; print "\n"; print '# $c hash ###############' . "\n"; print Dumper $c; print "\n"; print '# $f hash ###############' . "\n"; print Dumper $f; print "\n"; print '# print Dumper $test->{c}->{f}->{h}; #' . "\n"; print Dumper $test->{c}->{f}->{h}; print "\n"; print '# delete $test->{c}; #' . "\n"; delete $test->{c}; print "\n"; print '# $test hash ############' . "\n"; print Dumper $test; print "\n"; print '# $c hash ###############' . "\n"; print Dumper $c; print "\n"; print '# $f hash ###############' . "\n"; print Dumper $f; print "\n"; exit;
# $test hash ############ $VAR1 = { 'c' => { 'e' => 'e', 'd' => 2, 'f' => { 'h' => 'h', 'g' => 3 } }, 'a' => 1, 'b' => 'b' }; # $c hash ############### $VAR1 = { 'e' => 'e', 'd' => 2, 'f' => { 'h' => 'h', 'g' => 3 } }; # $f hash ############### $VAR1 = { 'h' => 'h', 'g' => 3 }; # delete $test->{c}->{f}->{h}; # # $test hash ############ $VAR1 = { 'c' => { 'e' => 'e', 'd' => 2, 'f' => { 'g' => 3 } }, 'a' => 1, 'b' => 'b' }; # $c hash ############### $VAR1 = { 'e' => 'e', 'd' => 2, 'f' => { 'g' => 3 } }; # $f hash ############### $VAR1 = { 'g' => 3 }; # print Dumper $test->{c}->{f}->{h}; # $VAR1 = undef; # delete $test->{c}; # # $test hash ############ $VAR1 = { 'a' => 1, 'b' => 'b' }; # $c hash ############### $VAR1 = { 'e' => 'e', 'd' => 2, 'f' => { 'g' => 3 } }; # $f hash ############### $VAR1 = { 'g' => 3 };
参照先は残ってる。
perlのガベージコレクションは参照カウントだから、
参照はずれたオブジェクトはなんかのタイミングで消されるのでしょう。
設定ファイル
昨日、うっかりMacbook Airをポチっとしてしまった。
そのせいで、僕所有のmacが二台になってしまうことに気づいた。
二台になると困る。
困るのが、設定ファイルだ。
.zshrcとか.emac.dだとか、もろもろ設定したものが二重管理になる。
そういうのは嫌なので、僕には個人の非公開リポジトリがあって
そこで一括管理しているんだが、管理方法としては、
configs/vimrc configs/screenrc
みたいに、configsというディレクトリの中に、vimrcを入れているだけだ。
これだと、設定ファイルをいっこいっこコピーして
自分の~/.vimrcみたいのを作んないと行けなそうだ。
それはメンドクサイし、一台で設定を変えたら、
その設定をもう一台で有効にするのが面倒くさすぎる。
そこで、こんな感じで ~/.vimrc -> ~/configs/vimrc
symlinkを作れば良いんだけど、
いくつか設定ファイルがあるとやっぱり面倒だ。
そこで、初期化シェルを書いてみた。
#!/bin/sh CONFIGS=( screenrc vim vimrc zshenv zshrc emacs.d gitconfig ) COMMAND='ln -s' CURRENT_DIR=`pwd` for FILE in "${CONFIGS[@]}";do TO="${CURRENT_DIR}/${FILE}" FROM="$HOME/.${FILE}" EXEC_STRING="${COMMAND} ${TO} ${FROM}" if [ -f ${FROM} ] || [ -d ${FROM} ] || [ -e ${FROM} ] ;then echo "Error: '${FROM}' already exists." >&2 continue fi if !([ -f ${TO} ] || [ -d ${TO} ]) ;then echo "Error: A source '${TO}' does not exist." >&2 continue fi `${EXEC_STRING}` if !([ -e ${FROM} ]) ;then echo "Error: Command '${EXEC_STRING}' failed." >&2 continue fi echo "Success: Created a symlink '${FROM}'." done exit 0
このスクリプト自体も、設定ファイルと同じディレクトリに入れておいて、リポジトリに上げちゃう。
新しいmacが届いたら、実行してやるという寸法です。
みんなはどうやって管理しているんだろう?
なんかもっといい方法あれば教えてください。
以下、備忘録
IFSとか完全に忘れていた。結局使わなかったが。。。。
mac ports
macのportsを使うときのvariantsという言葉を良く忘れる。
mac ports +
とかで検索する悲しいことはもうやめる。
Homebrewにする、、かな。
http://mxcl.github.com/homebrew/
Brainf*ck on Python
こんにちは。今日は雨ですね。
雨だし寒いし、僕はこういう日は家にいたい。
なんとなくPython気分が高ぶっている関係で、Pythonで何かが書きたい。
そんな日もあります。
勉強がてらBrainfuckのインタープリタ?をPythonで書いてみたのでよかったらみてみてください。
http://github.com/unlearned/Brainfuck-on-Python
ちなみにBrainfuckはこんな感じのやつ
http://ja.wikipedia.org/wiki/Brainfuck
Hello, world!はこんな風に書く事になります。
+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.------------.<++++++++.--------.+++.------.--------.>+.