Merge pull request #1915 from bergware/master

NTP enhancements
This commit is contained in:
tom mortensen
2024-11-20 10:20:10 -08:00
committed by GitHub
5 changed files with 42 additions and 15 deletions

View File

@@ -2,7 +2,8 @@ Menu="Dashboard"
Nchan="wg_poller,update_1,update_2,update_3,ups_status:stop,vm_dashusage"
---
<?PHP
/* Copyright 2005-2023, Lime Technology * Copyright 2012-2023, Bergware International.
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -1539,7 +1540,7 @@ vmdashusage.on('message', function(msg){
var data = JSON.parse(msg);
for (const [vm, vmdata] of Object.entries(data)) {
for (const [displayitem, value] of Object.entries(vmdata)) {
$('#vmmetrics-'+displayitem + '-' + vm ).html(value);
$('#vmmetrics-'+displayitem + '-' + vm ).html(value);
}
}
});

View File

@@ -59,6 +59,14 @@ _(Use NTP)_:
:use_ntp_help:
_(NTP interval)_:
: <select name="display_ntppoll">
<?=mk_option(_var($display,'ntppoll'), "", _('Default'))?>
<?=mk_option(_var($display,'ntppoll'), "8", _('Slow'))?>
<?=mk_option(_var($display,'ntppoll'), "5", _('Medium'))?>
<?=mk_option(_var($display,'ntppoll'), "3", _('Fast'))?>
</select><span class="ntp orange-text">_(Use DEFAULT setting when public NTP servers are defined)_</span>
_(NTP server)_ 1:
: <input type="text" name="NTP_SERVER1" maxlength="40" class="narrow" value="<?=htmlspecialchars($var['NTP_SERVER1'])?>">
@@ -107,12 +115,14 @@ function presetTime(form) {
function checkDateTimeSettings(form) {
if (form.USE_NTP.value=="yes") {
form.newDateTime.disabled=true;
form.display_ntppoll.disabled=false;
form.NTP_SERVER1.disabled=false;
form.NTP_SERVER2.disabled=false;
form.NTP_SERVER3.disabled=false;
form.NTP_SERVER4.disabled=false;
} else {
form.newDateTime.disabled=false;
form.display_ntppoll.disabled=true;
form.NTP_SERVER1.disabled=true;
form.NTP_SERVER2.disabled=true;
form.NTP_SERVER3.disabled=true;

View File

@@ -21,8 +21,11 @@ require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php";
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
if (isset($_POST['ntp'])) {
$ntp = exec("ntpq -pn|awk '{if (NR>3 && $2!=\".INIT.\") c++} END {print c}'");
die($ntp ? sprintf(_('Clock synchronized with %s NTP server'.($ntp==1?'':'s')),$ntp) : _('Clock is unsynchronized with no NTP servers'));
if (exec("pgrep -cf /usr/sbin/ntpd")) {
$ntp = exec("ntpq -pn|awk '$1~/^\*/{print $9;exit}'");
die($ntp ? sprintf(_('Clock is synchronized using NTP, time offset: %s ms'),abs($ntp)) : _('Clock is unsynchronized with no NTP servers'));
}
die(_('Clock is unsynchronized, free-running clock'));
}
if ($_POST['docker']) {
@@ -164,12 +167,10 @@ if ($_POST['vms']) {
echo "\0";
echo "<tr title='' class='useupdated'><td>";
if ($vmusage == "Y") {
foreach ($vmusagehtml as $vmhtml) {
echo $vmhtml;
}
if (!count($vmusagehtml)) echo "<span id='no_usagevms'><br> "._('No running virtual machines')."<br></span>";
if ($running < 1 && count($vmusagehtml)) echo "<span id='no_usagevms'><br>". _('No running virtual machines')."<br></span>";
if ($vmusage=='Y') {
foreach ($vmusagehtml as $vmhtml) echo $vmhtml;
if (!count($vmusagehtml)) echo "<span id='no_usagevms'><br> "._('No running virtual machines')."<br></span>";
if ($running<1 && count($vmusagehtml)) echo "<span id='no_usagevms'><br>". _('No running virtual machines')."<br></span>";
echo "</td></tr>";
}
}

View File

@@ -0,0 +1 @@
span.ntp{margin-left:40px}

View File

@@ -13,6 +13,7 @@ NTPD="/usr/sbin/ntpd"
OPTIONS="-g -u ntp:ntp"
CONF="/etc/ntp.conf"
IDENT="/boot/config/ident.cfg"
CONFIG="/boot/config/plugins/dynamix/dynamix.cfg"
# run & log functions
. /etc/rc.d/rc.runlog
@@ -38,11 +39,24 @@ ntpd_build(){
echo "interface listen $NET" >>$CONF
done
fi
# add configured NTP servers
[[ -n $NTP_SERVER1 ]] && echo "server $NTP_SERVER1 iburst" >>$CONF
[[ -n $NTP_SERVER2 ]] && echo "server $NTP_SERVER2 iburst" >>$CONF
[[ -n $NTP_SERVER3 ]] && echo "server $NTP_SERVER3 iburst" >>$CONF
[[ -n $NTP_SERVER4 ]] && echo "server $NTP_SERVER4 iburst" >>$CONF
# ntp poll interval may be adjusted to predefined values
if [[ -f $CONFIG ]]; then
NTP_POLL=$(grep -Po '^ntppoll="\K[^"]+' $CONFIG)
if [[ -n $NTP_POLL ]]; then
MINPOLL="minpoll $NTP_POLL"
MAXPOLL="maxpoll $NTP_POLL"
fi
fi
# add configured ntp servers or pools
for n in {1..4}; do
NTP="NTP_SERVER$n"
if [[ -n ${!NTP} ]]; then
# use either server or pool peers depending on remote ntp name
# pools use a round-robin mechanism to get a server out of the pool
[[ ${!NTP} =~ "pool" ]] && PEER=pool || PEER=server
echo "$PEER ${!NTP} iburst $MINPOLL $MAXPOLL" >>$CONF
fi
done
}
ntpd_start(){