home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.heaven.net
/
2015-02-04.ftp.heaven.net.tar
/
ftp.heaven.net
/
var
/
daemon-watcher
Wrap
Text File
|
1994-09-18
|
1KB
|
50 lines
#!/usr/bin/perl
# From Jonathan Dasteel of DurangoNet 8/11/94
# trivially edited to local environment.
require 'syslog.pl';
$seconds=$ARGV[0];
$seconds=90 if !$seconds;
%watch = (
'named', "/usr/sbin/named.restart"
# 'innd', "/etc/rc.d/rc.news",
# 'routed', "/usr/sbin/routed -g -s",
# 'faxd', "/etc/rc.d/rc.fax",
# 'httpd', "/etc/rc.d/rc.http",
# 'sendmail', "/etc/rc.d/rc.sendmail",
);
sub sendlog {
&openlog($0,'cons','user');
&syslog(@_[0],@_[1]);
&closelog();
}
&sendlog('info',"starting - checking processes every $seconds seconds");
fork && exit;
setpgrp(0,$$);
while(1) {
# create ps array...
%ps = ();
open(PS,"ps ax|") || die "ps ax|: $!";
while(<PS>) {
/^\s*\S+\s+\S+\s+\S+\s+\S+(.*)/;
$prog=$1;
foreach(keys %watch) {
$ps{$_}=$prog if $prog=~/$_/;
}
}
close PS;
foreach( keys %watch ) {
if( !$ps{$_} ) {
&sendlog('warning', "re-launching $_");
system "$watch{$_}&";
}
}
sleep( $seconds );
}
sub __GNUC__ { 1; }