生成命令,/home/howl/.rvm/bin/bootup_puma
:
rvm wrapper ruby-1.9.3-p125-perf bootup puma
创建 Puma 的配置文件,/etc/puma/puma.rb
:
bind 'unix:///tmp/puma.sock'
pidfile '/tmp/puma.pid'
rackup '/home/howl/one/config.ru'
创建服务,/etc/init.d/puma
:
#!/bin/sh
### BEGIN INIT INFO
# Provides: puma
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: puma initscript
# Description: puma
### END INIT INFO
# Original author: Forrest Robertson
# Do NOT "set -e"
DAEMON=/home/howl/.rvm/bin/bootup_puma # /home/howl/.rvm/gems/ruby-1.9.3-p125-perf/bin/puma
SCRIPT_NAME=/etc/init.d/puma
CONFIG_FILE=/etc/puma/puma.rb
APP_PATH=/home/howl/one
PID=/tmp/puma.pid
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
case "$1" in
start)
cd $APP_PATH && $DAEMON -C $CONFIG_FILE > $APP_PATH/log/puma.log 2>&1 &
;;
stop)
kill -9 `cat $PID`
;;
restart)
kill -SIGUSR2 `cat $PID`
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
exit 3
;;
esac
修改 nginx.conf:
upstream howl_cluster {
# server unix:/tmp/thin.howl.sock;
server unix://tmp/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name imgcdn.shareday.com;
root /home/howl/taobao;
}
server {
listen 80;
server_name shareday.com www.shareday.com shfeiming.com;
root /home/howl/www/public;
access_log /home/howl/nginx/access.log;
error_log /home/howl/nginx/error.log;
location / {
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://howl_cluster;
break;
}
}
}
和 thin 不同,在 puma 的重启前,必须先停掉 nginx,否则 puma.sock 被占用。
Address already in use - /tmp/puma.sock (Errno::EADDRINUSE)
原因在于,进程被杀掉后,puma.sock 依旧存在?!