Service function improvements

In May 2014 version 1.6.0 of lcfg-ngeneric was released which provided a new Service function for LCFG components (see this blog article for more details). The aim of this new feature was to make it possible to call daemon methods (e.g. stop, start, restart) in a platform-independent manner.

Originally the functionality in the Shell and Perl versions was implemented separately. This led to there being some inconsistencies in behaviour (e.g. only the Perl version supported setting timeouts). It also meant that adding new features was more difficult than necessary since everything had to be implemented twice.

Recently (version 1.15.0 of lcfg-ngeneric) we have revisited this code and split out the Perl implementation from the LCFG::Component module into a separate LCFG::Utils::Service module. This new module can be used in an entirely standalone manner from any Perl module or script. The new module has been designed to work in a similar way to the LCFG::Om::Command module. Here are a few examples:

use LCFG::Utils::Service;

my ( $status, $stdout, $stderr ) =
    LCFG::Utils::Service::Run( "crond", "status" );

my $status =
    LCFG::Utils::Service::Run( "sshd", "stop" );

LCFG::Utils::Service::Run( "httpd", "start",
                           { timeout => 20 } );

Alongside this new module has been added a wrapper script – lcfg-service which can be used from any script or the command line to call the daemon methods in a platform-independent way. This script is now used for the Service function in ngeneric. It supports setting a timeout, will exit with the status returned by the daemon method and also helpfully passes through any output to stderr or stdout so they can be captured in the calling script (for example, to redirect into a component log file).

To avoid some problems with timeout handling (see Bug#57277) we have raised the minimum required version of the IPC::Run to 0.91.

The actual API of the Service method in ngeneric is unchanged by the addition of this module and script. However, it’s worth noting that a couple of small changes in behaviour were made. There is now a default timeout of 10 minutes, in nearly all cases this will be more than adequate and should help avoid machines becoming hung. Also, for systemd, when a stop action is being called the --no-block option will be added to the arguments list. This avoids deadlock problems when a machine is being shut down. Without this we see problems when both systemd and an LCFG component request that a service be stopped. This has, in particular, affected the sshd service and the associated openssh LCFG component.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply