Commit 9510fdcf authored by Leigh Stoller's avatar Leigh Stoller

Strip out all the syslog stuff from stated and just write to a file.

I added a sig handler to reopen the log file. See corresponding changes
to doc/UPDATING and to install/boss-install.in
parent cbe236c4
......@@ -18,6 +18,17 @@ Note that some instructions may have steps that need to occur at a few
different points in the install process - these are marked with the
earliest time one of the steps needs to occur.
20100108: After install:
Change to how stated does it logging. In /etc/newsyslog.conf,
find the line for stated, and append this to the end of that line.
/var/run/stated.pid 31
then restart stated:
sudo kill -USR1 `cat /var/run/stated.pid`
20091228: After install:
New daemon to better manage the transition of nodes into
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -32,6 +32,7 @@ my $rebootlog = "$TB/log/nodereboot.log";
my $power = "$TB/bin/power";
my $apod = "$TB/sbin/apod";
my $TBLOG = "@TBLOGFACIL@";
my $LOGFILE = "$TB/log/stated.log";
$| = 1;
......@@ -44,14 +45,6 @@ use Getopt::Std;
use English;
use POSIX; # for strftime, and sigprocmask and friends
use Fcntl; # file constants for pidfile
use Sys::Syslog;
# Important note about syslog: It defaults to using an inet socket,
# but 'syslogd -s' (the default) doesn't listen for one. So either
# run syslogd without -s, or use setlogsock('unix') before openlog.
# (To get setlocksock: 'use Sys::Syslog qw(:DEFAULT setlogsock);' )
# Do lots of db retries before we fail and die
$libdb::DBQUERY_MAXTRIES = 100;
# Set up some notification throttling
my $mailgap = 15; # in seconds
......@@ -67,7 +60,6 @@ my $last_reload = time;
# Command line opts.
my $dbtag = "";
my $debug = 0;
my $nolog = 0;
my $server = "localhost";
my $port = @BOSSEVENTPORT@;
my $lockfile;
......@@ -80,7 +72,6 @@ sub usage {
Usage: $0 [-h] [-d] [-s server] [-p port] [-t dbtag]
-h This message
-d Turn on debugging output, and do not go into the background
-l Do not use syslog; send output to stderr. Use with -d only
-t tag Use only those nodes with matching tag in nodes table
-s server Use specified server, instead of this site's bossnode
-p port Use specified port
......@@ -112,11 +103,6 @@ if ($opt{s}) {
if ($opt{p}) {
$port = $opt{p};
}
if ($opt{l}) {
usage()
if (! $opt{d});
$nolog = 1;
}
if ($opt{t}) {
$dbtag = $opt{t};
}
......@@ -158,7 +144,7 @@ my $PXEKERNEL = "PXEKERNEL";
sub debug(@);
sub fatal($);
sub notify($;$);
sub info($;$);
sub info($);
sub getTimeouts();
sub getValid();
sub getModeTrans();
......@@ -190,16 +176,11 @@ if (!$debug) {
fatal("Couldn't remove $pidfile: $? $!\n");
}
# Background
# We use syslog, so redirect the output to nothing
if (TBBackGround("/dev/null")) {
if (TBBackGround($LOGFILE)) {
exit(0);
}
TBdbfork();
}
# set up syslog
if (! $nolog) {
openlog("stated","pid",$TBLOG);
}
if (defined($pidfile)) {
sysopen(PIDFILE, $pidfile, O_WRONLY | O_EXCL | O_CREAT) ||
......@@ -251,20 +232,20 @@ if ($debug) { qshow(); }
my $do_reload = 0;
my $sigrestart= 0;
my $sigcleanup= 0;
my $exiting = 0;
# Make the daemon reload database state on a sighup - but I'm worried
# about what would happen if we tried to do this mid-loop. So, we'll
# just set a flag and do it when we're done with our current pass.
$SIG{HUP} = sub { info("SIGHUP - Reloading DB state\n"); $do_reload = 1; };
$SIG{USR2} = sub { info("SIGUSR2 - Reopening logfile\n"); ReOpenLog($LOGFILE); };
# Set up other signals.
$SIG{USR1} = \&restart_wrap;
$SIG{USR2} = \&cleanup_wrap;
$SIG{INT} = \&cleanup_wrap;
$SIG{QUIT} = \&cleanup_wrap;
$SIG{ABRT} = \&cleanup_wrap;
$SIG{TERM} = \&cleanup_wrap;
$SIG{KILL} = \&cleanup_wrap;
# Track if I handled an event or not
my $event_count = 0;
......@@ -1469,7 +1450,7 @@ sub os_opmode() {
sub debug(@) {
if ($debug) {
print @_;
print STDERR @_;
}
}
......@@ -1563,26 +1544,12 @@ sub announce($) {
}
}
sub info($;$) {
sub info($) {
my $message = shift;
my $notice = shift || 0;
# Use syslog
my $prio="info";
if ($notice) {
$prio = "notice";
}
if ($nolog) {
print $message;
}
else {
if ($debug) {
# Print out log entries like this:
# Sep 20 09:36:00 stated[238]: Reloading state from database
print strftime("%b %e %H:%M:%S",localtime)." stated[$$]: $message";
$message = "DEBUG: ".$message;
}
syslog($prio,$message) || notify("syslog failed: $? $!\n");
}
# Print out log entries like this:
# Sep 20 09:36:00 [238]: Reloading state from database
print strftime("%b %e %H:%M:%S", localtime) . " [$$]: $message\n";
}
sub restart_wrap { $sigrestart=1; }
......@@ -1627,13 +1594,24 @@ sub cleanup_wrap { $sigcleanup=1; }
# This gets called if we catch a signal (TERM, etc.)
sub cleanup {
notify("Signal received, exiting\n");
notify("Cleanup signal received, exiting\n");
# now do the normal exit stuff in END {}
exit(0);
}
# This gets called if we die of 'natural causes' (exit, die, etc.)
END {
if ($ending) {
info("Recursive call to END block. Returning ...\n");
return;
}
if (!defined($handle)) {
#
# No handle, nothing interesting happening.
#
return;
}
$ending = 1;
debug("Ending stated...\n");
my $stat = $?;
$lastmail=0;
......@@ -1645,17 +1623,15 @@ END {
# Must be a child
info("Stated child exiting\n");
}
debug("Annouced. Cleaning up...\n");
# clean up Syslog
if (! $nolog) {
closelog();
}
debug("Announced. Cleaning up...\n");
if ($handle) {
debug("Unregistering w/event system...\n");
if (event_unregister($handle) == 0) {
die "Unable to unregister with event system\n";
info("Unable to unregister with event system\n");
}
else {
debug("Unregistered.\n");
}
debug("Unregistered.\n");
}
debug("Cleaned up. Bye!\n");
# Restore $? in case one of the things I called changed it
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2003-2009 University of Utah and the Flux Group.
# Copyright (c) 2003-2010 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -778,7 +778,8 @@ Phase "syslog", "Setting up syslog", sub {
DoneIfEdited($NEWSYSLOG_CONF);
AppendToFileFatal($NEWSYSLOG_CONF,
"$LOGDIR/tmcd.log 640 9 1000 * Z",
"$LOGDIR/stated.log 640 9 300 * Z",
"$LOGDIR/stated.log 640 9 1000 * Z ".
"/var/run/stated.pid 31",
"$LOGDIR/osselect.log 640 9 300 * Z",
"$LOGDIR/power.log 640 7 300 * Z",
"$LOGDIR/frisbeed.log 640 7 300 * Z",
......
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