LoginSignup
2
2

More than 5 years have passed since last update.

nginxの挙動を確認するためのプログラムを書く

Last updated at Posted at 2013-01-25
t/Util.pm
package t:Util
use strict;
use warnings;
use Test::More;
use Test::TCP;
use Proc::Guard qw(proc_guard);
use LWP::UserAgent;

sub nginx_start {
    my ($class, $conf_name) = @_;
    $conf_name ||= "basic.nginx.conf";


    my $pwd = `pwd`;
    chomp $pwd;
    my $nginx_bin = $ENV{'NGINX_BIN'}
        or die "please specify ENV NGINX_BIN";

    my $proc = proc_guard($nginx_bin, 
        '-g', 'daemon off;', 
        '-p', $pwd . '/t/ngx_base/',
        '-c', $pwd . "/t/ngx_base/etc/$conf_name"
    );
    Test::TCP::wait_port(8000);
    return $proc;
}

nginxを起動するときに、-g "daemon off;"するのと、-pと-cを指定するのがポイント。

port番号をランダムにするのはけっこう難しくて、さらに頑張るなら、Test::TCP::empty_port()で空いているポート番号を調べたのちに、設定ファイルを一時ファイルに置換し、それをもとに起動してやればよいが、ふつうにnginxを起動させられる設定ファイルにならないのがいけてない。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2