mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
wait for time sync up to 60s
This commit is contained in:
committed by
Aiden McClelland
parent
fdf473016b
commit
eeb557860e
@@ -1,8 +1,8 @@
|
||||
[Unit]
|
||||
Description=Embassy Init
|
||||
After=network.target ntp.service
|
||||
After=network.target
|
||||
Requires=network.target
|
||||
Wants=avahi-daemon.service nginx.service tor.service ntp.service
|
||||
Wants=avahi-daemon.service nginx.service tor.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::context::rpc::RpcContextConfig;
|
||||
@@ -8,6 +10,19 @@ use crate::Error;
|
||||
|
||||
pub const SYSTEM_REBUILD_PATH: &str = "/embassy-os/system-rebuild";
|
||||
|
||||
pub async fn check_time_is_synchronized() -> Result<bool, Error> {
|
||||
Ok(String::from_utf8(
|
||||
Command::new("timedatectl")
|
||||
.arg("show")
|
||||
.arg("-p")
|
||||
.arg("NTPSynchronized")
|
||||
.invoke(crate::ErrorKind::Unknown)
|
||||
.await?,
|
||||
)?
|
||||
.trim()
|
||||
== "NTPSynchronized=yes")
|
||||
}
|
||||
|
||||
pub async fn init(cfg: &RpcContextConfig, product_key: &str) -> Result<(), Error> {
|
||||
let should_rebuild = tokio::fs::metadata(SYSTEM_REBUILD_PATH).await.is_ok();
|
||||
let secret_store = cfg.secret_store().await?;
|
||||
@@ -100,6 +115,18 @@ pub async fn init(cfg: &RpcContextConfig, product_key: &str) -> Result<(), Error
|
||||
};
|
||||
info.save(&mut handle).await?;
|
||||
|
||||
let mut warn_time_not_synced = true;
|
||||
for _ in 0..60 {
|
||||
if check_time_is_synchronized().await? {
|
||||
warn_time_not_synced = false;
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
if warn_time_not_synced {
|
||||
tracing::warn!("Timed out waiting for system time to synchronize");
|
||||
}
|
||||
|
||||
crate::version::init(&mut handle).await?;
|
||||
|
||||
if should_rebuild {
|
||||
|
||||
@@ -37,7 +37,6 @@ apt-get install -y \
|
||||
ecryptfs-utils \
|
||||
cifs-utils \
|
||||
samba-common-bin \
|
||||
ntp \
|
||||
network-manager \
|
||||
vim \
|
||||
jq \
|
||||
@@ -90,9 +89,9 @@ rm -rf /var/lib/tor/*
|
||||
raspi-config nonint enable_overlayfs
|
||||
|
||||
# create a copy of the cmdline *without* the quirk string, so that it can be easily amended
|
||||
sudo sed -i 's/usb-storage.quirks=152d:0562:u,14cd:121c:u,0781:cfcb:u //g' /boot/cmdline.txt
|
||||
sudo cp /boot/cmdline.txt /boot/cmdline.txt.orig
|
||||
sudo sed -i 's/^/usb-storage.quirks=152d:0562:u,14cd:121c:u,0781:cfcb:u /g' /boot/cmdline.txt
|
||||
sed -i 's/usb-storage.quirks=152d:0562:u,14cd:121c:u,0781:cfcb:u //g' /boot/cmdline.txt
|
||||
cp /boot/cmdline.txt /boot/cmdline.txt.orig
|
||||
sed -i 's/^/usb-storage.quirks=152d:0562:u,14cd:121c:u,0781:cfcb:u /g' /boot/cmdline.txt
|
||||
|
||||
systemctl disable initialization.service
|
||||
sudo systemctl restart NetworkManager
|
||||
|
||||
Reference in New Issue
Block a user