What's the easiest way to make Busybox keep correct time?

Isaac Dunham ibid.ag at gmail.com
Mon Sep 1 05:03:26 UTC 2014


On Sun, Aug 31, 2014 at 10:45:09PM +0000, K.S. wrote:
> Isaac Dunham <ibid.ag <at> gmail.com> writes:
> 
> > Yes, it's because of the -q option; remove it if you want ntpd to run
> > as a daemon.
> 
> Thank you.  I did that and now it shows up in the process list, so I hope
> it's actually working!
> 
> > Put a line starting ntpd in the appropriate init script or
> > add an init script starting it.
> > I can't tell you what this looks like in more detail, because I have no
> > idea what init system you use.
> 
> It looks to me like all the init scripts on this system are in /etc/init.d
> and that I should just be able to create a new script in that directory
> called S95ntpd containing the following:
> 
> #!/bin/sh
> #
> # ntpd        Starts ntpd
> #
> 
> start() {
> 	echo -n "Starting ntpd: "
> 	/usr/sbin/ntpd -p north-america.pool.ntp.org
> 	echo "OK"
> }
> stop() {
> 	echo -n "Stopping ntpd: "
> 	killall ntpd
> 	echo "OK"
> }
> restart() {
> 	stop
> 	start
> }
> 
> case "$1" in
>   start)
> 	start
> 	;;
>   stop)
> 	stop
> 	;;
>   restart|reload)
> 	restart
> 	;;
>   *)
> 	echo "Usage: $0 {start|stop|restart}"
> 	exit 1
> esac
> 
> exit $?
> 
> I want to wait a few hours and make sure that ntpd is really working before
> I install that script, but does the script itself look okay?  I basically
> took another script that was already there and edited it to start ntpd.

Really, start()  should be a little more like this:

start() {
	echo -n "Starting ntpd: "
	/usr/sbin/ntpd -p north-america.pool.ntp.org && \
	echo "OK" || { echo "failed"; exit 1 }
}

And a lot of people use start-stop-daemon, probably because it can handle
various corner cases better.
But in general, that should work, even if it's not the optimal way.
You won't have more than one instance of ntpd running, for an example
of the sort of corner cases I mean...

HTH,
Isaac Dunham


More information about the busybox mailing list