lib/Ubic/Admin/Setup.pm

filter: Statementstmt 61.1% 151 / 247 Branchbran 32.7% 38 / 116 Conditioncond 3.8% 1 / 26 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 80.9% 17 / 21 Podpod 100% 7 / 7 totaltotal 49.5% 214 / 432 SCAR 66.1
CC
71
Cov
49%
setup
286.3
prompt
132.7
xsystem
56.0
CRAP 745.9
« lib/Ubic/Credentials/OS/MacOSX.pm ↑ Summary blib/lib/Ubic/Service/SimpleDaemon.pm »
1 package Ubic::Admin::Setup;
2 2 $Ubic::Admin::Setup::VERSION = '1.59';
3 # ABSTRACT: this module handles ubic setup: asks user some questions and configures your system
4  
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Getopt::Long 2.33;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use File::Which;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Ubic::AtomicFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Ubic::Settings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Ubic::Settings::ConfigFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 my $batch_mode;
21 my $quiet;
22  
23 sub _defaults {
24 1 ▶ if ($^O eq 'freebsd') {
Subroutine _defaults: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'freebsd') { } 0 1 1
25 return (
26 0 config => '/usr/local/etc/ubic/ubic.cfg',
27 data_dir => '/var/db/ubic',
28 service_dir => '/usr/local/etc/ubic/service',
29 log_dir => '/var/log/ubic',
30 example => '/usr/local/etc, /var',
31 );
32 }
33 else {
34 # fhs
35 return (
36 1 config => '/etc/ubic/ubic.cfg',
37 data_dir => '/var/lib/ubic',
38 service_dir => '/etc/ubic/service',
39 log_dir => '/var/log/ubic',
40 example => '/etc, /var',
41 );
42 }
43 };
44  
45 sub print_tty {
46 28 ▶ print @_ unless $quiet or $batch_mode;
Subroutine print_tty: called CC=3 SCAR=14.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet or $batch_mode 0 28 28
Condition33%1/3
$quiet or $batch_mode
l!l&&r!l&&!r
0280
MC/DC0%0/2
$quiet or $batch_mode
$quiet $batch_mode
Truth table33%1/3
A or B
A= $quietB= $batch_mode
ABresult
1X1
011
000
47 }
48  
49 sub prompt ($;$) {
50 6 ▶ my($mess, $def) = @_;
Subroutine prompt: called CC=13 SCAR=48.9
Pod documented
51 6 ▶ Carp::confess("prompt function called without an argument")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mess 0 6 6
52 unless defined $mess;
53  
54 6 ▶ return $def if $batch_mode;
Branch: 1 branch
BranchTrueFalseTotal
if $batch_mode 6 0 6
55  
56 0 ▶ my $isa_tty = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT));
Condition0%0/9
-t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
!ll&&!rl&&r
000
-t STDOUT or not -f STDOUT || -c STDOUT
l!l&&r!l&&!r
000
-f STDOUT || -c STDOUT
l!l&&r!l&&!r
000
MC/DC0%0/4
-t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT))
-t STDIN -t STDOUT -f STDOUT -c STDOUT
Truth table0%0/5
A && B or not(C || D)
A= -t STDINB= -t STDOUTC= -f STDOUTD= -c STDOUT
ABCDresult
0XXX0
101X0
10010
11XX1
10001
57 0 ▶ Carp::confess("tty not found") if not $isa_tty;
Branch: 1 branch
BranchTrueFalseTotal
unless $isa_tty 0 0 0
58  
59 0 ▶ $def = defined $def ? $def : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $def ? : 0 0 0
60  
61 0 local $| = 1;
62 0 local $\ = undef;
63 0 print "$mess ";
64  
65 0 my $ans;
66 0 ▶ if (not $isa_tty and eof STDIN) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $isa_tty and eof STDIN) { } 0 0 0
Condition0%0/3
not $isa_tty and eof STDIN
!ll&&!rl&&r
000
MC/DC0%0/2
not $isa_tty and eof STDIN
not $isa_tty eof STDIN
Truth table0%0/3
not(A) and B
A= not $isa_ttyB= eof STDIN
ABresult
0X0
100
111
67 0 print "$def\n";
68 }
69 else {
70 0 $ans = <STDIN>;
71 0 ▶ if( defined $ans ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ans) { } 0 0 0
72 0 chomp $ans;
73 }
74 else { # user hit ctrl-D
75 0 print "\n";
76 }
77 }
78  
79 0 ▶ return (!defined $ans || $ans eq '') ? $def : $ans;
Branch: 1 branch
BranchTrueFalseTotal
!defined($ans) || $ans eq '' ? : 0 0 0
Condition0%0/3
not defined $ans or $ans eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $ans or $ans eq ""
not defined $ans $ans eq ""
Truth table0%0/3
not(A) or B
A= not defined $ansB= $ans eq ""
ABresult
1X1
011
000
80 }
81  
82 sub prompt_str {
83 3 ▶ my ($description, $default) = @_;
Subroutine prompt_str: called CC=1 SCAR=0.0
Pod documented
84 3 return prompt("$description [$default]", $default);
85 }
86  
87 sub prompt_bool {
88 3 ▶ my ($description, $default) = @_;
Subroutine prompt_bool: called CC=4 SCAR=13.9
Pod documented
89 3 ▶ my $yn = ($default ? 'y' : 'n');
Branch: 1 branch
BranchTrueFalseTotal
$default ? : 1 2 3
90 3 ▶ my $yn_hint = ($default ? 'Y/n' : 'y/N');
Branch: 1 branch
BranchTrueFalseTotal
$default ? : 1 2 3
91 3 my $result = prompt("$description [$yn_hint]", $yn);
92 3 ▶ if ($result =~ /^y/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result =~ /^y/i) 1 2 3
93 1 return 1;
94 }
95 2 return;
96 }
97  
98 sub xsystem {
99 0 ▶ local $! = local $? = 0;
Subroutine xsystem: not called CC=7 SCAR=40.3
Pod documented
100 0 ▶ return if system(@_) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if system(@_) == 0 0 0 0
101  
102 0 my @msg;
103 0 ▶ if ($!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!) 0 0 0
104 0 push @msg, "error ".int($!)." '$!'";
105 }
106 0 ▶ if ($? > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? > 0) 0 0 0
107 0 ▶ push @msg, "kill by signal ".($? & 127) if ($? & 127);
Branch: 1 branch
BranchTrueFalseTotal
if $? & 127 0 0 0
108 0 ▶ push @msg, "core dumped" if ($? & 128);
Branch: 1 branch
BranchTrueFalseTotal
if $? & 128 0 0 0
109 0 ▶ push @msg, "exit code ".($? >> 8) if $? >> 8;
Branch: 1 branch
BranchTrueFalseTotal
if $? >> 8 0 0 0
110 }
111 0 die join ", ", @msg;
112 }
113  
114 sub slurp {
115 0 ▶ my ($file) = @_;
Subroutine slurp: not called CC=2 SCAR=17.9
Pod documented
116 0 ▶ open my $fh, '<', $file or die "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open ${file}: $!" 0 0 0
117 0 my $result = join '', <$fh>;
118 0 close $fh;
119 0 return $result;
120 }
121  
122 sub setup {
123  
124 1 ▶ my $opt_reconfigure;
Subroutine setup: called CC=45 SCAR=56.6
Pod documented
125 my $opt_service_dir;
126 1 my $opt_data_dir;
127 1 my $opt_log_dir;
128 1 my $opt_default_user = 'root';
129 1 my $opt_sticky_777 = 1;
130 1 my $opt_install_services = 1;
131 1 my $opt_crontab = 1;
132 1 my $opt_local;
133  
134 # These options are documented in ubic-admin script POD.
135 # Don't forget to update their description if you change them.
136 1 ▶ GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("local!", \$opt_local, "batch-mode", \$batch_mode, "quiet", \$quiet, "reconfigure!", \$opt_reconfigure, "service-dir=s", \$opt_service_dir, "data-dir=s", \$opt_data_dir, "log-dir=s", \$opt_log_dir, "default-user=s", \$opt_default_user, "sticky-777!", \$opt_sticky_777, "install-services!", \$opt_install_services, "crontab!", \$opt_crontab) or die "Getopt failed" 0 1 1
137 'local!' => \$opt_local,
138 'batch-mode' => \$batch_mode,
139 'quiet' => \$quiet,
140 'reconfigure!' => \$opt_reconfigure,
141 'service-dir=s' => \$opt_service_dir,
142 'data-dir=s' => \$opt_data_dir,
143 'log-dir=s' => \$opt_log_dir,
144 'default-user=s' => \$opt_default_user,
145 'sticky-777!' => \$opt_sticky_777,
146 'install-services!' => \$opt_install_services,
147 'crontab!' => \$opt_crontab,
148 ) or die "Getopt failed";
149  
150 1 ▶ die "Unexpected arguments '@ARGV'" if @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV 0 1 1
151  
152 1 my %defaults = _defaults();
153  
154 1 eval { Ubic::Settings->check_settings };
155 1 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 1 1
156 0 my $go = prompt_bool("Looks like ubic is already configured, do you want to reconfigure?", $opt_reconfigure);
157 0 ▶ return unless $go;
Branch: 1 branch
BranchTrueFalseTotal
unless $go 0 0 0
158 0 print_tty "\n";
159 }
160  
161 1 print_tty "Ubic can be installed either in your home dir or into standard system paths ($defaults{example}).\n";
162 1 print_tty "You need to be root to install it into system.\n";
163  
164 1 ▶ unless ($batch_mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($batch_mode) 0 1 1
165 0 $batch_mode = prompt_bool("Would you like to configure as much as possible automatically?", 1);
166 }
167  
168 # ideally, we want is_root option and local option to be orthogonal
169 # it's not completely true by now, though
170 1 ▶ my $is_root = ( $> ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$> ? : 1 0 1
171 1 my $local = $opt_local;
172 1 ▶ unless (defined $local) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $local) 0 1 1
173 0 ▶ if ($is_root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_root) { } 0 0 0
174 0 my $ok = prompt_bool("You are root, install into system?", 1);
175 0 ▶ $local = 1 unless $ok; # root can install locally
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
176 }
177 else {
178 0 my $ok = prompt_bool("You are not root, install locally?", 1);
179 0 ▶ return unless $ok; # non-root user can't install into system
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
180 0 $local = 1;
181 }
182 }
183  
184 1 my $local_dir;
185 1 ▶ if ($local) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local) 1 0 1
186 1 $local_dir = $ENV{HOME};
187 1 ▶ unless (defined $local_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $local_dir) 0 1 1
188 0 die "Can't find your home!";
189 }
190 1 ▶ unless (-d $local_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $local_dir) 0 1 1
191 0 die "Can't find your home dir '$local_dir'!";
192 }
193 }
194  
195 1 print_tty "\nService dir is a directory with descriptions of your services.\n";
196 my $default_service_dir = (
197 defined($local_dir)
198 ? "$local_dir/ubic/service"
199 : $defaults{service_dir}
200 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $local_dir ? : 1 0 1
201 1 ▶ $default_service_dir = $opt_service_dir if defined $opt_service_dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt_service_dir 0 1 1
202 1 my $service_dir = prompt_str("Service dir?", $default_service_dir);
203  
204 1 print_tty "\nData dir is where ubic stores all of its data: locks,\n";
205 1 print_tty "status files, tmp files.\n";
206 my $default_data_dir = (
207 defined($local_dir)
208 ? "$local_dir/ubic/data"
209 : $defaults{data_dir}
210 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $local_dir ? : 1 0 1
211 1 ▶ $default_data_dir = $opt_data_dir if defined $opt_data_dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt_data_dir 0 1 1
212 1 my $data_dir = prompt_str("Data dir?", $default_data_dir);
213  
214 1 print_tty "\nLog dir is where ubic.watchdog will write its logs.\n";
215 1 print_tty "(Your own services are free to write logs wherever they want.)\n";
216 my $default_log_dir = (
217 defined($local_dir)
218 ? "$local_dir/ubic/log"
219 : $defaults{log_dir}
220 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $local_dir ? : 1 0 1
221 1 ▶ $default_log_dir = $opt_log_dir if defined $opt_log_dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt_log_dir 0 1 1
222 1 my $log_dir = prompt_str("Log dir?", $default_log_dir);
223  
224 # TODO - sanity checks?
225  
226 1 my $default_user;
227 1 ▶ if ($is_root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_root) { } 0 1 1
228 0 print_tty "\nUbic services can be started from any user.\n";
229 0 print_tty "Some services don't specify the user from which they must be started.\n";
230 0 print_tty "Default user will be used in this case.\n";
231 0 $default_user = prompt_str("Default user?", $opt_default_user);
232 }
233 else {
234 1 print_tty "\n";
235 1 $default_user = getpwuid($>);
236 1 ▶ unless (defined $default_user) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $default_user) 0 1 1
237 0 die "Can't get login (uid '$>')";
238 }
239 1 print_tty "You're using local installation, so default service user will be set to '$default_user'.\n";
240 }
241  
242 1 my $enable_1777;
243 1 ▶ if ($is_root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_root) 0 1 1
244 0 print_tty "\nSystem-wide installations usually need to store service-related data\n";
245 0 print_tty "into data dir for different users. For non-root services to work\n";
246 0 print_tty "1777 grants for some data dir subdirectories is required.\n";
247 0 print_tty "(1777 grants means that everyone is able to write to the dir,\n";
248 0 print_tty "but only file owners are able to modify and remove their files.)\n";
249 0 print_tty "There are no known security issues with this approach, but you have\n";
250 0 print_tty "to decide for yourself if that's ok for you.\n";
251  
252 0 $enable_1777 = prompt_bool("Enable 1777 grants for data dir?", $opt_sticky_777);
253 }
254  
255 1 my $install_services;
256 {
257 1 print_tty "There are three standard services in ubic service tree:\n";
258 1 print_tty " - ubic.watchdog (universal watchdog)\n";
259 1 print_tty " - ubic.ping (http service status reporter)\n";
260 1 print_tty " - ubic.update (helper process which updates service portmap, used by ubic.ping service)\n";
261 1 print_tty "If you'll choose to install them, ubic.watchdog will be started automatically\n";
262 1 print_tty "and two other services will be initially disabled.\n";
263 1 $install_services = prompt_bool("Do you want to install standard services?", $opt_install_services);
264 }
265  
266 1 my $enable_crontab;
267 {
268 1 print_tty "\n'ubic.watchdog' is a service which checks all services and restarts them if\n";
269 1 print_tty "there are any problems with their statuses.\n";
270 1 print_tty "It is very simple and robust, but since it's important that watchdog never\n";
271 1 print_tty "goes down, we recommended to install the cron job which checks watchdog itself.\n";
272 1 print_tty "Also, this cron job will bring watchdog and all other services online on host reboots.\n";
273 1 $enable_crontab = prompt_bool("Install watchdog's watchdog as a cron job?", $opt_crontab);
274 }
275  
276 1 my $crontab_env_fix = '';
277 1 my $crontab_wrap_bash;
278 1 ▶ my $ubic_watchdog_full_name = which('ubic-watchdog') or die "ubic-watchdog script not found in your current PATH";
Branch: 1 branch
BranchTrueFalseTotal
my $ubic_watchdog_full_name = which("ubic-watchdog") or die "ubic-watchdog script not found in your current PATH" 0 1 1
279 {
280 1 my @path = split /:/, $ENV{PATH};
281 1 my @perls = grep { -x $_ } map { "$_/perl" } @path;
282 1 ▶ if ($perls[0] =~ /perlbrew/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($perls[0] =~ /perlbrew/) { } 0 1 1
elsif (@perls > 1) { } 1 0 1
283 0 print_tty "\nYou're using perlbrew.\n";
284  
285 0 ▶ my $HOME = $ENV{ORIGINAL_HOME} || $ENV{HOME}; # ORIGINAL_HOME is set in ubic tests
Condition0%0/3
$ENV{'ORIGINAL_HOME'} || $ENV{'HOME'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'ORIGINAL_HOME'} || $ENV{'HOME'}
$ENV{'ORIGINAL_HOME'} $ENV{'HOME'}
Truth table0%0/3
A || B
A= $ENV{'ORIGINAL_HOME'}B= $ENV{'HOME'}
ABresult
1X1
011
000
286 0 ▶ unless ($HOME) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($HOME) 0 0 0
287 0 die "HOME env variable not defined";
288 }
289 0 ▶ my $perlbrew_config = File::Spec->catfile($ENV{PERLBREW_ROOT} || "$HOME/perl5/perlbrew", "etc/bashrc");
Condition0%0/2
$ENV{'PERLBREW_ROOT'} || "$HOME/perl5/perlbrew"
l!l
00
MC/DC0%0/1
$ENV{'PERLBREW_ROOT'} || "$HOME/perl5/perlbrew"
$ENV{'PERLBREW_ROOT'}
Truth table0%0/2
A
A= $ENV{'PERLBREW_ROOT'}
Aresult
11
00
290 0 ▶ if (not -e $perlbrew_config) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $perlbrew_config) 0 0 0
291 0 die "Can't find perlbrew config (assumed $perlbrew_config)";
292 }
293 0 print_tty "I'll source your perlbrew config in ubic crontab entry to start the watchdog in the correct environment.\n";
294 0 $crontab_env_fix .= "source $perlbrew_config && ";
295 0 $crontab_wrap_bash = 1;
296 }
297 elsif (@perls > 1) {
298 1 print_tty "\nYou're using custom perl and it's not from perlbrew.\n";
299 1 print_tty "I'll add your current PATH to ubic crontab entry.\n";
300  
301 # TODO - what if PATH contains " quotes? hopefully nobody is that crazy...
302 1 $crontab_env_fix .= qq[PATH="$ENV{PATH}" ];
303 }
304  
305 1 ▶ if ($ENV{PERL5LIB}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PERL5LIB"}) 1 0 1
306 1 print_tty "\nYou're using custom PERL5LIB.\n";
307 1 print_tty "I'll add your current PERL5LIB to ubic crontab entry.\n";
308 1 print_tty "Feel free to edit your crontab manually after installation if necessary.\n";
309 1 $crontab_env_fix .= qq[PERL5LIB="$ENV{PERL5LIB}" ];
310 }
311 }
312  
313 my $config_file = (
314 defined($local_dir)
315 ? "$local_dir/.ubic.cfg"
316 : $defaults{config}
317 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $local_dir ? : 1 0 1
318  
319 {
320 1 print_tty "\nThat's all I need to know.\n";
321 1 print_tty "If you proceed, all necessary directories will be created,\n";
322 1 print_tty "and configuration file will be stored into $config_file.\n";
323 1 my $run = prompt_bool("Complete setup?", 1);
324 1 ▶ return unless $run;
Branch: 1 branch
BranchTrueFalseTotal
unless $run 0 1 1
325 }
326  
327 1 print "Installing dirs...\n";
328  
329 1 mkpath($_) for ($service_dir, $data_dir, $log_dir);
330  
331 1 for my $subdir (qw[
332 status simple-daemon/pid lock ubic-daemon tmp watchdog/lock watchdog/status
333 ]) {
334 7 mkpath("$data_dir/$subdir");
335 7 ▶ chmod(01777, "$data_dir/$subdir") or die "chmod failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
chmod 01777, "$data_dir/$subdir" or die "chmod failed: $!" 0 7 7
336 }
337  
338 1 mkpath("$service_dir/ubic");
339  
340 1 ▶ if ($install_services) {
Branch: 1 branch
BranchTrueFalseTotal
if ($install_services) 0 1 1
341 my $add_service = sub {
342 0 ▶ my ($name, $content) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
343 0 print "Installing ubic.$name service...\n";
344  
345 0 my $file = "$service_dir/ubic/$name";
346 0 Ubic::AtomicFile::store($content => $file);
347 0 };
348  
349 0 $add_service->(
350 'ping',
351 "use Ubic::Ping::Service;\n"
352 ."Ubic::Ping::Service->new;\n"
353 );
354  
355 0 $add_service->(
356 'watchdog',
357 "use Ubic::Service::SimpleDaemon;\n"
358 ."Ubic::Service::SimpleDaemon->new(\n"
359 ."bin => [ 'ubic-periodic', '--rotate-logs', '--period=60', '--stdout=$log_dir/watchdog.log', '--stderr=$log_dir/watchdog.err.log', 'ubic-watchdog' ],\n"
360 .");\n"
361 );
362  
363 0 $add_service->(
364 'update',
365 "use Ubic::Service::SimpleDaemon;\n"
366 ."Ubic::Service::SimpleDaemon->new(\n"
367 ."bin => [ 'ubic-periodic', '--rotate-logs', '--period=60', '--stdout=$log_dir/update.log', '--stderr=$log_dir/update.err.log', 'ubic-update' ],\n"
368 .");\n"
369 );
370 }
371  
372 1 ▶ if ($enable_crontab) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable_crontab) 0 1 1
373 0 print "Installing cron jobs...\n";
374  
375 0 system("crontab -l >$data_dir/tmp/crontab.stdout 2>$data_dir/tmp/crontab.stderr");
376 0 my $old_crontab = slurp("$data_dir/tmp/crontab.stdout");
377 0 my $stderr = slurp("$data_dir/tmp/crontab.stderr");
378 0 unlink "$data_dir/tmp/crontab.stdout";
379 0 unlink "$data_dir/tmp/crontab.stderr";
380 0 ▶ if ($stderr and $stderr !~ /no crontab/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stderr and not $stderr =~ /no crontab/) 0 0 0
Condition0%0/3
$stderr and not $stderr =~ /no crontab/
!ll&&!rl&&r
000
MC/DC0%0/2
$stderr and not $stderr =~ /no crontab/
$stderr not $stderr =~ /no crontab/
Truth table0%0/3
A and not(B)
A= $stderrB= not $stderr =~ /no crontab/
ABresult
0X0
100
111
381 0 die "crontab -l failed";
382 }
383  
384 0 my @crontab_lines = split /\n/, $old_crontab;
385 0 @crontab_lines = grep { $_ !~ /\Qubic-watchdog ubic.watchdog\E/ } @crontab_lines;
386  
387 0 ▶ open my $fh, '|-', 'crontab -' or die "Can't run 'crontab -': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "|-", "crontab -" or die "Can't run 'crontab -': $!" 0 0 0
388 my $printc = sub {
389 0 ▶ print {$fh} @_ or die "Can't write to pipe: $!";
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} @_ or die "Can't write to pipe: $!" 0 0 0
390 0 };
391  
392 0 my $crontab_command = "$crontab_env_fix$ubic_watchdog_full_name ubic.watchdog";
393 0 ▶ if ($crontab_wrap_bash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crontab_wrap_bash) 0 0 0
394 0 $crontab_command = "bash -c '$crontab_command'";
395 }
396 0 push @crontab_lines, "* * * * * $crontab_command >>$log_dir/watchdog.log 2>>$log_dir/watchdog.err.log";
397 0 $printc->("$_\n") for @crontab_lines;
398 0 ▶ close $fh or die "Can't close pipe: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Can't close pipe: $!" 0 0 0
399 }
400  
401 1 print "Installing $config_file...\n";
402 1 Ubic::Settings::ConfigFile->write($config_file, {
403 service_dir => $service_dir,
404 data_dir => $data_dir,
405 default_user => $default_user,
406 });
407  
408 1 ▶ if ($install_services) {
Branch: 1 branch
BranchTrueFalseTotal
if ($install_services) 0 1 1
409 0 print "Starting ubic.watchdog...\n";
410 0 xsystem('ubic start ubic.watchdog');
411 }
412  
413 1 print "Installation complete.\n";
414 }
415  
416  
417 2 1;
418  
419 __END__
« lib/Ubic/Credentials/OS/MacOSX.pm ↑ Summary blib/lib/Ubic/Service/SimpleDaemon.pm »