Showing posts with label DreamHost. Show all posts
Showing posts with label DreamHost. Show all posts

Wednesday, August 13, 2008

扩展名原来很重要

所谓世事难预料,估计我在 DreamHost 有仇家,今天我的站点突然全线瘫痪,Catalyst 始终报 500 错误。可是,站点程序又完全没有更新过,百思不得其解。Google 了一圈又一圈,抱着死马当活马医的态度,把 pl 改成了看起来更 fastcgi 的 fcgi,哎,就好了。
[razzle ~]$ cp script/myapp_fastcgi.pl script/myapp_fastcgi.fcgi
[razzle ~]$ diff .htaccess.old .htaccess
1c1
< AddHandler fastcgi-script pl
---
> AddHandler fastcgi-script fcgi
12,13c12,13
< RewriteCond %{REQUEST_URI} !^/script/myapp_fastcgi.pl
< RewriteRule ^(.*)$ script/myapp_fastcgi.pl/$1 [PT,L]
---
> RewriteCond %{REQUEST_URI} !^/script/myapp_fastcgi.fcgi
> RewriteRule ^(.*)$ script/myapp_fastcgi.fcgi/$1 [PT,L]

没想出问题所在,如果哪位大侠精通此道,还望不吝赐教。

Sunday, February 04, 2007

在 DreamHost 虚拟主机上部署 Catalyst 应用

在虚拟主机上部署 Catalyst 应用的前提是用户可以自己安装 CPAN 模块,DreamHost 提供了 shell 环境,所以就完全没问题了。

如何在非 root 环境下安装 CPAN 模块,请参考 Catalyst Wiki 中的相关文章

好,在安装完 Catalyst 之后呢,那么就万事具备,只欠东风了。
虚拟主机,Catalyst 自带的 httpd 肯定是不能用的;没有 apache 的控制权限,mod_perl 也上不了;剩下还有 cgi 和 fastcgi 方式,还用想吗?当然用 fastcgi 咯~

下面就以 fastcgi 方式为例,分享一下我的一些经验。

一、部署环境
[hostname ~]$ ls -1
MyApp/ # 项目名
example.com/ # 域名

二、apache 环境
[hostname ~]$ ls -a1 example.com
.htaccess
script -> /home/islue/MyApp/script/
static -> /home/islue/MyApp/root/static/

软链接的意义很好理解,不罗嗦了,然后来看一下 .htaccess 文件。
[hostname ~]$ cat example.com/.htaccess
AddHandler fastcgi-script .pl

RewriteEngine On

# 避免屏蔽 DreamHost 提供的 Site Statistics 功能
RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/failed_auth.html$
RewriteRule ^.*$ - [L]

# fastcgi 工作模式
RewriteCond %{REQUEST_URI} !^/script/myapp_fastcgi.pl
RewriteRule ^(.*)$ script/myapp_fastcgi.pl/$1 [PT,L]

很容易理解吧,也不罗嗦了。

三、定制 myapp_fastcgi.pl
[hostname ~]$ cat MyApp/script/myapp_fastcgi.pl
...

BEGIN {
$ENV{CATALYST_ENGINE} ||= 'FastCGI';
unshift @INC, qw(
/home/islue/local/lib/perl/5.8
/home/islue/local/lib/perl/5.8.4
/home/islue/local/lib/perl5
/home/islue/local/lib/perl5/i386-linux-thread-multi
/home/islue/local/share/perl/5.8
/home/islue/local/share/perl/5.8.4
);
$SIG{'TERM'} = 'IGNORE';
}

...

我原以为,修改过了 .bashrc 之后,应该不需要再用 use lib 了,但是数次实践下来,不在 myapp_fastcgi.pl 里声明用户的 lib 还真不行。要是哪位知道这里的道道,记得告诉我啊。

至于为什么要 IGNORE TERM,故事是这样的,很久很久以前,世界和平,大家都过着男耕女织的生活,不用在意什么,MyApp 也能跑得欢快。

突然有一天,电闪雷鸣,大雨瓢泼,MyApp 就再也跑不起来了,访问站点能看到的只有 Internal Server (500) 错误,翻开史册,书上如是说:
[Mon Jan 29 06:13:13 2007] [error] [client 210.151.136.180] FastCGI: comm with (dynamic) server "/home/islue/example.com/script/myapp_fastcgi.pl" aborted: (first read) idle timeout (60 sec)
[Mon Jan 29 06:13:13 2007] [error] [client 210.151.136.180] FastCGI: incomplete headers (0 bytes) received from server "/home/islue/example.com/script/myapp_fastcgi.pl"

在无数次 ps 之后,总算看到 myapp_fastcgi.pl 的身影一闪而过。是他杀,我惊醒!真相只有一个,下面公布凶手的自白书。
Dreamhost regularly kills off sleeping processes with a proc watch script. This will kill your dispatch.fcgi processes, leading to Error 500s from time to time. You'll need to make dispatch.fcgi ignore all TERM requests by changing how it responds to them.

说笑啦,上面这段是 DreamHost 客服给我的回复。IGNORE TERM 之后,世界又太平了。

四、应用启动方式

启动应用的方法就是访问站点。如果需要重启,杀掉所有 myapp_fastcgi.pl 即可,如果 IGNORE TERM 了的话,需要 kill -9。

Wednesday, August 30, 2006

DreamHost promo codes

正在筹划个站点,于是满地图找空间,最后决定买 Dreamhost 的虚拟主机。
最初是在 Catalyst 的 wiki 上看到它的广告的,那么想当然地以为它是支持 Catalyst 的,买了之后发现不是这样的,这是后话。
L1: Crazy Domain Insane (20GB disk, 1TB bw, $9.95/month)

咋一看,价格和内容都还不错;再一瞅,跟咱电信一样,包年免初装费,按月付费的话要额外追加一项
$49.95 set up fee

那一年就一年吧,$119.4,也还好吧。那么,最后掏钱之前 Google 一下,这 Dreamhost 到底怎么样,好不好,恕我孤陋寡闻,一搜就搜出了 promo codes 这个东西,大把大把的。使用促销代码注册,最多可以获得$97的优惠,然后$22.4就出手了。
回到上面的话题,原来 Catalyst 需要自己安装的,好就好在 Dreamhost 提供了 ssh/telnet 权限,可以在自己的目录下自行安装。当前正在摸索中……
既然 promo codes 利人又利己,那么我也来弄个玩玩
Code: NOTICPAN
PlanCostThis Code's Discount
L1 Monthly$59.90$50.00
L1 Yearly$119.40$97.00
L1 Two years$190.80$97.00
L2 Monthly$69.90$60.00
L2 Yearly$239.40$97.00
L2 Two years$382.80$97.00
L3 Monthly$89.90$80.00
L3 Yearly$479.40$97.00
L3 Two years$766.80$97.00
L4 Monthly$129.90$97.00
L4 Yearly$959.40$97.00
L4 Two years$1534.80$97.00
While L3 is at L2's price, L2's discount will be used for L3.