Ubic-Service-InitScriptWrapper
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Ubic/Service/InitScriptWrapper.pm view on Meta::CPAN
package Ubic::Service::InitScriptWrapper;
{
$Ubic::Service::InitScriptWrapper::VERSION = '0.02';
}
# ABSTRACT: represent any /etc/init.d/ script as ubic service
use strict;
use warnings;
use parent qw(Ubic::Service::Skeleton);
use autodie qw(:all);
use IPC::System::Simple; # force system() support for autodie
sub new {
my $class = shift;
my ($init) = @_;
die "Invalid parameters" unless @_ == 1;
if ($init !~ m{/}) {
$init = "/etc/init.d/$init";
}
unless (-e $init) {
die "Init script $init not found";
}
return bless { init => $init } => $class;
}
sub start_impl {
my $self = shift;
system("$self->{init} start >/dev/null");
}
sub stop_impl {
my $self = shift;
system("$self->{init} stop >/dev/null");
}
sub reload {
my $self = shift;
system("$self->{init} reload >/dev/null");
return 'reloaded'; # we expect system() to fail if reload is not implemented
}
sub status_impl {
my $self = shift;
no autodie;
my $code = system("$self->{init} status >/dev/null");
if ($code == 0) {
return 'running';
}
else {
return 'not running'; # TODO - distinguish 'not running' and 'broken'
}
}
1;
__END__
=pod
=head1 NAME
Ubic::Service::InitScriptWrapper - represent any /etc/init.d/ script as ubic service
=head1 VERSION
version 0.02
=head1 SYNOPSIS
# in /etc/ubic/service/my-nginx
use Ubic::Service::InitScriptWrapper;
Ubic::Service::InitScriptWrapper->new('nginx'); # map /etc/init.d/nginx to 'my-nginx' ubic service
=head1 DESCRIPTION
This module lets you turn any LSB-compliant init script into ubic service.
Note that this is completely different from L<Ubic::Run>. C<Ubic::Run> lets you
turn ubic service to init script. This module does the reverse thing.
=head1 WHY?
There are several reasons why this module can be useful.
view all matches for this distributionview release on metacpan - search on metacpan
( run in 3.124 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-48ebf85a1963 )