Although we generally use Keepalive to monitor AOLserver-based Web services, it will work fine to monitor any HTTP service on a Unix machine.
cd /web
tar xvf keepalive-1999.tar.gz (creates /web/keepalive)
keepalive_init procedure in /tcl/init.tcl to
add monitors analogously in the same way as the sample monitor is added, knowing
that the arguments to new_monitor are, in order:
which tells Unix to restart nsd if it should die for any reason. Thus keepalive just needs to kill the existing nsd process. The problem is that Web servers must be owned by root if they are to grab Port 80 and Keepalive can't kill a Web server unless it runs as root (a security risk). The solution at ArsDigita is to build a setuid Perl script that Keepalive can call:nsjw:34:respawn:/home/nsadmin/bin/nsd -i -c /home/nsadmin/nsd.ini
restart-aolserver
#!/usr/local/bin/perl
## Restarts an AOLserver. Takes as its only argument the name of the server to kill.
## This is a perl script because it needs to run setuid root,
## and perl has fewer security gotchas than most shells.
$ENV{'PATH'} = '/sbin:/bin';
# uncomment this stuff if you're at an installation where a server
# takes a long time to restart or keeps important state
# if (scalar(@ARGV) == 0) {
# die "Don't run this without any arguments!";
# }
$server = shift;
$< = $>; # set realuid to effective uid (root)
sub getpids {
## get the PIDs of all jobdirect servers
my $ps_output = `/usr/bin/ps -ef`;
my @pids;
foreach (split(/\n/, $ps_output)) {
next unless /^\s*\S+\s+(\d+).*nsd.*$server.ini/;
push(@pids, $1);
}
@pids;
}
@pids = &getpids;
print "Killing ", join(" ", @pids), "\n";
kill 'KILL', @pids;
I think using aolserver to keep another aolserver alive is a bit risky. Even without the RDBMS - if both your aolservers hang for the same reason then what? I would feel much more comfortable using cron and a shell script.
-- David Cotter, September 21, 2001