line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package ubic_daemon; |
3
|
|
|
|
|
|
|
$ubic_daemon::VERSION = '1.60'; |
4
|
|
|
|
|
|
|
# ABSTRACT: daemonize any binary |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
619
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use Getopt::Long 2.33; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
20
|
|
11
|
1
|
|
|
1
|
|
87
|
use Pod::Usage; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use Ubic::Daemon qw(:all); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
4
|
use Ubic::Settings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
234
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
return 1 if caller(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $name; |
19
|
|
|
|
|
|
|
my $pid_dir = Ubic::Settings->data_dir.'/ubic-daemon'; |
20
|
|
|
|
|
|
|
my ($stop, $list); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
GetOptions( |
23
|
|
|
|
|
|
|
'name=s' => \$name, |
24
|
|
|
|
|
|
|
'pid-dir=s' => \$pid_dir, |
25
|
|
|
|
|
|
|
'stop' => \$stop, |
26
|
|
|
|
|
|
|
'list' => \$list, |
27
|
|
|
|
|
|
|
) or pod2usage(2); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if ($stop) { |
30
|
|
|
|
|
|
|
pod2usage(2) unless @ARGV == 0; |
31
|
|
|
|
|
|
|
unless (-e "$pid_dir/$name") { |
32
|
|
|
|
|
|
|
die "$name not found"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
# TODO - check owner |
35
|
|
|
|
|
|
|
stop_daemon("$pid_dir/$name"); |
36
|
|
|
|
|
|
|
system("rm -rf $pid_dir/$name"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($list) { |
39
|
|
|
|
|
|
|
pod2usage(2) unless @ARGV == 0; |
40
|
|
|
|
|
|
|
for my $file (glob "$pid_dir/*") { |
41
|
|
|
|
|
|
|
my $name = File::Spec->abs2rel($file, $pid_dir); |
42
|
|
|
|
|
|
|
print "$name\t"; |
43
|
|
|
|
|
|
|
if (check_daemon($file)) { |
44
|
|
|
|
|
|
|
print "running\n"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
|
|
|
|
|
|
print "dead\n"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
pod2usage(2) unless @ARGV == 1; |
53
|
|
|
|
|
|
|
pod2usage(2) unless defined $name; |
54
|
|
|
|
|
|
|
start_daemon({ |
55
|
|
|
|
|
|
|
name => $name, |
56
|
|
|
|
|
|
|
pidfile => "$pid_dir/$name", |
57
|
|
|
|
|
|
|
bin => shift(@ARGV), |
58
|
|
|
|
|
|
|
}); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |