File Coverage

blib/lib/Svsh/S6.pm
Criterion Covered Total %
statement 6 12 50.0
branch n/a
condition 0 4 0.0
subroutine 2 5 40.0
pod 3 3 100.0
total 11 24 45.8


line stmt bran cond sub pod time code
1             package Svsh::S6;
2              
3 1     1   825 use Moo;
  1         2  
  1         5  
4 1     1   216 use namespace::clean;
  1         2  
  1         6  
5              
6             our $DEFAULT_BASEDIR = '/service';
7              
8             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
17             to L - the supervisor shell.
18              
19             =head2 DEFAULT BASE DIRECTORY
20              
21             C does not have a default base directory, but recommends C,
22             so that is what will be used if a base directory was not provided to C.
23              
24             =head1 IMPLEMENTED METHODS
25              
26             Refer to L 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     0 1   my $text = $_[0]->run_cmd('s6-svstat', $_[0]->basedir.'/'.$_[2]->{args}->[0].'/log');
104 0   0       my $pid = ($text =~ m/\(pid (\d+)\)/)[0]
105             || die "Can't figure out pid of the logging process";
106              
107             # find out the current log file
108 0   0       my $logfile = $_[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 1   $_[0]->run_cmd('s6-svscanctl', '-a', $_[0]->basedir);
120             }
121              
122             =head2 terminate()
123              
124             =cut
125              
126             sub terminate {
127 0     0 1   $_[0]->run_cmd('s6-svscanctl', '-t', $_[0]->basedir);
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, or through the web interface at
136             L.
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
151            
152             =item * AnnoCPAN: Annotated CPAN documentation
153            
154             L
155            
156             =item * CPAN Ratings
157            
158             L
159            
160             =item * Search CPAN
161            
162             L
163            
164             =back
165              
166             =head1 AUTHOR
167              
168             Ido Perlmuter
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
177             and L.
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;
208             __END__