The LCFG client uses the
om command line tool to call the
configure method for an LCFG component when the resources change. Up until now this has been done using backticks which is not the best approach, particularly given that this involves building a command string and launching a full shell. I’ve now added a new Perl module to help with running om commands from perl. It’s in version 0.7.1 of lcfg-om, you can use it like this:
use LCFG::Om::Command; my ( $status, $stdout, $stderr ) = LCFG::Om::Command::Run( "updaterpms", "run", "-Dv", "-t" );
The parameters are: component, method, ngeneric args, component args. You only need to specify the component and method names, the other two are optional. The argument options can either be simple strings or references to lists.
The status will be true/false to show the success of the command. You also get any output to stdout and stderr separately.
If you’re concerned that some method might not complete in a reasonable amount of time you can specify a timeout for the command:
my ( $status, $stdout, $stderr ) = LCFG::Om::Command::Run( "openafs", "restart", "-Dv", "", $timeout );
If the timeout is reached then the Run command dies, you need to use
eval or a module like
Try::Tiny to catch that exception.
Nicely this will also close file-descriptors 11 and 12 which are used internally by the LCFG ngeneric framework for logging. This will avoid daemons becoming asociated with those files when they are restarted (and consequently
tieing up the rdxprof process).
This is one of those nice situations where fixing a problem for one project has additional benefits for others. The trick here was in realising that the code should be added to the
lcfg-om project rather than it just being in the LCFG client code base.