app.pl 874 B

1234567891011121314151617181920212223242526272829
  1. use strict;
  2. use Unix::Processors;
  3. use Getopt::Std 'getopts'; getopts('a', my $opts = +{});
  4. use Cwd 'getcwd';
  5. my $cpus = Unix::Processors->new->max_online;
  6. my @cmd = (
  7. ($opts->{a} # async server
  8. ? [qw'plackup -s Twiggy::Prefork -E production --max-reqs-per-child=0 --backlog 16384
  9. --max-workers', $cpus, qw'-l /dev/shm/app.sock -a app-async.psgi']
  10. : [qw'start_server --backlog 16384 --path /dev/shm/app.sock --
  11. plackup -s Gazelle -E production --max-reqs-per-child 10000000
  12. --max-workers', $cpus, qw'-a app.psgi']),
  13. [qw'nginx -c nginx.conf -p', getcwd]
  14. );
  15. my @child;
  16. for (@cmd) {
  17. if ((my $pid = fork) > 0) { push @child, $pid }
  18. elsif (defined $pid) { exec @$_ }
  19. else { die 'fork failed' }
  20. }
  21. # wait childs
  22. $SIG{INT} = $SIG{TERM} = sub { kill TERM => @child; 1 while wait != -1 };
  23. 1 while wait != -1;
  24. exit 0;