Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Cron based NTPD watchdog

    Scheduled Pinned Locked Moved 2.1 Snapshot Feedback and Problems - RETIRED
    2 Posts 2 Posters 1.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      ssheikh
      last edited by

      I hacked up this small script to restart NTPD if it is found stopped.

      /* $Id$ */
      /*
          watchdog_ntpd
          written for pfSense (http://www.pfSense.com)
          Shahid Sheikh
      
          This is a quick hack to check if ntpd is running.
          If not, this restarts it.
      */
      
      require_once("service-utils.inc");
      require_once("system.inc");
      
      if (!(is_service_running("ntpd"))) {
          log_error("NTPD was found dead.");
          system_ntp_configure(true);
      }
      ?>
      
      

      saved it as /etc/watchdog_ntpd.

      chmod +x /etc/watchdog_ntpd

      Added to the config.xml in the <cron>…</cron> section:

      
                      <minute>0</minute>
                              <hour>*/3</hour>
                              <mday>*</mday>
                              <month>*</month>
                              <wday>*</wday>
                              <who>root</who>
                              <command></command>/usr/bin/nice -n20 /etc/watchdog_ntpd 
      
      

      Using the Cron package makes managing the Cron jobs easier. I prefer to use it instead of tinkering with the xml file.

      Adjust the frequency of running the check as needed. I have mine set to every 3 hours.

      Shahid

      1 Reply Last reply Reply Quote 0
      • G Offline
        ggzengel
        last edited by

        "principle of cause and effect"
        If nobody here which change the cause, we have to fight with the effect.

        Thanks for the script.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.