new perls v5.39.10
[andk-cpan-tools.git] / bin / analysis-webserver-ipcclcron.pl
blob5d0d1c6704ba25ca6cbebd7d176e99a43b1b32e8
1 #!/usr/bin/perl
3 # use 5.010;
4 use strict;
5 use warnings;
7 =head1 NAME
11 =head1 SYNOPSIS
15 =head1 OPTIONS
17 =over 8
19 =cut
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
23 =item B<--dry-run|n!>
25 Tells us what it would do and exits.
27 =item B<--help|h!>
29 This help
31 =back
33 =head1 DESCRIPTION
35 Starts catalyst. Concurrency is managed by IPC::ConcurrencyLimit.
37 =cut
40 use FindBin;
41 use lib "$FindBin::Bin/../CPAN-Blame/lib";
42 BEGIN {
43 push @INC, qw( );
45 use CPAN::Blame::Config::Cnntp;
47 use Dumpvalue;
48 use File::Basename qw(dirname);
49 use File::Path qw(mkpath);
50 use File::Spec;
51 use File::Temp;
52 use Getopt::Long;
53 use Pod::Usage;
54 use Hash::Util qw(lock_keys);
55 use Time::Moment;
57 our %Opt;
58 lock_keys %Opt, map { /([^=|!]+)/ } @opt;
59 GetOptions(\%Opt,
60 @opt,
61 ) or pod2usage(1);
62 if ($Opt{help}) {
63 pod2usage(0);
66 my($workdir);
67 BEGIN {
68 $workdir = File::Spec->catdir
69 ($CPAN::Blame::Config::Cnntp::Config->{solver_vardir},
70 "workdir");
72 use IPC::ConcurrencyLimit;
74 my($basename) = File::Basename::basename(__FILE__);
75 my $limit = IPC::ConcurrencyLimit->new
77 max_procs => 1,
78 path => "$workdir/IPC-ConcurrencyLimit-$basename",
80 my $limitid = $limit->get_lock;
81 if (not $limitid) {
82 warn "Another process appears to be still running. Exiting.";
83 exit(0);
86 my $logfile = __FILE__ . ".log";
87 sub appendlog {
88 my($what) = @_;
89 $what =~ s/\s*\z//;
90 my $tm = Time::Moment->now_utc;
91 open my $fh, ">>", $logfile or die "Could not open '$logfile': $!";
92 print $fh "$tm $what\n";
93 close $fh or die "Could not close '$logfile': $!";
96 appendlog("Starting as $$");
97 my $wd = "$FindBin::Bin/..";
98 chdir $wd or die "Could not chdir to $wd: $!";
99 0==system qq{"$^X" "$FindBin::Bin/../CPAN-Blame/script/cpan_blame_server.pl" "--port" "3002" >> $logfile 2>&1} or die "problem running webserver, giving up";
100 appendlog("Finished as $$");
102 # Local Variables:
103 # mode: cperl
104 # cperl-indent-level: 4
105 # End: