NAME

SysV::Init::Service - Class for SysV init service manipulation.

SYNOPSIS

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;

METHODS

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.

ERRORS

new():
        Parameter 'service' is required.
        Service '%s' doesn't present.
        Service with .sh suffix doesn't possible.
        From Class::Utils::set_params():
                Unknown parameter '%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.

EXAMPLE

# 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

DEPENDENCIES

Class::Utils, English, Error::Pure, File::Spec::Functions, IO::CaptureOutput, List::MoreUtils.

SEE ALSO

service.

REPOSITORY

https://github.com/tupinek/SysV-Init-Service

AUTHOR

Michal Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

BSD license.

VERSION

0.02