| 1 | package Svsh::S6; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | our $DEFAULT_BASEDIR = '/service'; | |||||||||||
| 7 | |||||||||||||
| 8 | 1 | with 'Svsh'; | |||||||||||
| 9 | |||||||||||||
| 10 | =head1 NAME | ||||||||||||
| 11 | |||||||||||||
| 12 | Svsh::S6 - s6 support for svsh | ||||||||||||
| 13 | |||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||
| 15 | |||||||||||||
| 16 | This class provides support for L<s6|http://www.skarnet.org/software/s6/> | ||||||||||||
| 17 | to L<svsh> - the supervisor shell. | ||||||||||||
| 18 | |||||||||||||
| 19 | =head2 DEFAULT BASE DIRECTORY | ||||||||||||
| 20 | |||||||||||||
| 21 | C<s6> does not have a default base directory, but recommends C</service>, | ||||||||||||
| 22 | so that is what will be used if a base directory was not provided to C<svsh>. | ||||||||||||
| 23 | |||||||||||||
| 24 | =head1 IMPLEMENTED METHODS | ||||||||||||
| 25 | |||||||||||||
| 26 | Refer to L<Svsh> for complete explanation of these methods. Only changes from | ||||||||||||
| 27 | the base specifications are listed here. | ||||||||||||
| 28 | |||||||||||||
| 29 | =head2 status() | ||||||||||||
| 30 | |||||||||||||
| 31 | =cut | ||||||||||||
| 32 | |||||||||||||
| 33 | sub status { | ||||||||||||
| 34 | my $statuses = {}; | ||||||||||||
| 35 | foreach ($_[0]->_service_dirs) { | ||||||||||||
| 36 | my $raw = $_[0]->run_cmd('s6-svstat', $_[0]->basedir.'/'.$_); | ||||||||||||
| 37 | my ($status, $comment, $seconds) = ($raw =~ m/(up|down) \(([^\)]+)\) (\d+)/); | ||||||||||||
| 38 | $statuses->{$_} = { | ||||||||||||
| 39 | status => $status, | ||||||||||||
| 40 | duration => $seconds, | ||||||||||||
| 41 | pid => '-' | ||||||||||||
| 42 | }; | ||||||||||||
| 43 | |||||||||||||
| 44 | if ($comment =~ m/pid (\d+)/) { | ||||||||||||
| 45 | $statuses->{$_}->{pid} = $1; | ||||||||||||
| 46 | } | ||||||||||||
| 47 | } | ||||||||||||
| 48 | return $statuses; | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | =head2 start( @services ) | ||||||||||||
| 52 | |||||||||||||
| 53 | =cut | ||||||||||||
| 54 | |||||||||||||
| 55 | sub start { | ||||||||||||
| 56 | foreach (@{$_[2]->{args}}) { | ||||||||||||
| 57 | $_[0]->run_cmd('s6-svc', '-u', $_[0]->basedir.'/'.$_); | ||||||||||||
| 58 | } | ||||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | =head2 stop( @services ) | ||||||||||||
| 62 | |||||||||||||
| 63 | =cut | ||||||||||||
| 64 | |||||||||||||
| 65 | sub stop { | ||||||||||||
| 66 | foreach (@{$_[2]->{args}}) { | ||||||||||||
| 67 | $_[0]->run_cmd('s6-svc', '-Dd', $_[0]->basedir.'/'.$_); | ||||||||||||
| 68 | } | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | =head2 restart( @services ) | ||||||||||||
| 72 | |||||||||||||
| 73 | =cut | ||||||||||||
| 74 | |||||||||||||
| 75 | sub restart { | ||||||||||||
| 76 | foreach (@{$_[2]->{args}}) { | ||||||||||||
| 77 | $_[0]->run_cmd('s6-svc', '-q', $_[0]->basedir.'/'.$_); | ||||||||||||
| 78 | } | ||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | =head2 signal( $signal, @services ) | ||||||||||||
| 82 | |||||||||||||
| 83 | =cut | ||||||||||||
| 84 | |||||||||||||
| 85 | sub signal { | ||||||||||||
| 86 | my ($sign, @sv) = @{$_[2]->{args}}; | ||||||||||||
| 87 | |||||||||||||
| 88 | # convert signal to perpctl command | ||||||||||||
| 89 | $sign =~ s/^sig//i; | ||||||||||||
| 90 | my $cmd = $sign =~ m/^usr(1|2)$/i ? $1 : lc(substr($sign, 0, 1)); | ||||||||||||
| 91 | |||||||||||||
| 92 | foreach (@sv) { | ||||||||||||
| 93 | $_[0]->run_cmd('s6-svc', "-$cmd", $_[0]->basedir.'/'.$_); | ||||||||||||
| 94 | } | ||||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | =head2 fg( $service ) | ||||||||||||
| 98 | |||||||||||||
| 99 | =cut | ||||||||||||
| 100 | |||||||||||||
| 101 | sub fg { | ||||||||||||
| 102 | # find out the pid of the logging process | ||||||||||||
| 103 | 0 | ▶ | my $text = $_[0]->run_cmd('s6-svstat', $_[0]->basedir.'/'.$_[2]->{args}->[0].'/log'); | ||||||||||
|
Subroutine
fg: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 104 | 0 | ▶ | my $pid = ($text =~ m/\(pid (\d+)\)/)[0] | ||||||||||
|
Condition0%0/2
($text =~ /\(pid (\d+)\)/)[0] || die(q[Can't figure out pid of the logging process])
MC/DC0%0/1
($text =~ /\(pid (\d+)\)/)[0] || die(q[Can't figure out pid of the logging process])
($text =~ /\(pid (\d+)\)/)[0]
Truth table0%0/2
A
A= ($text =~ /\(pid (\d+)\)/)[0]
| |||||||||||||
| 105 | || die "Can't figure out pid of the logging process"; | ||||||||||||
| 106 | |||||||||||||
| 107 | # find out the current log file | ||||||||||||
| 108 | 0 | ▶ | my $logfile = $_[0]->find_logfile($pid) | ||||||||||
|
Condition0%0/2
$_[0]->find_logfile($pid) || die(q[Can't find out process' log file])
MC/DC0%0/1
$_[0]->find_logfile($pid) || die(q[Can't find out process' log file])
$_[0]->find_logfile($pid)
Truth table0%0/2
A
A= $_[0]->find_logfile($pid)
| |||||||||||||
| 109 | || die "Can't find out process' log file"; | ||||||||||||
| 110 | |||||||||||||
| 111 | 0 | $_[0]->run_cmd('tail', '-f', $logfile, { as_system => 1 }); | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | =head2 rescan() | ||||||||||||
| 115 | |||||||||||||
| 116 | =cut | ||||||||||||
| 117 | |||||||||||||
| 118 | sub rescan { | ||||||||||||
| 119 | 0 | ▶ | $_[0]->run_cmd('s6-svscanctl', '-a', $_[0]->basedir); | ||||||||||
|
Subroutine
rescan: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | =head2 terminate() | ||||||||||||
| 123 | |||||||||||||
| 124 | =cut | ||||||||||||
| 125 | |||||||||||||
| 126 | sub terminate { | ||||||||||||
| 127 | 0 | ▶ | $_[0]->run_cmd('s6-svscanctl', '-t', $_[0]->basedir); | ||||||||||
|
Subroutine
terminate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | =head1 BUGS AND LIMITATIONS | ||||||||||||
| 131 | |||||||||||||
| 132 | No bugs have been reported. | ||||||||||||
| 133 | |||||||||||||
| 134 | Please report any bugs or feature requests to | ||||||||||||
| 135 | C<bug-Svsh@rt.cpan.org>, or through the web interface at | ||||||||||||
| 136 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Svsh>. | ||||||||||||
| 137 | |||||||||||||
| 138 | =head1 SUPPORT | ||||||||||||
| 139 | |||||||||||||
| 140 | You can find documentation for this module with the perldoc command. | ||||||||||||
| 141 | |||||||||||||
| 142 | perldoc Svsh::S6 | ||||||||||||
| 143 | |||||||||||||
| 144 | You can also look for information at: | ||||||||||||
| 145 | |||||||||||||
| 146 | =over 4 | ||||||||||||
| 147 | |||||||||||||
| 148 | =item * RT: CPAN's request tracker | ||||||||||||
| 149 | |||||||||||||
| 150 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Svsh> | ||||||||||||
| 151 | |||||||||||||
| 152 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||
| 153 | |||||||||||||
| 154 | L<http://annocpan.org/dist/Svsh> | ||||||||||||
| 155 | |||||||||||||
| 156 | =item * CPAN Ratings | ||||||||||||
| 157 | |||||||||||||
| 158 | L<http://cpanratings.perl.org/d/Svsh> | ||||||||||||
| 159 | |||||||||||||
| 160 | =item * Search CPAN | ||||||||||||
| 161 | |||||||||||||
| 162 | L<http://search.cpan.org/dist/Svsh/> | ||||||||||||
| 163 | |||||||||||||
| 164 | =back | ||||||||||||
| 165 | |||||||||||||
| 166 | =head1 AUTHOR | ||||||||||||
| 167 | |||||||||||||
| 168 | Ido Perlmuter <ido at ido50 dot net> | ||||||||||||
| 169 | |||||||||||||
| 170 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 171 | |||||||||||||
| 172 | Copyright (c) 2015, Ido Perlmuter C<< ido at ido50 dot net >>. | ||||||||||||
| 173 | |||||||||||||
| 174 | This module is free software; you can redistribute it and/or | ||||||||||||
| 175 | modify it under the same terms as Perl itself, either version | ||||||||||||
| 176 | 5.8.1 or any later version. See L<perlartistic|perlartistic> | ||||||||||||
| 177 | and L<perlgpl|perlgpl>. | ||||||||||||
| 178 | |||||||||||||
| 179 | The full text of the license can be found in the | ||||||||||||
| 180 | LICENSE file included with this module. | ||||||||||||
| 181 | |||||||||||||
| 182 | =head1 DISCLAIMER OF WARRANTY | ||||||||||||
| 183 | |||||||||||||
| 184 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||||||||||||
| 185 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | ||||||||||||
| 186 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | ||||||||||||
| 187 | PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER | ||||||||||||
| 188 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||||||||||||
| 189 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE | ||||||||||||
| 190 | ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH | ||||||||||||
| 191 | YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL | ||||||||||||
| 192 | NECESSARY SERVICING, REPAIR, OR CORRECTION. | ||||||||||||
| 193 | |||||||||||||
| 194 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||||||||||||
| 195 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||||||||||||
| 196 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE | ||||||||||||
| 197 | LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, | ||||||||||||
| 198 | OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE | ||||||||||||
| 199 | THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | ||||||||||||
| 200 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | ||||||||||||
| 201 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | ||||||||||||
| 202 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||||||||||||
| 203 | SUCH DAMAGES. | ||||||||||||
| 204 | |||||||||||||
| 205 | =cut | ||||||||||||
| 206 | |||||||||||||
| 207 | 1 | 1; | |||||||||||
| 208 | __END__ | ||||||||||||