SysV::Init::Service - Class for SysV init service manipulation.
use SysV::Init::Service; my $obj = SysV::Init::Service->new(%parameters); my @commands = $obj->commands; my $name = $obj->name; my $exit_code = $obj->start; my $exit_code = $obj->status; my $exit_code = $obj->stop;
new(%parameters)
Constructor.
service
Service. Default value is undef. It is required.
service_dir
Service directory. Default value is '/etc/init.d'.
commands()
Get service commands. Returns array of possible commands alphabetically sorted.
name()
Get service name. Returns string with service name.
start()
Run service start command. Returns exit code.
status()
Run service status command and return exit code. Returns exit code.
stop()
Run service stop command. Returns exit code.
new(): Parameter 'service' is required. Service '%s' doesn't present. From Class::Utils::set_params(): Unknown parameter '%s'. commands(): Problem with run service '%s'. STDERR: %s start(): Problem with service '%s' start. STDERR: %s Service hasn't start command. status(): Service hasn't status command. stop(): Problem with service '%s' stop. STDERR: %s Service hasn't stop command.
# Pragmas. use strict; use warnings; # Modules. use File::Spec::Functions qw(catfile); use File::Temp qw(tempfile tempdir); use IO::Barf qw(barf); use SysV::Init::Service; # Temporary directory. my $temp_dir = tempdir('CLEANUP' => 1); # Create fake service. my $fake = <<'END'; #!/bin/sh echo "[ ok ] Usage: /fake {start|stop|status}." END # Save to file. my $fake_file = catfile($temp_dir, 'fake'); barf($fake_file, $fake); # Chmod. chmod 0755, $fake_file; # Service object. my $obj = SysV::Init::Service->new( 'service' => 'fake', 'service_dir' => $temp_dir, ); # Get commands. my @commands = $obj->commands; # Print commands to output. map { print $_."\n"; } @commands; # Clean. unlink $fake_file; # Output: # start # stop # status
Class::Utils, English, Error::Pure, File::Spec::Functions, IO::CaptureOutput, List::MoreUtils.
service.
https://github.com/tupinek/SysV-Init-Service
Michal Špaček mailto:skim@cpan.org
http://skim.cz
BSD license.
0.01
To install SysV::Init::Service, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SysV::Init::Service
CPAN shell
perl -MCPAN -e shell install SysV::Init::Service
For more information on module installation, please visit the detailed CPAN module installation guide.