2015/08/03

php-fpmをServer::Starterを使ってHot deploy

したかったけど、ダメだった。

Server::Starterはサーバプログラムをよしなにホットデプロイしてくれるスーパーデーモンです。

FPM_SOCKETSを使ってsocketは引き継げるが、php-fpmがそもそもgraceful shutdownに対応してないため、Server::StarterがSIGHUPを受けてphp-fpmを切り替える際に処理途中のリクエストが切断される。

なんとかしたい……。

FPM_SOCKETSについて

php-fpmは環境変数のFPM_SOCKETSからsocket情報を引き継ぐ機能がある。

start_serverはsocket情報をSERVER_STARTER_PORTに入れてサーバプログラムに渡すので、FPM_SOCKETSにセットしてphp-fpmを起動するとよい。

ざっくり書くとこういう形

start.sh

#!/bin/bash
start_server --path=`pwd`/php-fpm.sock \
    --interval=15 \
    --signal-on-hup=QUIT -- \
    sh -c 'FPM_SOCKETS=$SERVER_STARTER_PORT php-fpm -y php-fpm.conf'

その他テスト用ファイル

php-fpm.conf

[global]
pid = /Users/yosasaki/devel/php/php-fpm-graceful/php-fpm.pid
error_log = /Users/yosasaki/devel/php/php-fpm-graceful/php-fpm-error_log
daemonize = no

[www]
listen = /Users/yosasaki/devel/php/php-fpm-graceful/php-fpm.sock
listen.backlog = 256
listen.allowed_clients = 127.0.0.1
listen.mode = 0660
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /Users/yosasaki/devel/php/php-fpm-graceful/www-slow_log
php_admin_value[error_log] = /Users/yosasaki/devel/php/php-fpm-graceful/www-error_log
php_admin_flag[log_errors] = on

index.php

<?php
sleep(10);
echo "OK";

nginx.conf

worker_processes  1;
daemon off;

events {
  worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;

  server {
    listen       8080;
    server_name  localhost;
    root /Users/yosasaki/devel/php/php-fpm-graceful;

    location / {
      fastcgi_pass   unix:/Users/yosasaki/devel/php/php-fpm-graceful/php-fpm.sock;
      fastcgi_index  index.php;
      include fastcgi.conf;
    }
  }
}

1 件のコメント:

  1. Cafe Casino is a superb place search out|to search out} somewhat range in online gambling sites. One thing we appreciated was that the complete casino games library at Las Atlantis could be played on the go on their optimized web site, which we found stood a lot as} any other mobile website we’ve tried. The welcome bonus at Slots.lv begins at a 200% match for fiat and 300% for Bitcoin customers. If you’re someone that likes transferring smaller chunks of 토토사이트 cash though, we found their minimum $150 deposit again to bank cards, bank accounts, and Bitcoin to be a bit extreme. But not many will have experienced this age-old traditional in a reimagined digital setting.

    返信削除