/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

  1. #! /usr/bin/perl -w
  2. # 980904 Harlan Stenn - created
  3. # vvv CHANGE THESE vvv
  4. $ps = "/bin/ps x |";
  5. $ntp_conf = "/etc/ntp.conf";
  6. $ntpd = "/usr/local/bin/xntpd";
  7. $ntpdate = "/usr/local/bin/ntpdate -b -s 10.0.0.1 10.0.0.2";
  8. # ^^^ CHANGE THESE ^^^
  9. {
  10. if (0)
  11. {
  12. }
  13. elsif ($ARGV[0] eq "start")
  14. {
  15. @pidlist = pidlist($ntpd);
  16. if (defined(@pidlist))
  17. {
  18. warn "NTP is already running\n";
  19. }
  20. else
  21. {
  22. if ( -f $ntp_conf && -x $ntpd )
  23. {
  24. system ($ntpdate);
  25. system ($ntpd." -c ".$ntp_conf);
  26. }
  27. }
  28. }
  29. elsif ($ARGV[0] eq "stop")
  30. {
  31. @pidlist = pidlist($ntpd);
  32. kill 'TERM', @pidlist if (scalar(@pidlist) > 0);
  33. }
  34. else
  35. {
  36. die "Usage: $0 {start,stop}\n";
  37. }
  38. }
  39. sub pidlist ($)
  40. {
  41. my ($target) = @_;
  42. my ($qt) = quotemeta($target);
  43. my @pids;
  44. open(PS, $ps) || die "Can't run ps: $!\n";
  45. while (<PS>)
  46. {
  47. chomp;
  48. next unless (/$qt/);
  49. print "Got <$_>\n";
  50. if (/^\s*(\d+)\s+/)
  51. {
  52. push @pids, $1;
  53. }
  54. }
  55. close(PS);
  56. return @pids;
  57. }