Blame contrib/scripts/nanny.pl

Packit Service ae04f2
#!/usr/bin/perl
Packit Service ae04f2
#
Packit Service ae04f2
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit Service ae04f2
#
Packit Service ae04f2
# This Source Code Form is subject to the terms of the Mozilla Public
Packit Service ae04f2
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service ae04f2
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit Service ae04f2
#
Packit Service ae04f2
# See the COPYRIGHT file distributed with this work for additional
Packit Service ae04f2
# information regarding copyright ownership.
Packit Service ae04f2
Packit Service ae04f2
# A simple nanny to make sure named stays running.
Packit Service ae04f2
Packit Service ae04f2
$pid_file_location = '/var/run/named.pid';
Packit Service ae04f2
$nameserver_location = 'localhost';
Packit Service ae04f2
$dig_program = 'dig';
Packit Service ae04f2
$named_program =  'named';
Packit Service ae04f2
Packit Service ae04f2
fork() && exit();
Packit Service ae04f2
Packit Service ae04f2
for (;;) {
Packit Service ae04f2
	$pid = 0;
Packit Service ae04f2
	open(FILE, $pid_file_location) || goto restart;
Packit Service ae04f2
	$pid = <FILE>;
Packit Service ae04f2
	close(FILE);
Packit Service ae04f2
	chomp($pid);
Packit Service ae04f2
Packit Service ae04f2
	$res = kill 0, $pid;
Packit Service ae04f2
Packit Service ae04f2
	goto restart if ($res == 0);
Packit Service ae04f2
Packit Service ae04f2
	$dig_command =
Packit Service ae04f2
	       "$dig_program +short . \@$nameserver_location > /dev/null";
Packit Service ae04f2
	$return = system($dig_command);
Packit Service ae04f2
	goto restart if ($return == 9);
Packit Service ae04f2
Packit Service ae04f2
	sleep 30;
Packit Service ae04f2
	next;
Packit Service ae04f2
Packit Service ae04f2
 restart:
Packit Service ae04f2
	if ($pid != 0) {
Packit Service ae04f2
		kill 15, $pid;
Packit Service ae04f2
		sleep 30;
Packit Service ae04f2
	}
Packit Service ae04f2
	system ($named_program);
Packit Service ae04f2
	sleep 120;
Packit Service ae04f2
}