/contrib/ntp/scripts/rc2/local.ntpd
https://bitbucket.org/freebsd/freebsd-head/ · Perl · 64 lines · 53 code · 7 blank · 4 comment · 8 complexity · f7263980745d121405c1d71958308414 MD5 · raw file
- #! /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;
- }