Skip to content

Instantly share code, notes, and snippets.

@eNV25
Created May 1, 2022 14:20
Show Gist options
  • Save eNV25/393cc77734484871cae1a2ca6395f970 to your computer and use it in GitHub Desktop.
Save eNV25/393cc77734484871cae1a2ca6395f970 to your computer and use it in GitHub Desktop.
# /etc/systemd/system/timesync.service
[Unit]
Description=time sync using HTTP Date header
Wants=network-online.target network.target
After=network-online.target network.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c '{ exec {sleep}<> <(:); while ! : >/dev/tcp/time.google.com/80; do read -r -t 1 -u $$sleep; done; } 2>/dev/null; true'
ExecStart=/bin/bash -c 'timedatectl set-time "$(date +"%%Y-%%m-%%d %%H:%%M:%%S %%Z" -d"$(curl -sSI http://time.google.com | grep -i "Date: " | cut -d" " -f2-)")"'
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment