| 1 | package Sphinx::Control; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Errno qw/ECHILD/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.04'; | |||||||||
| 8 | 2 | our $AUTHORITY = 'cpan:FAYLAND'; | |||||||||
| 9 | |||||||||||
| 10 | 2 | with 'MooseX::Control'; | |||||||||
| 11 | |||||||||||
| 12 | 2 | has '+control_name' => ( default => 'searchd' ); | |||||||||
| 13 | 1 | ▶ | has 'indexer_args' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub pre_startup { inner() } | ||||||||
|
Subroutine
pre_startup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 16 | 0 | ▶ | sub post_startup { inner() } | ||||||||
|
Subroutine
post_startup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub pre_shutdown { inner() } | ||||||||
|
Subroutine
pre_shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 19 | 0 | ▶ | sub post_shutdown { inner() } | ||||||||
|
Subroutine
post_shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub get_server_pid { | ||||||||
|
Subroutine
get_server_pid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 22 | 0 | my $self = shift; | |||||||||
| 23 | |||||||||||
| 24 | 0 | my $pid = $self->pid_file->slurp(chomp => 1); | |||||||||
| 25 | 0 | ▶ | ($pid) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | || confess "No PID found in pid_file (" . $self->pid_file . ")"; | ||||||||||
| 27 | 0 | $pid; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub construct_command_line { | ||||||||
|
Subroutine
construct_command_line: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 31 | 0 | my $self = shift; | |||||||||
| 32 | 0 | my @opts = @_; | |||||||||
| 33 | 0 | my $conf = $self->config_file; | |||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | (-f $conf) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | || confess "Could not locate configuration file ($conf)"; | ||||||||||
| 37 | |||||||||||
| 38 | 0 | ($self->binary_path, @opts, '--config', $conf->stringify); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub find_pid_file { | ||||||||
|
Subroutine
find_pid_file: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 42 | 0 | my $self = shift; | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $config_file = $self->config_file; | |||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | (-f $config_file) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | || confess "Could not find pid_file because could not find config file ($config_file)"; | ||||||||||
| 48 | |||||||||||
| 49 | my @approaches = ( | ||||||||||
| 50 | 0 | ▶ | sub { $config_file->slurp(chomp => 1) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 51 | 0 | ); | |||||||||
| 52 | |||||||||||
| 53 | 0 | foreach my $approach (@approaches) { | |||||||||
| 54 | 0 | my @config = $approach->(); | |||||||||
| 55 | 0 | foreach my $line (@config) { | |||||||||
| 56 | 0 | ▶ | if ($line =~ /pid_file\s*\=\s*(.*)\s*/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | return Path::Class::File->new($1); | |||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | confess "Could not locate the pid-file information, please supply it manually"; | |||||||||
| 63 | }; | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub restart { | ||||||||
|
Subroutine
restart: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | 0 | my $self = shift; | |||||||||
| 67 | |||||||||||
| 68 | 0 | $self->debug("Restarting searchd ..."); | |||||||||
| 69 | 0 | $self->stop; | |||||||||
| 70 | |||||||||||
| 71 | 0 | $self->start; | |||||||||
| 72 | 0 | $self->debug("searchd restarted."); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub reload { | ||||||||
|
Subroutine
reload: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 76 | 0 | my $self = shift; | |||||||||
| 77 | |||||||||||
| 78 | 0 | $self->debug("reloading searchd ..."); | |||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | if ( $self->is_server_running ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | # send HUP | ||||||||||
| 82 | 0 | kill 1, $self->server_pid; | |||||||||
| 83 | } | ||||||||||
| 84 | else { | ||||||||||
| 85 | 0 | $self->start; | |||||||||
| 86 | } | ||||||||||
| 87 | 0 | $self->debug("searchd reloaded."); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | sub run_indexer { | ||||||||
|
Subroutine
run_indexer: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 91 | 0 | my $self = shift; | |||||||||
| 92 | 0 | my @extra_args = @_; | |||||||||
| 93 | |||||||||||
| 94 | 0 | my $searchd = $self->binary_path; | |||||||||
| 95 | 0 | my $indexer = $searchd; | |||||||||
| 96 | 0 | $indexer =~ s/searchd$/indexer/is; | |||||||||
| 97 | |||||||||||
| 98 | 0 | ▶ | confess "Cannot execute Sphinx indexer binary $indexer" unless -x $indexer; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | |||||||||||
| 100 | 0 | $self->debug("starting indexer ..."); | |||||||||
| 101 | |||||||||||
| 102 | 0 | my $config = $self->config_file->stringify; | |||||||||
| 103 | 0 | my $cmd = "$indexer --config $config"; | |||||||||
| 104 | 0 | ▶ | $cmd .= ' ' . join(" ", @{$self->indexer_args}) if $self->indexer_args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | ▶ | $cmd .= ' ' . join(" ", @extra_args) if @extra_args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | |||||||||||
| 107 | 0 | $self->debug("run $cmd..."); | |||||||||
| 108 | 0 | ▶ | if (my $status = _system_with_status($cmd)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | confess $status; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 0 | $self->debug("indexer done..."); | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | 0 | ▶ | sub _system_with_status { | ||||||||
|
Subroutine
_system_with_status: not called CC=6 SCAR=37.4
| |||||||||||
| 116 | 0 | my ($command) = @_; | |||||||||
| 117 | |||||||||||
| 118 | 0 | local $SIG{CHLD} = 'IGNORE'; | |||||||||
| 119 | 0 | my $status = system($command); | |||||||||
| 120 | 0 | ▶ | unless ($status == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 0 | ▶ | if ($? == -1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 0 | ▶ | return '' if $! == ECHILD; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | return "$command failed to execute: $!"; | |||||||||
| 124 | } | ||||||||||
| 125 | 0 | ▶ | if ($? & 127) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | ▶ | return sprintf("$command died with signal %d, %s coredump\n", | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | ($? & 127), ($? & 128) ? 'with' : 'without'); | ||||||||||
| 128 | } | ||||||||||
| 129 | 0 | return sprintf("$command exited with value %d\n", $? >> 8); | |||||||||
| 130 | } | ||||||||||
| 131 | 0 | return ''; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | 2 | ▶ | no Moose; 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 135 | |||||||||||
| 136 | 2 | 1; | |||||||||
| 137 | __END__ | ||||||||||