1 1.1 christos #!/usr/bin/perl 2 1.1.1.4 christos # 3 1.1 christos # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4 1.1 christos # 5 1.1.1.3 christos # SPDX-License-Identifier: MPL-2.0 6 1.1.1.3 christos # 7 1.1 christos # This Source Code Form is subject to the terms of the Mozilla Public 8 1.1.1.4 christos # License, v. 2.0. If a copy of the MPL was not distributed with this 9 1.1.1.2 christos # file, you can obtain one at https://mozilla.org/MPL/2.0/. 10 1.1 christos # 11 1.1 christos # See the COPYRIGHT file distributed with this work for additional 12 1.1 christos # information regarding copyright ownership. 13 1.1 christos 14 1.1 christos # A simple nanny to make sure named stays running. 15 1.1 christos 16 1.1 christos $pid_file_location = '/var/run/named.pid'; 17 1.1 christos $nameserver_location = 'localhost'; 18 1.1 christos $dig_program = 'dig'; 19 1.1 christos $named_program = 'named'; 20 1.1 christos 21 1.1 christos fork() && exit(); 22 1.1 christos 23 1.1 christos for (;;) { 24 1.1 christos $pid = 0; 25 1.1 christos open(FILE, $pid_file_location) || goto restart; 26 1.1 christos $pid = <FILE>; 27 1.1 christos close(FILE); 28 1.1 christos chomp($pid); 29 1.1 christos 30 1.1 christos $res = kill 0, $pid; 31 1.1 christos 32 1.1 christos goto restart if ($res == 0); 33 1.1 christos 34 1.1 christos $dig_command = 35 1.1 christos "$dig_program +short . \@$nameserver_location > /dev/null"; 36 1.1 christos $return = system($dig_command); 37 1.1 christos goto restart if ($return == 9); 38 1.1 christos 39 1.1 christos sleep 30; 40 1.1 christos next; 41 1.1 christos 42 1.1 christos restart: 43 1.1 christos if ($pid != 0) { 44 1.1 christos kill 15, $pid; 45 1.1 christos sleep 30; 46 1.1 christos } 47 1.1 christos system ($named_program); 48 1.1 christos sleep 120; 49 1.1 christos } 50