mirror of
https://github.com/webmin/webmin.git
synced 2026-09-21 13:00:38 +01:00
Finalize support for systems usingsystemd-timesyncd and chronyd
This commit is contained in:
@@ -52,6 +52,35 @@ if ($in{'action'} eq $text{'action_sync'}) {
|
||||
} elsif ($in{'action'} eq $text{'index_sync'} || $in{'mode'} eq 'ntp') {
|
||||
# Sync with a time server
|
||||
$access{'ntp'} || &error($text{'acl_nontp'});
|
||||
# Save service status
|
||||
if (defined($in{'sync_service_name'}) &&
|
||||
defined($in{'sync_service_status'})) {
|
||||
my $service_name = $in{'sync_service_name'};
|
||||
if ($service_name !~ /^(chronyd|systemd-timesyncd)$/) {
|
||||
&error(&text('error_serviceunknown', &html_escape($service_name)));
|
||||
}
|
||||
my $service_status = int($in{'sync_service_status'});
|
||||
&foreign_require('init');
|
||||
if ($service_status == 2) {
|
||||
# Enable service on boot
|
||||
&init::enable_at_boot($service_name);
|
||||
# Start service
|
||||
&init::restart_action($service_name);
|
||||
}
|
||||
if ($service_status == 1) {
|
||||
# Disable service on boot
|
||||
&init::disable_at_boot($service_name);
|
||||
# Start service
|
||||
&init::restart_action($service_name);
|
||||
}
|
||||
if ($service_status == 0) {
|
||||
# Disable service on boot
|
||||
&init::disable_at_boot($service_name);
|
||||
# Stop service
|
||||
&init::stop_action($service_name);
|
||||
}
|
||||
}
|
||||
# Run sync
|
||||
$in{'timeserver'} =~ /\S/ || &error($text{'error_etimeserver'});
|
||||
$err = &sync_time($in{'timeserver'}, $in{'hardware'});
|
||||
&error("<pre>".&html_escape($err)."</pre>") if ($err);
|
||||
|
||||
@@ -162,15 +162,55 @@ if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } &
|
||||
print &ui_hidden("mode", "ntp");
|
||||
print &ui_table_start(&hlink($text{'index_timeserver'}, "timeserver"),
|
||||
"width=100%", 2, [ "width=30%" ]);
|
||||
|
||||
print &ui_table_row($text{'index_addresses'},
|
||||
&ui_textbox("timeserver", $config{'timeserver'}, 60));
|
||||
|
||||
# Show hardware time checkbox
|
||||
if ($support_hwtime) {
|
||||
print &ui_table_row(" ",
|
||||
&ui_checkbox("hardware", 1, $text{'index_hardware2'},
|
||||
$config{'timeserver_hardware'}));
|
||||
my $ntp_support;
|
||||
if (&has_command("ntpdate") || &has_command("sntp")) {
|
||||
$ntp_support = 1;
|
||||
print &ui_table_row($text{'index_addresses'},
|
||||
&ui_textbox("timeserver", $config{'timeserver'}, 60));
|
||||
# Show hardware time checkbox
|
||||
if ($support_hwtime) {
|
||||
print &ui_table_row(" ",
|
||||
&ui_checkbox("hardware", 1, $text{'index_hardware2'},
|
||||
$config{'timeserver_hardware'}));
|
||||
}
|
||||
}
|
||||
if (&foreign_require('init') && &init::action_status('chronyd') > 0 && &has_command("chronyc")) {
|
||||
my $chronyd_running = &init::status_action('chronyd');
|
||||
my $chronyd_run_atboot = &init::action_status('chronyd');
|
||||
my $ui_hiddens = &ui_hidden("sync_service_name", "chronyd");
|
||||
$ui_hiddens .= &ui_hidden("timeserver", $config{'timeserver'})
|
||||
if (!$ntp_support);
|
||||
print &ui_table_row(&text('index_tabsync2', 'chronyd'),
|
||||
$ui_hiddens.
|
||||
&ui_radio("sync_service_status",
|
||||
(($chronyd_run_atboot == 2 && $chronyd_running) ? 2 :
|
||||
($chronyd_run_atboot < 2 && $chronyd_running) ? 1 : 0),
|
||||
[ [ 2, $text{'index_serviceonboot'} ], [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
|
||||
# Show hardware time checkbox
|
||||
if ($support_hwtime) {
|
||||
print &ui_table_row(" ",
|
||||
" ".&ui_checkbox("hardware", 1, $text{'index_hardware2'},
|
||||
$config{'timeserver_hardware'}));
|
||||
}
|
||||
}
|
||||
if (&foreign_require('init') && &init::action_status('systemd-timesyncd') > 0) {
|
||||
my $systemd_timesyncd_running = &init::status_action('systemd-timesyncd');
|
||||
my $systemd_timesyncd_run_atboot = &init::action_status('systemd-timesyncd');
|
||||
my $ui_hiddens = &ui_hidden("sync_service_name", "systemd-timesyncd");
|
||||
$ui_hiddens .= &ui_hidden("timeserver", $config{'timeserver'})
|
||||
if (!$ntp_support);
|
||||
print &ui_table_row(&text('index_tabsync2', 'systemd-timesyncd'),
|
||||
$ui_hiddens.
|
||||
&ui_radio("sync_service_status",
|
||||
(($systemd_timesyncd_run_atboot == 2 && $systemd_timesyncd_running) ? 2 :
|
||||
($systemd_timesyncd_run_atboot < 2 && $systemd_timesyncd_running) ? 1 : 0),
|
||||
[ [ 2, $text{'index_serviceonboot'} ], [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
|
||||
# Show hardware time checkbox
|
||||
if ($support_hwtime) {
|
||||
print &ui_table_row(" ",
|
||||
" ".&ui_checkbox("hardware", 1, $text{'index_hardware2'},
|
||||
$config{'timeserver_hardware'}));
|
||||
}
|
||||
}
|
||||
|
||||
# Show boot-time checkbox
|
||||
|
||||
@@ -5,6 +5,7 @@ index_zone=Timezone
|
||||
index_eformat=Unrecognized <tt>hwclock</tt> output format
|
||||
index_sched=Synchronize on schedule?
|
||||
index_schedyes=Yes, at times below ..
|
||||
index_serviceonboot=Yes, and start at boot
|
||||
index_sync=Sync and Apply
|
||||
index_hardware2=Set hardware time too
|
||||
index_boot=Synchronize when Webmin starts?
|
||||
@@ -14,6 +15,7 @@ index_ehwclock=$1 failed : $2
|
||||
index_tabtime=Set time
|
||||
index_tabzone=Change timezone
|
||||
index_tabsync=Time server sync
|
||||
index_tabsync2=Run system <tt>$1</tt> service for synchronization
|
||||
index_desctime=This form is for changing the system's current time, which is used by all running processes. On operating systems that have a separate hardware clock, it can be used to set that too.
|
||||
index_desczone=This form allows you to set the system's default time zone, which is used to convert the system time to a human-readable format and offset.
|
||||
index_descsync=This form is for configuring the system to automatically synchronize the time with a remote server. Synchronization will be done using the Unix <tt>time</tt> protocol or NTP, depending on which commands are installed and what the remote system supports.
|
||||
@@ -54,6 +56,7 @@ error_sync=Can't sync with system time : $1
|
||||
error_ediff=Time server different with local time is too large : $1 days
|
||||
error_entp=NTP time synchronization failed : $1
|
||||
error_etimeserver=No time servers to sync with entered
|
||||
error_serviceunknown=Unknown service : $1
|
||||
|
||||
log_set_date=Set system time to $1
|
||||
log_set_hwclock=Set hardware clock to $1
|
||||
|
||||
@@ -48,8 +48,7 @@ if (&has_command("ntpdate")) {
|
||||
elsif (&has_command("sntp")) {
|
||||
$out = &backquote_logged("sntp -s $servs 2>&1");
|
||||
}
|
||||
elsif (&has_command("chronyc")) {
|
||||
&foreign_require('init');
|
||||
elsif (&foreign_require('init') && &init::action_status('chronyd') > 0 && &has_command("chronyc")) {
|
||||
my $chronyd_running = &init::status_action('chronyd');
|
||||
$out = &backquote_logged("systemctl restart chronyd 2>&1");
|
||||
$out .= &backquote_logged("chronyc makestep 2>&1");
|
||||
|
||||
Reference in New Issue
Block a user