Created
September 1, 2023 14:19
-
-
Save mlichvar/d2260423e2c5c3d83ec9608feaa749f1 to your computer and use it in GitHub Desktop.
Start multiprocess chrony NTP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
servers=$(nproc) | |
chronyd="/usr/sbin/chronyd" | |
trap terminate SIGINT SIGTERM | |
terminate() | |
{ | |
for p in /var/run/chrony/chronyd*.pid; do | |
pid=$(cat "$p" 2> /dev/null) | |
[[ "$pid" =~ [0-9]+ ]] && kill "$pid" | |
done | |
} | |
conf="" | |
for c in /etc/chrony.conf /etc/chrony/chrony.conf; do | |
[ -f "$c" ] && conf=$c | |
done | |
case "$("$chronyd" --version | grep -o -E '[1-9]\.[0-9]+')" in | |
1.*|2.*|3.*) | |
echo "chrony version too old to run multiple instances" | |
exit 1;; | |
4.0) opts="";; | |
4.1) opts="xleave copy";; | |
*) opts="xleave copy extfield F323";; | |
esac | |
for i in $(seq 1 "$servers"); do | |
echo "Starting server instance #$i" | |
"$chronyd" "$@" -n -x \ | |
"server 127.0.0.1 port 11123 minpoll 0 maxpoll 0 $opts" \ | |
"allow" \ | |
"cmdport 0" \ | |
"bindcmdaddress /var/run/chrony/chronyd-server$i.sock" \ | |
"pidfile /var/run/chrony/chronyd-server$i.pid" & | |
done | |
echo "Starting client instance" | |
"$chronyd" "$@" -n \ | |
"include $conf" \ | |
"port 11123" \ | |
"bindaddress 127.0.0.1" \ | |
"allow 127.0.0.1" & | |
wait | |
echo Exiting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment