nanny.pl revision dafcb997e390efa4423883dafd100c975c4095d6
21635968f7663163ce914f238fd99e40fdff07a1Tinderbox User#!/usr/bin/perl
596f89167fd3225ea0866a5dc79bdd54c7aafdb6Tinderbox User#
21635968f7663163ce914f238fd99e40fdff07a1Tinderbox User# Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2000, 2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Permission to use, copy, modify, and distribute this software for any
21635968f7663163ce914f238fd99e40fdff07a1Tinderbox User# purpose with or without fee is hereby granted, provided that the above
21635968f7663163ce914f238fd99e40fdff07a1Tinderbox User# copyright notice and this permission notice appear in all copies.
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt#
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
2baa66562a2f119edffded961d3391f87ff98ec0Ondřej Surý# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1fea816a07f0c0e9cb34816a3f8d29fb62540024Mark Andrews# PERFORMANCE OF THIS SOFTWARE.
f1740da065d4555039fe8bb53beb4153e3f94de3Mark Andrews
470af54b4ec7ab38ad10a5bd22a0a20664838c99Evan Hunt# $Id: nanny.pl,v 1.8 2004/03/05 05:14:16 marka Exp $
# A simple nanny to make sure named stays running.
$pid_file_location = '/var/run/named.pid';
$nameserver_location = 'localhost';
$dig_program = 'dig';
$named_program = 'named';
fork() && exit();
for (;;) {
$pid = 0;
open(FILE, $pid_file_location) || goto restart;
$pid = <FILE>;
close(FILE);
chomp($pid);
$ps_command = "ps -axw | grep named | grep $pid | grep -v grep |";
# ps_command MUST end in a pipe (|) character!
# Make sure there's a named on the pid we just got. Since there is no
# good way to test this, use the output from ps.
open(PIPE, $ps_command) || die($ps_command);
$line = <PIPE>;
close(PIPE);
chomp($line);
goto restart if ($line eq "");
$dig_command = "$dig_program +short . \@$nameserver_location > /dev/null";
$return = system($dig_command);
goto restart if ($return == 9);
sleep 30;
next;
restart:
if ($pid != 0) {
kill 15, $pid;
sleep 30;
}
system ($named_program);
sleep 120;
}