bin/ubic-daemon

filter: Statementstmt 55.0% 22 / 40 Branchbran 65.0% 13 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 62.1% 41 / 66 SCAR 0.7
CC
1
Cov
58%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Ubic/SingletonLock.pm ↑ Summary bin/ubic »
1 #!/usr/bin/env perl
2 package ubic_daemon;
3 1 $ubic_daemon::VERSION = '1.59';
4 # ABSTRACT: daemonize any binary
5  
6 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 9 ▶use Getopt::Long 2.33;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use Ubic::Daemon qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Ubic::Settings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶return 1 if caller();
Branch: 1 branch
BranchTrueFalseTotal
if caller() 1 4 5
17  
18 2 my $name;
19 2 my $pid_dir = Ubic::Settings->data_dir.'/ubic-daemon';
20 0 my ($stop, $list);
21  
22 0 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("name=s", \$name, "pid-dir=s", \$pid_dir, "stop", \$stop, "list", \$list) or pod2usage(2) 0 4 4
23 'name=s' => \$name,
24 'pid-dir=s' => \$pid_dir,
25 'stop' => \$stop,
26 'list' => \$list,
27 ) or pod2usage(2);
28  
29 0 ▶if ($stop) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stop) { } 1 3 4
elsif ($list) { } 1 2 3
30 0 ▶ pod2usage(2) unless @ARGV == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV == 0 0 1 1
31 0 ▶ unless (-e "$pid_dir/$name") {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "$pid_dir/$name") 0 1 1
32 0 die "$name not found";
33 }
34 # TODO - check owner
35 0 stop_daemon("$pid_dir/$name");
36 0 system("rm -rf $pid_dir/$name");
37 }
38 elsif ($list) {
39 0 ▶ pod2usage(2) unless @ARGV == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV == 0 0 1 1
40 0 for my $file (glob "$pid_dir/*") {
41 0 my $name = File::Spec->abs2rel($file, $pid_dir);
42 0 print "$name\t";
43 0 ▶ if (check_daemon($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (check_daemon($file)) { } 1 0 1
44 0 print "running\n";
45 }
46 else {
47 0 print "dead\n";
48 }
49 }
50 }
51 else {
52 0 ▶ pod2usage(2) unless @ARGV == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV == 1 0 2 2
53 0 ▶ pod2usage(2) unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 2 2
54 0 start_daemon({
55 name => $name,
56 pidfile => "$pid_dir/$name",
57 bin => shift(@ARGV),
58 });
59 }
60  
61 __END__
« lib/Ubic/SingletonLock.pm ↑ Summary bin/ubic »