3.11. services

3.11.1. NAME

services - Guardian Digital WebTool module interface to system services.

3.11.2. SYNOPSIS

use services;
my $services  = new services();

3.11.3. DESCRIPTION

This Guardian Digital WebTool module provides an interface to manipulating system services. This module allows you to start and stop services, enable and disable services at boot time, and get the current and boot status for services. This function allows you to manipulate xinetd-based services.

3.11.4. METHODS

read_initscript($)

This function reads a given daemon file(usually under /etc/init.d/).It returns values of chkconfig and description in hash reference only if both exists in file. Chkconfig values consists of in which runlevel it should start, its start priority and stop priority.

Example Usage:

my $data    = read_initscript(DIR_INITSCRIPTS . '/' . $f);
next if (! defined($data) || $blacklist->{$data->{'name'}});
$data->{'current_state'}    = $self->current_state($data->{'name'});
$data->{'boot_state'}       = $self->boot_state($data->{'name'});

read_xinetd($)

This function reads a given daemon file(usually under /etc/xinetd.d/). It returns values of interface(what IPs it should listen to), service enable/disable and description in hash reference.

Example Usage:

my $tmp  = read_xinetd(DIR_XINETD . '/' . $f);
$description    = $tmp->{'description'};
$interface      = $tmp->{'interface'};
$disable_status = $tmp->{'disable'};

boot_state($)

This function basically checks particular service is scheduled to start at booting or not. It takes service name as argument. It reads through applying chkconfig command and returns 1 if service is running or run level 3 is on.

Example Usage:

$boot_schedule = $services->boot_state($service);

current_state($)

This function can be used to check the current status of service by passing service name as argument. Returns 1 if service is running.

Example Usage:

$current_status = $services->current_state($service);

list_services()

This function basically lists all services from /etc/init.d/ and /etc/xinetd.d and return data like current state, boot state, name, description back in array form.

Example Usage:

foreach my $svc ($services->list_services()) {
 my $service         = $svc->{'name'};
 my $description     = $page->str_truncate(make_description($page, $svc), 60);
 my $current_state   = make_toggle_link($page, 'current', $svc->{'name'},
                             $svc->{'current_state'}, $svc->{'type'});
 my $boot_state      = make_toggle_link($page, 'boot', $svc->{'name'},
                             $svc->{'boot_state'}, $svc->{'type'});
 }

run_initscript($$)

Depending on the arguments (service name and operation), this function is used to start/stop/restart given service.(e.g /etc/init.d/named start). Returns true or false.

Example Usage:

$services->run_initscript($service, 'start');

start($)

This function is used to start a particular service, it receives a service name as an argument.

Example Usage:

if ($services->start('ftp') == 0) {
.....
}

stop($)

This function is used to stop a particular service, it receives a service name as an argument.

Example Usage:

if ($services->stop('ftp') == 0) {
.....
}

restart($)

This function is used to restart a particular service, it receives a service name as an argument.

Example Usage:

$services->restart('ftp');

run_chkconfig($$)

This function is used to activate/deactivate service at boot time. It receives two arguments(operation=add/delete and service=service name). Its been done using /sbin/chkconfig --operation servicename command.

Example Usage:

$services->run_chkconfig('add', $service);

enable($)

This function is used to add(enable) service at boot time. It receives service name as argument.

Example Usage:

if ($services->enable('ftp') == 0) {
.....
}

disable($)

This function is used to delete(disable) service at boot time. It receives service name as argument.

Example Usage:

if ($services->disable('ftp') == 0) {
.....
}

xinetd_enable($)

This function is used to enable inetd-based services(e.g.ftp,simap). it receives service name as an argument and opens service file under /etc/xinetd.d. In that file it comment out disable option. Then it restarts xinetd.

Example Usage:

$services->xinetd_enable('ftp');

xinetd_disable($)

This function is used to disable inetd-based services(e.g.ftp,simap). it receives service name as an argument and opens service file under /etc/xinetd.d. In that file it turn on disable option. Then it restarts xinetd.

Example Usage:

$services->xinetd_disable('ftp');

3.11.5. AUTHORS

Ryan W. Maple <ryan@guardiandigital.com>

3.11.6. COPYRIGHT AND LICENSE

Copyright Guardian Digital, Inc., All Rights Reserved