Commit 519ba19b authored by Leigh Stoller's avatar Leigh Stoller

Switch power command to use syslog; since power runs as the user, it

might not be able to write the output file. Better to us syslog anyway
since its a low usage command.
parent 213d2a15
#
# Switch power to use syslog.
#
use strict;
use libinstall;
my $SYSLOG_CONF = "/etc/syslog.conf";
my $POWERLOG = "$TBROOT/log/power.log";
my $CHMOD = "/bin/chmod";
my $CHGRP = "/usr/bin/chgrp";
sub InstallUpdate($$)
{
my ($version, $phase) = @_;
#
# If something should run in the pre-install phase.
#
if ($phase eq "pre") {
Phase "power", "Updating power logging", sub {
Phase "syslog.conf", "Updating $SYSLOG_CONF", sub {
DoneIfEdited($SYSLOG_CONF);
BackUpFileFatal($SYSLOG_CONF);
AppendToFileFatal($SYSLOG_CONF,
"!power", "*.*\t\t\t\t\t\t$LOGDIR/power.log");
};
Phase "logfile", "Creating $POWERLOG", sub {
DoneIfExists($POWERLOG);
CreateFileFatal($POWERLOG);
ExecQuietFatal("$CHGRP tbadmin $POWERLOG");
ExecQuietFatal("$CHMOD 640 $POWERLOG");
};
Phase "syslogd", "Restarting syslogd", sub {
HUPDaemon("syslog");
};
};
}
#
# If something should run in the post-install phase.
#
if ($phase eq "post") {
}
return 0;
}
1;
......@@ -23,7 +23,7 @@ my $RPCSERVER = "@OUTERBOSS_NODENAME@";
my $RPCPORT = "@OUTERBOSS_XMLRPCPORT@";
my $RPCCERT = "@OUTERBOSS_SSLCERTNAME@";
my $WOL = "$TB/sbin/whol";
my $logfile = "$TB/log/power.log";
my $TBLOG = "@TBLOGFACIL@";
use lib "@prefix@/lib";
use libdb;
......@@ -44,6 +44,7 @@ use strict;
use English;
use Getopt::Std;
use POSIX qw(strftime);
use Sys::Syslog;
sub usage() {
print << "END";
......@@ -137,6 +138,9 @@ foreach my $n (0..$#machines) {
#
print "do \"$op\" to @machines\n" if $verbose > 1;
# Set up syslog
openlog("power", "pid", $TBLOG);
#
# Handle the status command which is not a per-node operation and not
# allowed by anyone except admins.
......@@ -674,8 +678,9 @@ sub logit($)
my ($message) = @_;
my ($me) = getpwuid($UID);
# Sep 20 09:36:00 [$me] $message
open(LOG,">> $logfile");
print LOG strftime("%b %e %H:%M:%S", localtime) . " [$me] $message";
close(LOG);
syslog("info", "[$me] $message");
}
END {
closelog();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment