summaryrefslogtreecommitdiffstats
path: root/sbin/init.d/ntp
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/init.d/ntp')
-rwxr-xr-xsbin/init.d/ntp56
1 files changed, 56 insertions, 0 deletions
diff --git a/sbin/init.d/ntp b/sbin/init.d/ntp
new file mode 100755
index 0000000..3d18789
--- /dev/null
+++ b/sbin/init.d/ntp
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+. `dirname $0`/functions
+
+option config standard_option /etc/ntp/ntp.conf
+option keys standard_option /etc/ntp/ntp.keys
+option pidfile reserved_option /var/run/ntp.pid
+option hard_sync boolean_option
+option force_sync boolean_option
+option sync_servers long_option
+
+option procname reserved_option ntpd
+option bin reserved_option /usr/sbin/ntpd
+option cmdline reserved_option '$bin -c $opt_config -p $pidfile -k $opt_keys'
+
+# assign values after all the options have been read
+function fct_end_section {
+ if [ -z "$opt_sync_servers" ]; then
+ valueof $opt_config server > /dev/null
+ opt_sync_servers=$REPLY
+ fi
+}
+
+# perform a forced synchronisation before starting the daemon
+function fct_pre_start {
+ local driftfile
+
+ valueof $opt_config driftfile > /dev/null 2>&1 ; driftfile=$REPLY
+ if [ -n "$driftfile" -a ! -e "${driftfile%/*}" ] ; then
+ mkdir -p ${driftfile%/*}
+ fi
+ if [ "$opt_force_sync" = "1" -a "$opt_sync_servers" ]; then
+ ntpdate -u -t 2 $opt_sync_servers
+ fi
+ if [ "$opt_hardsync" = "1" ]; then
+ /sbin/hwclock -w --noadjfile --localtime
+ fi
+}
+
+# perform a forced synchronisation before stopping the daemon
+function fct_pre_stop {
+ if [ "$opt_hardsync" = "1" ]; then
+ /sbin/hwclock -w --noadjfile --localtime
+ fi
+}
+
+# execute a forced resynchronisation to sync servers
+function do_update {
+ if [ "$opt_sync_servers" ]; then
+ ntpdate -t 2 -u $opt_sync_servers
+ /sbin/hwclock -w --noadjfile --localtime
+ fi
+}
+
+load_config
+