home *** CD-ROM | disk | FTP | other *** search
/ ftp.heaven.net / 2015-02-04.ftp.heaven.net.tar / ftp.heaven.net / var / daemon-watcher
Text File  |  1994-09-18  |  1KB  |  50 lines

  1. #!/usr/bin/perl
  2. # From Jonathan Dasteel of DurangoNet 8/11/94
  3. # trivially edited to local environment.
  4. require 'syslog.pl';
  5. $seconds=$ARGV[0];
  6. $seconds=90 if !$seconds;
  7.  
  8. %watch = (
  9.           'named', "/usr/sbin/named.restart"
  10. #         'innd', "/etc/rc.d/rc.news",
  11. #         'routed', "/usr/sbin/routed -g -s",
  12. #         'faxd', "/etc/rc.d/rc.fax",
  13. #         'httpd', "/etc/rc.d/rc.http",
  14. #         'sendmail', "/etc/rc.d/rc.sendmail",
  15.           );
  16.  
  17. sub sendlog {
  18.     &openlog($0,'cons','user');
  19.     &syslog(@_[0],@_[1]);
  20.     &closelog();
  21. }
  22. &sendlog('info',"starting - checking processes every $seconds seconds");
  23.  
  24. fork && exit;
  25. setpgrp(0,$$);
  26.  
  27. while(1) {
  28.     # create ps array...
  29.     %ps = ();
  30.     open(PS,"ps ax|") || die "ps ax|: $!";
  31.     while(<PS>) {
  32.         /^\s*\S+\s+\S+\s+\S+\s+\S+(.*)/;
  33.         $prog=$1;
  34.         foreach(keys %watch) {
  35.             $ps{$_}=$prog if $prog=~/$_/;
  36.         }
  37.     }
  38.     close PS;
  39.     foreach( keys %watch ) {
  40.         if( !$ps{$_} ) {
  41.             &sendlog('warning', "re-launching $_");
  42.             system "$watch{$_}&";
  43.         }
  44.     }
  45.     sleep( $seconds );
  46. }
  47. sub __GNUC__ { 1; }
  48.  
  49.  
  50.