2007-03-04 01:16:24 +00:00
|
|
|
{ntp, modprobe, glibc, pwdutils, writeText, servers}:
|
2006-12-21 23:43:17 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
stateDir = "/var/lib/ntp";
|
|
|
|
|
|
|
|
ntpUser = "ntp";
|
|
|
|
|
|
|
|
config = writeText "ntp.conf" "
|
|
|
|
driftfile ${stateDir}/ntp.drift
|
|
|
|
|
|
|
|
${toString (map (server: "server " + server + "\n") servers)}
|
|
|
|
";
|
|
|
|
|
2006-12-22 19:29:18 +00:00
|
|
|
ntpFlags = "-c ${config} -u ${ntpUser}:nogroup -i ${stateDir}";
|
2006-12-22 19:23:19 +00:00
|
|
|
|
2006-12-21 23:43:17 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "ntpd";
|
|
|
|
|
|
|
|
job = "
|
|
|
|
description \"NTP daemon\"
|
|
|
|
|
2006-12-22 17:28:25 +00:00
|
|
|
start on ip-up
|
|
|
|
stop on ip-down
|
|
|
|
stop on shutdown
|
2006-12-21 23:43:17 +00:00
|
|
|
|
|
|
|
start script
|
|
|
|
|
|
|
|
if ! ${glibc}/bin/getent passwd ${ntpUser} > /dev/null; then
|
|
|
|
${pwdutils}/sbin/useradd -g nogroup -d ${stateDir} -s /noshell \\
|
|
|
|
-c 'NTP daemon user' ${ntpUser}
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${ntpUser} ${stateDir}
|
|
|
|
|
2006-12-22 19:23:19 +00:00
|
|
|
# Needed to run ntpd as an unprivileged user.
|
2007-03-04 01:16:24 +00:00
|
|
|
${modprobe}/sbin/modprobe capability
|
2006-12-22 19:23:19 +00:00
|
|
|
|
|
|
|
${ntp}/bin/ntpd -q -g ${ntpFlags}
|
2006-12-21 23:43:17 +00:00
|
|
|
|
|
|
|
end script
|
|
|
|
|
2006-12-22 19:23:19 +00:00
|
|
|
respawn ${ntp}/bin/ntpd -n ${ntpFlags}
|
2006-12-21 23:43:17 +00:00
|
|
|
";
|
|
|
|
|
|
|
|
}
|