diff options
Diffstat (limited to 'contrib/ntp/scripts/rc2/local.ntpd')
-rw-r--r-- | contrib/ntp/scripts/rc2/local.ntpd | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/ntp/scripts/rc2/local.ntpd b/contrib/ntp/scripts/rc2/local.ntpd new file mode 100644 index 0000000..ba53e05 --- /dev/null +++ b/contrib/ntp/scripts/rc2/local.ntpd @@ -0,0 +1,64 @@ +#! /usr/bin/perl -w +# 980904 Harlan Stenn - created + +# vvv CHANGE THESE vvv + +$ps = "/bin/ps x |"; + +$ntp_conf = "/etc/ntp.conf"; +$ntpd = "/usr/local/bin/xntpd"; +$ntpdate = "/usr/local/bin/ntpdate -b -s 10.0.0.1 10.0.0.2"; + +# ^^^ CHANGE THESE ^^^ + +{ + if (0) + { + } + elsif ($ARGV[0] eq "start") + { + @pidlist = pidlist($ntpd); + if (defined(@pidlist)) + { + warn "NTP is already running\n"; + } + else + { + if ( -f $ntp_conf && -x $ntpd ) + { + system ($ntpdate); + system ($ntpd." -c ".$ntp_conf); + } + } + } + elsif ($ARGV[0] eq "stop") + { + @pidlist = pidlist($ntpd); + kill 'TERM', @pidlist if (scalar(@pidlist) > 0); + } + else + { + die "Usage: $0 {start,stop}\n"; + } +} + +sub pidlist ($) + { + my ($target) = @_; + my ($qt) = quotemeta($target); + my @pids; + + open(PS, $ps) || die "Can't run ps: $!\n"; + while (<PS>) + { + chomp; + next unless (/$qt/); + print "Got <$_>\n"; + if (/^\s*(\d+)\s+/) + { + push @pids, $1; + } + } + close(PS); + return @pids; + } |