Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for time sync before starting tor #2209

Merged
merged 2 commits into from Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/embassy-init.service
Expand Up @@ -2,7 +2,7 @@
Description=Embassy Init
After=network-online.target
Requires=network-online.target
Wants=avahi-daemon.service tor.service
Wants=avahi-daemon.service

[Service]
Type=oneshot
Expand Down
33 changes: 23 additions & 10 deletions backend/src/init.rs
Expand Up @@ -319,16 +319,8 @@ pub async fn init(cfg: &RpcContextConfig) -> Result<InitResult, Error> {
}
let tmp_docker = cfg.datadir().join("package-data/tmp/docker");
let tmp_docker_exists = tokio::fs::metadata(&tmp_docker).await.is_ok();
if should_rebuild || !tmp_docker_exists {
if tmp_docker_exists {
tokio::fs::remove_dir_all(&tmp_docker).await?;
}
Command::new("cp")
.arg("-ra")
.arg("/var/lib/docker")
.arg(&tmp_docker)
.invoke(crate::ErrorKind::Filesystem)
.await?;
if should_rebuild && tmp_docker_exists {
tokio::fs::remove_dir_all(&tmp_docker).await?;
}
Command::new("systemctl")
.arg("stop")
Expand Down Expand Up @@ -392,6 +384,26 @@ pub async fn init(cfg: &RpcContextConfig) -> Result<InitResult, Error> {
.await?;
tracing::info!("Enabled Docker QEMU Emulation");

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");
} else {
tracing::info!("Syncronized system clock");
}

Command::new("systemctl")
.arg("start")
.arg("tor")
.invoke(crate::ErrorKind::Tor)
.await?;

receipts
.ip_info
.set(&mut handle, crate::net::dhcp::init_ips().await?)
Expand All @@ -407,6 +419,7 @@ pub async fn init(cfg: &RpcContextConfig) -> Result<InitResult, Error> {
},
)
.await?;

receipts
.system_start_time
.set(&mut handle, time().await?)
Expand Down
2 changes: 2 additions & 0 deletions build/lib/scripts/postinst
Expand Up @@ -46,7 +46,9 @@ $SYSTEMCTL enable systemd-resolved.service
$SYSTEMCTL enable systemd-networkd-wait-online.service
$SYSTEMCTL disable wpa_supplicant.service

$SYSTEMCTL disable docker.service
$SYSTEMCTL disable postgresql.service
$SYSTEMCTL disable tor.service
$SYSTEMCTL disable bluetooth.service
$SYSTEMCTL disable hciuart.service
$SYSTEMCTL disable triggerhappy.service
Expand Down