#!/usr/bin/perl
# You should symlink to this program from the init.d directory.
# The name of the link should be that of the module name you 
# want to use.
# Runs in verbose sysv startup mode
use NOCpulse::Object;
use lib qw(/etc/rc.d/np.d);
use RootOnlyPlease;
use NOCpulse::Config;
use SysVStep;

$NOCpulse::Object::config = NOCpulse::Config->new('/etc/rc.d/np.d/SysV.ini');
my $debug = NOCpulse::Debug->new; # default debug object
$debug->addstream(LEVEL=>1)->timestamps(1);
$debug->addstream(LEVEL=>1,
		FILE=>SysVStep->ConfigValue('logFileName'),
		APPEND=>1)->timestamps(1);

my @stepName = split('/',$0);
my $stepName = pop(@stepName);
$stepName =~ s/(S|K)(\d+)(.*)/$3/;
eval "require($stepName)";
if ($@) {
	$debug->dprint(1,"MODULE LOAD FAILED: $@\n");
	exit(1);
}
my $exitlevel;
eval {$exitlevel = $stepName->newInitialized()->run() };
if ($@) {
	$debug->dprint(1,"!!!!!!!!!! STEP $stepName EXECUTION FAILED: $@\n");
	exit(1);
}
exit($exitlevel);
