Commit 8ca3dbfb authored by Leigh Stoller's avatar Leigh Stoller

Minor changes to genlastlog stuff; instead of running out of crontab,

run from a testbed style daemon so that we can more easily get word
of failure.
parent 42343250
......@@ -1030,7 +1030,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
lib/GNUmakefile \
os/GNUmakefile os/split-image.sh os/imagezip/GNUmakefile \
pxe/GNUmakefile pxe/proxydhcp.restart pxe/bootinfo.restart \
security/GNUmakefile security/paperbag security/genlastlog.wrapper \
security/GNUmakefile security/paperbag security/lastlog_daemon \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/mkacct-ctrl \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
tbsetup/os_load tbsetup/os_setup tbsetup/mkprojdir tbsetup/power \
......
......@@ -152,7 +152,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
lib/GNUmakefile \
os/GNUmakefile os/split-image.sh os/imagezip/GNUmakefile \
pxe/GNUmakefile pxe/proxydhcp.restart pxe/bootinfo.restart \
security/GNUmakefile security/paperbag security/genlastlog.wrapper \
security/GNUmakefile security/paperbag security/lastlog_daemon \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/mkacct-ctrl \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
tbsetup/os_load tbsetup/os_setup tbsetup/mkprojdir tbsetup/power \
......
......@@ -37,3 +37,7 @@ if [ -x @prefix@/sbin/batch_daemon ]; then
@prefix@/sbin/batch_daemon
fi
if [ -x @prefix@/sbin/lastlog_daemon ]; then
echo -n " lastlogd"
@prefix@/sbin/lastlog_daemon
fi
......@@ -10,7 +10,7 @@ include $(OBJDIR)/Makeconf
BINS = suexec lastlogin
SCRIPTS = plasticwrap
SBINS = paperbag genlastlog genlastlog.wrapper
SBINS = paperbag genlastlog lastlog_daemon
#
# Force dependencies on the scripts so that they will be rerun through
......
......@@ -14,24 +14,28 @@
* syslogd_flags="-a 155.101.132.0/22"
*
* This program parses that file and inserts a bunch of entries into the DB.
* See the update comands below.
* See the update comands below.
*
* This program should be run from cron on a periodic basis, say twice an
* hour. Also note that there should be an entry in /etc/syslog.conf on
* the users node that sends auth.info to /var/log/logins, which should
* periodically cleaned with an entry in /etc/newsyslog.conf to keep it from
* filling up the filesystem. The /etc/crontab entry should look like this:
* The entry in users:/etc/syslog.conf to capture the syslog data coming
* from the nodes:
*
* 5,35 * * * * root /usr/testbed/sbin/genlastlog.wrapper
* auth.info /var/log/logins
*
* and the /etc/newsyslog.conf entry should look like this:
* while on each experimental node:
*
* auth.info @users.emulab.net
*
* Of course, you need to make sure /var/log/logins is cleaned periodically,
* so put an entry in /etc/newsyslog.conf:
*
* /var/log/logins 640 7 500 * Z
*
* To prevent information loss that can occurr if the log file is rolled,
* we actually read the first roll file (it is gzipped of course). This
* causes us to do some extra work, but its not too bad.
* To prevent information loss that can occurr between the primary file
* and the first roll file (logins.0.gz), the program actually reads the
* first roll file (it is gzipped of course). This causes us to do some
* extra work, but thats okay since we really do not want to lose that data.
*/
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
......@@ -89,6 +93,7 @@ main(int argc, char **argv)
gzFile *infp;
char buf[BUFSIZ], *bp;
struct hostent *he;
int errors = 0;
progname = argv[0];
......@@ -121,6 +126,7 @@ main(int argc, char **argv)
if ((infp = gzopen(buf, "r")) == NULL) {
syslog(LOG_ERR, "Opening %s: %m", buf);
errors++;
}
else {
doit(infp);
......@@ -136,6 +142,7 @@ main(int argc, char **argv)
if ((infp = gzopen(buf, "r")) == NULL) {
syslog(LOG_ERR, "Opening %s: %m", buf);
errors++;
}
else {
doit(infp);
......@@ -145,7 +152,7 @@ main(int argc, char **argv)
alarm(0);
syslog(LOG_NOTICE, "genlastlog ending");
exit(0);
exit(errors);
}
......
#!/usr/bin/perl -wT
use English;
#
# usage: genlastlog.wrapper
#
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $genlastlog = "$TB/sbin/genlastlog";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# Only root and TB Admins.
#
if ($UID && !TBAdmin($UID)) {
die("*** $0:\n".
" You must be root or a TB administrator\n");
}
#
# Run actual program. We only care about non-zero exit status, in which
# case we notify tbops.
#
if (system("$genlastlog")) {
SENDMAIL($TBOPS, "TESTBED: Genlastlog Failed",
"Please look at the syslog entries for genlastlog!");
}
exit(0);
#!/usr/bin/perl -wT
use English;
use Getopt::Std;
#
# Generate lastlog info from syslog data on users node.
#
# usage: lastlog_daemon [-d]
#
# TODO: Use "logger" instead of writing a log file.
#
sub usage()
{
print STDOUT "Usage: lastlog_daemon [-d]\n" .
"Use the -d option to prevent daemonization\n";
exit(-1);
}
my $optlist = "d";
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
# Testbed Support library
use lib "@prefix@/lib";
use libdb;
use libtestbed;
my $genlastlog = "$TB/sbin/genlastlog";
my $logfile = "$TB/log/genlastlog";
#
# Turn off line buffering on output (dots ...).
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/usr/bin:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 0) {
usage();
}
if (defined($options{"d"})) {
$debug = $options{"d"};
}
#
# Only root and TB Admins.
#
if ($UID && !TBAdmin($UID)) {
die("*** $0:\n".
" You must be root or a TB administrator\n");
}
# Go to ground.
if (! $debug) {
if (TBBackGround($logfile)) {
exit(0);
}
}
#
# And just loop.
#
while (1) {
print "Running at " . TBTimeStamp() . "\n";
if (system("$genlastlog")) {
my $exit_status = $? >> 8;
print "Exited with status $exit_status at " . TBTimeStamp() . "\n";
SENDMAIL($TBOPS, "TESTBED: Genlastlog Failed!",
"Failed with exit value $exit_status.\n".
"Please look at the syslog entries for genlastlog!");
}
sleep(60 * 15);
}
exit(0);
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