| 1 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | package Ubic::Service::ServerStarter; | ||||||||||||
| 4 | { | ||||||||||||
| 5 | 1 | $Ubic::Service::ServerStarter::VERSION = '0.002'; | |||||||||||
| 6 | } | ||||||||||||
| 7 | 1 | ▶ | use base qw(Ubic::Service::Skeleton); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use Params::Validate qw(:all); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use Ubic::Daemon qw(:all); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | # ABSTRACT: Run programs using Server::Starter | ||||||||||||
| 14 | |||||||||||||
| 15 | 1 | ▶ | my $server_command = $ENV{'UBIC_SERVICE_SERVERSTARTER_BIN'} || 'start_server'; | ||||||||||
|
Condition50%1/2
$ENV{'UBIC_SERVICE_SERVERSTARTER_BIN'} || 'start_server'
MC/DC0%0/1
$ENV{'UBIC_SERVICE_SERVERSTARTER_BIN'} || 'start_server'
$ENV{'UBIC_SERVICE_SERVERSTARTER_BIN'}
Truth table50%1/2
A
A= $ENV{'UBIC_SERVICE_SERVERSTARTER_BIN'}
| |||||||||||||
| 16 | |||||||||||||
| 17 | sub new { | ||||||||||||
| 18 | 0 | ▶ | my ($class) = (shift); | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 19 | |||||||||||||
| 20 | 0 | my $params = validate(@_, { | |||||||||||
| 21 | cmd => { type => ARRAYREF }, | ||||||||||||
| 22 | args => { type => HASHREF, optional => 1 }, | ||||||||||||
| 23 | user => { type => SCALAR, optional => 1 }, | ||||||||||||
| 24 | group => { type => SCALAR | ARRAYREF, optional => 1 }, | ||||||||||||
| 25 | status => { type => CODEREF, optional => 1 }, | ||||||||||||
| 26 | ubic_log => { type => SCALAR, optional => 1 }, | ||||||||||||
| 27 | env => { type => HASHREF, optional => 1 }, | ||||||||||||
| 28 | stdout => { type => SCALAR, optional => 1 }, | ||||||||||||
| 29 | stderr => { type => SCALAR, optional => 1 }, | ||||||||||||
| 30 | pidfile => { type => SCALAR, optional => 1 }, | ||||||||||||
| 31 | cwd => { type => SCALAR, optional => 1 }, | ||||||||||||
| 32 | }); | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | return bless $params => $class; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | sub pidfile { | ||||||||||||
| 38 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
pidfile: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 39 | 0 | ▶ | return $self->{pidfile} if defined $self->{pidfile}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 0 | return "/tmp/".$self->full_name.".pid"; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | sub sspidfile { | ||||||||||||
| 44 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
sspidfile: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 45 | 0 | ▶ | return $self->{args}{'pid-file'} || $self->pidfile . '.ss'; | ||||||||||
|
Condition0%0/2
$self->{'args'}{'pid-file'} || $self->pidfile . '.ss'
MC/DC0%0/1
$self->{'args'}{'pid-file'} || $self->pidfile . '.ss'
$self->{'args'}{'pid-file'}
Truth table0%0/2
A
A= $self->{'args'}{'pid-file'}
| |||||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | sub statusfile { | ||||||||||||
| 49 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
statusfile: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 50 | 0 | ▶ | return $self->{args}{'status-file'} || $self->pidfile . '.status.ss'; | ||||||||||
|
Condition0%0/2
$self->{'args'}{'status-file'} || $self->pidfile . '.status.ss'
MC/DC0%0/1
$self->{'args'}{'status-file'} || $self->pidfile . '.status.ss'
$self->{'args'}{'status-file'}
Truth table0%0/2
A
A= $self->{'args'}{'status-file'}
| |||||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | sub bin { | ||||||||||||
| 54 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
bin: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||
| 55 | |||||||||||||
| 56 | 0 | my @cmd = split(/\s+/, $server_command); | |||||||||||
| 57 | |||||||||||||
| 58 | 0 | my %args = %{ $self->{args} }; | |||||||||||
| 59 | 0 | ▶ | $args{'pid-file'} = $self->sspidfile unless $args{'pid-file'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 0 | ▶ | $args{'status-file'} = $self->statusfile unless $args{'status-file'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | |||||||||||||
| 62 | 0 | for my $key (keys %args) { | |||||||||||
| 63 | 0 | ▶ | my $cmd_key = (length $key == 1) ? '-' : '--'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | 0 | $cmd_key .= $key; | |||||||||||
| 65 | 0 | my $v = $args{$key}; | |||||||||||
| 66 | 0 | ▶ | next unless defined $v; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 0 | push @cmd, $cmd_key, $v; | |||||||||||
| 68 | } | ||||||||||||
| 69 | 0 | push @cmd, '--', @{ $self->{cmd} }; | |||||||||||
| 70 | |||||||||||||
| 71 | 0 | return \@cmd; | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | sub start_impl { | ||||||||||||
| 75 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
start_impl: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 76 | |||||||||||||
| 77 | 0 | my $daemon_opts = { | |||||||||||
| 78 | bin => $self->bin, | ||||||||||||
| 79 | pidfile => $self->pidfile, | ||||||||||||
| 80 | term_timeout => 5, # TODO - configurable? | ||||||||||||
| 81 | }; | ||||||||||||
| 82 | 0 | for (qw/ env cwd stdout stderr ubic_log /) { | |||||||||||
| 83 | 0 | ▶ | $daemon_opts->{$_} = $self->{$_} if defined $self->{$_}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | } | ||||||||||||
| 85 | 0 | start_daemon($daemon_opts); | |||||||||||
| 86 | 0 | return; | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | sub stop_impl { | ||||||||||||
| 90 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
stop_impl: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 91 | 0 | return stop_daemon($self->pidfile, { timeout => 7 }); | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | sub status_impl { | ||||||||||||
| 95 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
status_impl: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 96 | 0 | my $running = check_daemon($self->pidfile); | |||||||||||
| 97 | 0 | ▶ | return 'not running' unless ($running); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | 0 | ▶ | if ($self->{status}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 0 | return $self->{status}->(); | |||||||||||
| 100 | } else { | ||||||||||||
| 101 | 0 | return 'running'; | |||||||||||
| 102 | } | ||||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | sub reload { | ||||||||||||
| 106 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
reload: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 107 | 0 | my $reval = system $server_command, '--restart', | |||||||||||
| 108 | '--pid-file', $self->sspidfile, | ||||||||||||
| 109 | '--status-file', $self->statusfile; | ||||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | return 'reloaded' if $reval == 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | 0 | die 'failed to reload!'; | |||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | sub user { | ||||||||||||
| 116 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
user: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 117 | 0 | ▶ | return $self->{user} if defined $self->{user}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 0 | return $self->SUPER::user; | |||||||||||
| 119 | }; | ||||||||||||
| 120 | |||||||||||||
| 121 | sub group { | ||||||||||||
| 122 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
group: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 123 | 0 | my $groups = $self->{group}; | |||||||||||
| 124 | 0 | ▶ | return $self->SUPER::group() if not defined $groups; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | 0 | ▶ | return @$groups if ref $groups eq 'ARRAY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 126 | 0 | return $groups; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | sub timeout_options { | ||||||||||||
| 130 | # TODO - make them customizable | ||||||||||||
| 131 | return { | ||||||||||||
| 132 | 0 | ▶ | start => { trials => 15, step => 0.1 }, | ||||||||||
|
Subroutine
timeout_options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 133 | stop => { trials => 15, step => 0.1 }, | ||||||||||||
| 134 | }; | ||||||||||||
| 135 | } | ||||||||||||
| 136 | |||||||||||||
| 137 | 1 | 1; | |||||||||||
| 138 | |||||||||||||
| 139 | |||||||||||||
| 140 | __END__ | ||||||||||||