reap_playwright_servers 727 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/perl
  2. package Playwright::ServerReaper;
  3. use strict;
  4. use warnings;
  5. use Proc::ProcessTable;
  6. use Playwright::Util;
  7. use LWP::UserAgent;
  8. exit main() unless caller;
  9. sub main {
  10. my $t = Proc::ProcessTable->new;
  11. my @matches = grep { $_->cmndline =~ m/playwright_server --port/ } @{$t->table};
  12. my $ua = LWP::UserAgent->new();
  13. foreach my $process (@matches) {
  14. print "$process->cmndline\n";
  15. my ($port) = $process->cmndline =~ m/playwright_server --port (\d+)/;
  16. next unless $port;
  17. print "Instructing playwright_server process ".$process->pid()." listening on $port to shut down...\n";
  18. Playwright::Util::request( 'GET', 'shutdown', $port, $ua );
  19. }
  20. return 0;
  21. }
  22. 1;