File:  [LON-CAPA] / doc / loncapafiles / ntpcheck.piml
Revision 1.35: download - view: text, annotated - select for diffs
Mon May 27 00:24:30 2019 UTC (4 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Support Fedora 29 and 30.
- Appropriate message if chrony in use instead of ntp (i.e., sles15).

    1: <!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN" 
    2: 	"http://lpml.sourceforge.net/DTD/piml.dtd">
    3: <!-- ntpcheck.piml -->
    4: <!-- Matthew Hall -->
    5: 
    6: <!-- $Id: ntpcheck.piml,v 1.35 2019/05/27 00:24:30 raeburn Exp $ -->
    7: 
    8: <!--
    9: 
   10: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   11: 
   12: LON-CAPA is free software; you can redistribute it and/or modify
   13: it under the terms of the GNU General Public License as published by
   14: the Free Software Foundation; either version 2 of the License, or
   15: (at your option) any later version.
   16: 
   17: LON-CAPA is distributed in the hope that it will be useful,
   18: but WITHOUT ANY WARRANTY; without even the implied warranty of
   19: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20: GNU General Public License for more details.
   21: 
   22: You should have received a copy of the GNU General Public License
   23: along with LON-CAPA; if not, write to the Free Software
   24: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25: 
   26: /home/httpd/html/adm/gpl.txt
   27: 
   28: http://www.lon-capa.org/
   29: 
   30: -->
   31: 
   32: <piml>
   33: <targetroot>/</targetroot>
   34: <files>
   35: <file>
   36: <target dist="default"></target>
   37: <perlscript mode="fg">
   38: print "Checking to be sure the Network Time Protocol is running properly.\n";
   39: if ('<DIST />' eq 'sles15') {
   40:     print "For more information on chronyd please see https://chrony.tuxfamily.org/\n";
   41: } else {
   42:     print "For more information on ntpd please see http://www.ntp.org/\n";
   43: }
   44: my $NTPD;
   45: my $name = 'ntp';
   46: my $checkcmd = 'ps -ef |grep ntp |grep -v grep |grep -v ntpcheck';
   47: my $startntpcmd;
   48: my $is_running;
   49: if (('<DIST />' eq 'fedora15')    || ('<DIST />' eq 'fedora16') ||
   50:     ('<DIST />' eq 'fedora17')    || ('<DIST />' eq 'fedora18') ||
   51:     ('<DIST />' eq 'fedora19')    || ('<DIST />' eq 'fedora20') ||
   52:     ('<DIST />' eq 'fedora21')    || ('<DIST />' eq 'fedora22') ||
   53:     ('<DIST />' eq 'fedora23')    || ('<DIST />' eq 'fedora24') ||
   54:     ('<DIST />' eq 'fedora25')    || ('<DIST />' eq 'fedora26') ||
   55:     ('<DIST />' eq 'fedora27')    || ('<DIST />' eq 'fedora28') ||
   56:     ('<DIST />' eq 'fedora29')    || ('<DIST />' eq 'fedora30') ||
   57:     ('<DIST />' eq 'centos7')     || ('<DIST />' eq 'rhes7')    ||
   58:     ('<DIST />' eq 'scientific7') || ('<DIST />' eq 'sles12')   ||
   59:     ('<DIST />' eq 'sles15')      || ('<DIST />' eq 'ubuntu18')) {
   60:     $NTPD = 'ntpd';
   61:     if ('<DIST />' eq 'ubuntu18') {
   62:         $NTPD = 'ntp';
   63:     } elsif ('<DIST />' eq 'sles15') {
   64:         $NTPD = 'chronyd';
   65:         $name = $NTPD;
   66:     }
   67:     $checkcmd = "systemctl is-enabled $NTPD.service";
   68:     $startntpcmd = "systemctl start $NTPD.service";
   69:     if (!-e "/usr/sbin/$NTPD") {
   70:         print "$name is not installed.\n";
   71:         exit;
   72:     }
   73: } else {
   74:     if (-e "/etc/init.d/ntpd") {
   75:         $NTPD = "ntpd";
   76:     } elsif (-e "/etc/init.d/xntpd") {
   77:         $NTPD = "xntpd";
   78:     } elsif (-e "/etc/init.d/ntp") {
   79:         $NTPD = "ntp"; 
   80:     } else {
   81:         print "ntp is not installed.\n";
   82:         exit;
   83:     }
   84:     $startntpcmd = "/etc/init.d/$NTPD start";
   85: }
   86: 
   87: if (open(PIPE,'-|',$checkcmd)) {
   88:     $is_running = &lt;PIPE&gt;;
   89:     chomp($is_running);
   90:     close(PIPE);
   91:     if (!$is_running) {
   92:         print "WARNING: $name is installed but is not currently running.\n";
   93:         if ($name eq 'ntp') {
   94:             print "Please verify the configuration of ntp in /etc/ntp.conf and /etc/ntp/step-tickers\n";
   95:         }
   96:         print "Start $name by executing\n $startntpcmd\n";
   97:     } else {
   98:         print "$name is installed and running\n";
   99:     }
  100: } else {
  101:     print "Could not determine $name status.\n";
  102: }
  103: 
  104: # chkconfig barfs to stderr if the target isn't set up right.
  105: if (('<DIST />' eq 'fedora15')    || ('<DIST />' eq 'fedora16') ||
  106:     ('<DIST />' eq 'fedora17')    || ('<DIST />' eq 'fedora18') ||
  107:     ('<DIST />' eq 'fedora19')    || ('<DIST />' eq 'fedora20') ||
  108:     ('<DIST />' eq 'fedora21')    || ('<DIST />' eq 'fedora22') ||
  109:     ('<DIST />' eq 'fedora23')    || ('<DIST />' eq 'fedora24') ||
  110:     ('<DIST />' eq 'fedora25')    || ('<DIST />' eq 'fedora26') ||
  111:     ('<DIST />' eq 'fedora27')    || ('<DIST />' eq 'fedora28') ||
  112:     ('<DIST />' eq 'fedora29')    || ('<DIST />' eq 'fedora30') ||
  113:     ('<DIST />' eq 'centos7')     || ('<DIST />' eq 'rhes7')    ||
  114:     ('<DIST />' eq 'scientific7') || ('<DIST />' eq 'sles12')   ||
  115:     ('<DIST />' eq 'sles15')      || ('<DIST />' eq 'ubuntu18')) {
  116:     if (!-l "/etc/systemd/system/multi-user.target.wants/$NTPD.service") {  
  117:         print "**** WARNING: $NTPD is not configured to run at boot.  To correct this run:\nsystemctl enable $NTPD.service\n";
  118:     }
  119:     exit;
  120: } else {
  121:     my $checking_bin;
  122:     my $restartchk;
  123:     if (('<DIST />' eq 'debian5') || ('<DIST />' eq 'debian6') || ('<DIST />' eq 'ubuntu6') || 
  124:         ('<DIST />' eq 'ubuntu8') || ('<DIST />' eq 'ubuntu10') || ('<DIST />' eq 'ubuntu12') || 
  125:         ('<DIST />' eq 'ubuntu14') || ('<DIST />' eq 'ubuntu16')) {
  126:         $checking_bin = '/usr/sbin/sysv-rc-conf';
  127:     } else {
  128:         $checking_bin = '/sbin/chkconfig';
  129:     }
  130:     $restartchk = `$checking_bin --list $NTPD 2>/dev/null`;
  131:     if ($restartchk eq '') {
  132:         print "**** WARNING: ntpd is either not installed or not configured to run at boot.\n";
  133:         exit;
  134:     }
  135:     if ($restartchk =~ /^error reading information on service / ||
  136:         $restartchk !~ /\d:(on|off)/) {
  137:         print "**** WARNING: Unable to check status $NTPD with $checking_bin.\n";
  138:         exit;
  139:     }
  140:     if ($restartchk !~ /\s3:on/) {
  141:         print "**** WARNING: ntpd is not set to start at runlevel 3.  To correct this run:\n$checking_bin --level 345 $NTPD on\n";
  142:         exit;
  143:     }
  144:     if ($restartchk !~ /\s5:on/) {
  145:         print "**** WARNING: ntpd is not set to start at runlevel 5.  To correct this run:\n$checking_bin --level 345 $NTPD on\n";
  146:         exit;
  147:     }
  148: }
  149: </perlscript>
  150: </file>
  151: </files>
  152: </piml>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>