@ -37,6 +37,7 @@ my $conf = {
'system' => {
action => "off",
agent_version => "1.0",
do_chown => 0,
log_level => 1,
'wait' => 60,
device => "",
@ -54,8 +55,14 @@ my $conf = {
};
# Log file for output.
if (not -e $conf->{'system'}{'log'})
{
# We'll chown the log.
$conf->{'system'}{do_chown} = 1;
}
my $log = IO::Handle->new();
open ($log, ">>".$conf->{'system'}{'log'}) || warn "Failed to open: [".$conf->{'system'}{'log'}."] for writing; Error: $!\n";
open ($log, ">>".$conf->{'system'}{'log'}) || die "Failed to open: [".$conf->{'system'}{'log'}."] for writing; Error: $!\n";
# Set $log and STDOUT to hot (unbuffered) output.
if (1)
{
@ -74,7 +81,7 @@ read_cla($conf, $log);
read_stdin($conf, $log);
# If I've been asked to show the metadata XML, do so and then exit.
if (( $conf->{'system'}{action} eq "metadata") or ($conf->{'system'}{action} eq "meta-data") )
if ($conf->{'system'}{action} eq "metadata")
{
metadata($conf, $log);
do_exit($conf, $log, 0);
@ -116,6 +123,16 @@ sub do_exit
# Close the log file handle, if it exists.
$log->close() if $log;
record($conf, $log, "system::do_chown: [".$conf->{'system'}{do_chown}."].\n", 2);
if ($conf->{'system'}{do_chown})
{
record($conf, $log, "Changing ownership of: [".$conf->{'system'}{do_chown}."] to [hacluster:haclient].\n", 1);
my $uid = getpwnam('hacluster');
my $gid = getgrnam('haclient');
record($conf, $log, "chown'ing: [".$conf->{'system'}{do_chown}."].\n", 2);
chown $uid, $gid, $conf->{'system'}{'log'};
}
exit ($exit_status);
}
@ -274,36 +291,36 @@ sub read_cla
{
# Print the version information and then exit.
$conf->{'system'}{version} = 1;
record($conf, $log, "[ Debug ] - 'system::version': . [".$conf->{'system'}{version}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::version': [".$conf->{'system'}{version}."]\n", 2 );
}
elsif (($arg eq "-q") or ($arg eq "--quiet"))
{
# Suppress all messages, including critical messages, from STDOUT.
$conf->{'system'}{log_level} = 0;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{quiet}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{quiet}."]\n", 2 );
}
elsif ($arg eq "--debug")
{
# Enable debug mode.
$conf->{'system'}{log_level} = 2;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 2 );
}
elsif (($arg eq "-w") or ($arg eq "--wait"))
{
# How long to wait before exiting.
$set_next = "wait";
record($conf, $log, "[ Debug ] - 'set_next': ........ [".$set_next."]\n", 1 );
record($conf, $log, "[ Debug ] - 'set_next': [".$set_next."]\n", 2 );
}
elsif (($arg eq "-o") or ($arg eq "--action"))
{
# This is the action to take.
$set_next = "action";
record($conf, $log, "[ Debug ] - 'set_next': ........ [".$set_next."]\n", 1 );
record($conf, $log, "[ Debug ] - 'set_next': [".$set_next."]\n", 2 );
}
else
{
# Bad argument.
record($conf, $log, "[ Warning ] - Argument: [".$arg."] is not valid arguments.\n", 1 );
record($conf, $log, "[ Warning ] - Argument: [".$arg."] is not valid arguments.\n", 2 );
}
}
@ -344,7 +361,7 @@ sub read_stdin
my ($name, $value) = split /\s*=\s*/, $option;
# Record the line for now, but comment this out before release.
record ($conf, $log, "Name: [$name], value: [$value].\n", 2 );
record ($conf, $log, "Name: [$name], value: [$value].\n");
# Set my variables depending on the veriable name.
if ($name eq "agent")
@ -352,27 +369,27 @@ sub read_stdin
# This is only used by 'fenced', but I record it for
# potential debugging.
$conf->{'system'}{agent} = $value;
record($conf, $log, "[ Debug ] - 'system::agent': ... [".$conf->{'system'}{agent}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::agent': [".$conf->{'system'}{agent}."]\n", 2 );
}
elsif ($name eq "action")
{
$conf->{'system'}{action} = $value;
record($conf, $log, "[ Debug ] - 'system::action': .. [".$conf->{'system'}{action}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::action': [".$conf->{'system'}{action}."]\n", 2 );
}
elsif ($name eq "quiet")
{
$conf->{'system'}{log_level} = 0;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 2 );
}
elsif ($name eq "debug")
{
$conf->{'system'}{log_level} = 2;
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::log_level': [".$conf->{'system'}{log_level}."]\n", 2 );
}
elsif ($name eq "wait")
{
$conf->{'system'}{wait} = $value;
record($conf, $log, "[ Debug ] - 'system::wait': .... [".$conf->{'system'}{'wait'}."]\n", 1 );
record($conf, $log, "[ Debug ] - 'system::wait': [".$conf->{'system'}{wait}."]\n", 2 );
}
else
{
@ -392,7 +409,7 @@ sub record
return if $level > $conf->{'system'}{log_level};
# Print to the log
print $log get_date_time($conf)." - ". $msg;
print $log $msg;
# Print to the screen if we're not 'quiet'.
print $msg if not $conf->{'system'}{quiet};