55use Doit; # install from CPAN or do "git clone https://github.com/eserte/doit.git ~/src/Doit"
66use Doit::Log;
77use File::Basename qw( dirname) ;
8+ use Hash::Util ' lock_keys' ;
89
910my $dest_system = " analysis2022" ; # requires an entry in /etc/hosts with the real IP address
1011
12+ my %variant_info = (
13+ fast2 => {
14+ repo_localdir_base => ' CPAN-Testers-Matrix' , # XXX should be CPAN-Testers-Matrix.fast2
15+ repo_branch => ' master' ,
16+ conf_file_base => ' cpantestersmatrix.yml' ,
17+ conf_file_content => <<"EOF" ,
18+ # PLEASE DO NOT EDIT (source is @{[ __FILE__ ]} line @{[ __LINE__ ]})
19+ cpan_home: $ENV {HOME}/.cpan
20+ plain_packages_file: /tmp/plain_packages_file
21+ static_dist_dir: /var/tmp/metabase-log/log-as-ndjson
22+ cache_root: /tmp/cpantesters_fast_cache
23+ serializer: Sereal
24+ filefmt_dist: ndjson
25+ ndjson_append_url: http://127.0.0.1:6081/matrixndjson
26+ #ndjson_append_url: http://127.0.0.1:3002/matrixndjson
27+ EOF
28+ unit_name => ' cpan-testers-matrix' , # used also for description and pidfile name # in this caseshould be cpan-testers-matrix.fast2
29+ port => 5002,
30+ },
31+ );
32+
1133sub unpriv_setup {
12- my $unpriv_doit = shift ;
34+ my ($unpriv_doit , $variant ) = @_ ;
35+
36+ my $variant_info = $variant_info {$variant } // error " No support for variant $variant " ;
37+ lock_keys %$variant_info ;
1338
1439 Doit::Log::set_label(" \@ $dest_system (unpriv)" );
1540
16- my $repo_localdir = " $ENV {HOME}/src/CPAN/CPAN-Testers-Matrix " ;
17- my $repo_branch = ' master ' ;
41+ my $repo_localdir = " $ENV {HOME}/src/CPAN/" . $variant_info -> { repo_localdir_base } ;
42+ my $repo_branch = $variant_info -> { repo_branch } ;
1843
1944 $unpriv_doit -> make_path(dirname($repo_localdir ));
2045
@@ -33,19 +58,10 @@ sub unpriv_setup {
3358 # XXX Verzeichnisse überprüfen, evtl. cache_root verlegen? (wobei: dieses Verzeichnis könnte von Zeit zu Zeit aufgeräumt werden, und solange es unterhalb von /tmp liegt, passiert das zumindest bei einem Reboot)
3459 # # Usually no restart needed, as it is still running as a CGI script.
3560 # #$unit_restart++ if
36- $unpriv_doit -> write_binary(" $repo_localdir /cgi-bin/cpantestersmatrix.yml" , <<"EOF" );
37- # PLEASE DO NOT EDIT (source is @{[ __FILE__ ]} line @{[ __LINE__ ]})
38- cpan_home: $ENV {HOME}/.cpan
39- plain_packages_file: /tmp/plain_packages_file
40- static_dist_dir: /var/tmp/metabase-log/log-as-ndjson
41- cache_root: /tmp/cpantesters_fast_cache
42- serializer: Sereal
43- filefmt_dist: ndjson
44- ndjson_append_url: http://127.0.0.1:6081/matrixndjson
45- #ndjson_append_url: http://127.0.0.1:3002/matrixndjson
46- EOF
47-
48- $unpriv_doit -> make_path(' /var/tmp/metabase-log/log-as-ndjson' );
61+ $unpriv_doit -> write_binary(" $repo_localdir /cgi-bin/" . $variant_info -> {conf_file_base }, $variant_info -> {conf_file_content });
62+ if ($variant eq ' fast2' ) { # XXX maybe this needs also be done via config; what about other variants?
63+ $unpriv_doit -> make_path(' /var/tmp/metabase-log/log-as-ndjson' );
64+ }
4965
5066 return {
5167 repo_localdir => $repo_localdir ,
@@ -54,7 +70,10 @@ sub unpriv_setup {
5470}
5571
5672sub priv_setup {
57- my ($priv_doit , $info ) = @_ ;
73+ my ($priv_doit , $variant , $info ) = @_ ;
74+
75+ my $variant_info = $variant_info {$variant } // error " No support for variant $variant " ;
76+ lock_keys %$variant_info ;
5877
5978 Doit::Log::set_label(" \@ $dest_system (priv)" );
6079
@@ -91,11 +110,11 @@ sub priv_setup {
91110
92111 my $unit_contents = <<"EOF" ;
93112[Unit]
94- Description=cpan-testers-matrix
113+ Description=$variant_info ->{unit_name}
95114After=syslog.target
96115
97116[Service]
98- ExecStart=/usr/bin/starman -l :5002 --pid /var/run/starman_cpan-testers-matrix .pid $repo_localdir /cpan-testers-matrix.psgi
117+ ExecStart=/usr/bin/starman -l :$variant_info ->{port} --pid /var/run/starman_ $variant_info ->{unit_name} .pid $repo_localdir /cpan-testers-matrix.psgi
99118Environment="BOTCHECKER_JS_ENABLED=1"
100119Restart=always
101120
@@ -104,12 +123,12 @@ sub priv_setup {
104123EOF
105124
106125 $unit_restart ++
107- if $priv_doit -> write_binary(" /etc/systemd/system/starman_cpan-testers-matrix .service" , $unit_contents );
126+ if $priv_doit -> write_binary(" /etc/systemd/system/starman_ $variant_info ->{unit_name} .service" , $unit_contents );
108127
109128 if ($unit_restart ) {
110129 $priv_doit -> system (qw( systemctl daemon-reload) );
111- $priv_doit -> system (qw( systemctl enable starman_cpan-testers-matrix .service) );
112- $priv_doit -> system (qw( systemctl restart starman_cpan-testers-matrix .service) );
130+ $priv_doit -> system (qw( systemctl enable) , " starman_ $variant_info ->{unit_name} .service" );
131+ $priv_doit -> system (qw( systemctl restart) , " starman_ $variant_info ->{unit_name} .service" );
113132 }
114133}
115134
@@ -124,25 +143,33 @@ sub check_dest_system_hostname {
124143
125144return 1 if caller ;
126145
146+ require Getopt::Long;
147+
127148$ENV {LC_ALL } = ' C.UTF-8' ; # conservative choice, avoid locale warnings
128149
129150my $doit = Doit-> init;
130151$doit -> add_component(' git' );
131152$doit -> add_component(' deb' );
132153
154+ my $variant = ' fast2' ;
155+ Getopt::Long::GetOptions(" variant" => \$variant )
156+ or error " usage: $0 [--dry-run] [--variant std|fast|fast2]\n " ;
157+ my $variant_info = $variant_info {$variant }
158+ or error " unsupported variant, use: " . join (" , " , sort keys %variant_info );
159+
133160check_dest_system_hostname();
134161
135162my $unpriv_doit = $doit -> do_ssh_connect($dest_system );
136- my $info = $unpriv_doit -> call_with_runner(' unpriv_setup' );
163+ my $info = $unpriv_doit -> call_with_runner(' unpriv_setup' , $variant );
137164
138165my $priv_doit = $doit -> do_ssh_connect($dest_system , as => ' root' );
139- $priv_doit -> call_with_runner(' priv_setup' , $info );
166+ $priv_doit -> call_with_runner(' priv_setup' , $variant , $ info );
140167
141168# simple ping test
142169require LWP::UserAgent;
143170my $ua = LWP::UserAgent-> new;
144171$ua -> timeout(10);
145- my $url = " http://$dest_system :5002 " ;
172+ my $url = " http://$dest_system :$variant_info ->{port} " ;
146173my $resp = $ua -> get($url );
147174$resp -> is_success or error " Fetching $url failed: " . $resp -> dump ;
148175$resp -> decoded_content =~ / (CPAN Testers Matrix|JavaScript Required)/ or error " Unexpected content on $url : " . $resp -> decoded_content;
0 commit comments