What have you found for these years?

2009-01-22

沒人用 rack 跑 rails 嗎?

updated: 啊,成功了,真滿意...
rack cluster config 仿造 thin cluster, 不過這邊的 env 是
rack 的 env. rails 的 env 要在 config.ru 裡面設定。

---
pid: tmp/pids/web_server_rack.pid
log: log/web_server_rack.log
port: 3000
chdir: /home/photos
daemonize: true
host: 0.0.0.0
servers: 5
user: photos
group: photos
rackup: web_server/config.ru
server: thin
environment: none
$ rack app:server:restart
Sending TERM to thin(27808)...
Killed thin(27808)
Starting thin on 0.0.0.0:3500...

Sending TERM to thin(27811)...
Killed thin(27811)
Starting thin on 0.0.0.0:3501...

Sending TERM to thin(27814)...
Killed thin(27814)
Starting thin on 0.0.0.0:3502...

Sending TERM to thin(27817)...
Killed thin(27817)
Starting thin on 0.0.0.0:3503...

Sending TERM to thin(27820)...
Killed thin(27820)
Starting thin on 0.0.0.0:3504...

Sending TERM to thin(27823)...
Killed thin(27823)
Starting thin on 0.0.0.0:3000...

Sending TERM to thin(27826)...
Killed thin(27826)
Starting thin on 0.0.0.0:3001...

Sending TERM to thin(27829)...
Killed thin(27829)
Starting thin on 0.0.0.0:3002...

Sending TERM to thin(27832)...
Killed thin(27832)
Starting thin on 0.0.0.0:3003...

Sending TERM to thin(27835)...
Killed thin(27835)
Starting thin on 0.0.0.0:3004...

設定也很簡單:
namespace :web_server do
[:start, :stop, :restart].each{ |cmd|
desc "#{cmd} web_server"
task cmd do
ENV['config'] = 'web_server/rack.yml'
Rake::Task["app:rack:#{cmd}"].execute
end
}
end


找半天 rails 沒 adapter, 連 google 都找不到。
最後總算發現了,原來是在 thin 裡面!什麼鬼,rails 不做反而是 thin 做。
而且這是很久以前的事了吧?為什麼 rails 不改用 rack 或是內建?

另外這個 adapter 還有問題,Lint 說 Set-Cookie 應該要是 string,
卻是 array! 拿掉 if Thin.ruby_18? 改成:

[@response['Set-Cookie'], cookies].compact.join("\n")

可以解決這個小問題... 這樣總算是能用 rackup 跑 rails 了,
於是之前寫的 rack cluster 才能用。(目前包在 app-deploy 裡)
只是這 adapter 居然有一百多行,也未免太長了吧...
每個人都在說 rails 支援 rack, 都是像這樣拿 thin 去改的嗎???

有時候 ruby 的東西真的是不可思議,每個人都在說,
結果實際上好像根本沒人在用,一用都是問題百出...(還是沒人肯分享?)
evented mongrel 也是一例。

要不是很喜歡 ruby, 而且東西都用 ruby 做了,真的是...
改玩 sapphire 吧 lol

2 retries:

Hinoris said...

創造時代的不是標點符號,而是使用標點符號的人。

Lin Jen-Shin (godfat) said...

創造時代的不是科技,而是使用科技的人。

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0