Add init script (sysv) support for busybox's ntpd

Submitted by Laszlo Papp on March 2, 2015, 10:12 a.m. | Patch ID: 89647

Details

Message ID 1425291126-1729-1-git-send-email-laszlo.papp@polatis.com
State New
Headers show

Commit Message

Laszlo Papp March 2, 2015, 10:12 a.m.
Signed-off-by: Laszlo Papp <laszlo.papp@polatis.com>
---
 meta/recipes-core/busybox/busybox.inc             | 12 +++--
 meta/recipes-core/busybox/busybox_1.23.1.bb       |  2 +
 meta/recipes-core/busybox/files/busybox-ntpd      | 54 +++++++++++++++++++++++
 meta/recipes-core/busybox/files/busybox-ntpd.conf |  2 +
 4 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 meta/recipes-core/busybox/files/busybox-ntpd
 create mode 100644 meta/recipes-core/busybox/files/busybox-ntpd.conf

Patch hide | download patch | download mbox

diff --git a/meta/recipes-core/busybox/busybox.inc b/meta/recipes-core/busybox/busybox.inc
index 0769d92..b33d624 100644
--- a/meta/recipes-core/busybox/busybox.inc
+++ b/meta/recipes-core/busybox/busybox.inc
@@ -19,7 +19,7 @@  export EXTRA_CFLAGS = "${CFLAGS}"
 export EXTRA_LDFLAGS = "${LDFLAGS}"
 export EXTRA_OEMAKE += "'LD=${CCLD}'"
 
-PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock"
+PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock ${PN}-ntpd"
 
 FILES_${PN}-httpd = "${sysconfdir}/init.d/busybox-httpd /srv/www"
 FILES_${PN}-syslog = "${sysconfdir}/init.d/syslog* ${sysconfdir}/syslog-startup.conf* ${sysconfdir}/syslog.conf* ${systemd_unitdir}/system/syslog.service ${sysconfdir}/default/busybox-syslog"
@@ -27,15 +27,17 @@  FILES_${PN}-mdev = "${sysconfdir}/init.d/mdev ${sysconfdir}/mdev.conf ${sysconfd
 FILES_${PN}-udhcpd = "${sysconfdir}/init.d/busybox-udhcpd"
 FILES_${PN}-udhcpc = "${sysconfdir}/udhcpc.d ${datadir}/udhcpc"
 FILES_${PN}-hwclock = "${sysconfdir}/init.d/hwclock.sh"
+FILES_${PN}-ntpd = "${sysconfdir}/init.d/busybox-ntpd ${sysconfdir}/busybox-ntpd.conf"
 
-INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock"
+INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock ${PN}-ntpd"
 
 INITSCRIPT_NAME_${PN}-httpd = "busybox-httpd"
 INITSCRIPT_NAME_${PN}-hwclock = "hwclock.sh"
 INITSCRIPT_NAME_${PN}-mdev = "mdev"
 INITSCRIPT_PARAMS_${PN}-mdev = "start 03 S ."
 INITSCRIPT_NAME_${PN}-syslog = "syslog"
-INITSCRIPT_NAME_${PN}-udhcpd = "busybox-udhcpd" 
+INITSCRIPT_NAME_${PN}-udhcpd = "busybox-udhcpd"
+INITSCRIPT_NAME_${PN}-ntpd = "busybox-ntpd"
 
 SYSTEMD_PACKAGES = "${PN}-syslog"
 SYSTEMD_SERVICE_${PN}-syslog = "busybox-syslog.service"
@@ -273,6 +275,10 @@  do_install () {
                        install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
                fi
 	fi
+    if grep "CONFIG_NTPD=y" ${B}/.config; then
+        install -m 0755 ${WORKDIR}/busybox-ntpd ${D}${sysconfdir}/init.d/
+        install -m 0644 ${WORKDIR}/busybox-ntpd.conf ${D}${sysconfdir}/
+    fi
 
     if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
         if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
diff --git a/meta/recipes-core/busybox/busybox_1.23.1.bb b/meta/recipes-core/busybox/busybox_1.23.1.bb
index 1742390..8e57381 100644
--- a/meta/recipes-core/busybox/busybox_1.23.1.bb
+++ b/meta/recipes-core/busybox/busybox_1.23.1.bb
@@ -31,6 +31,8 @@  SRC_URI = "http://www.busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
            file://recognize_connmand.patch \
            file://busybox-cross-menuconfig.patch \
            file://CVE-2014-9645_busybox_reject_module_names_with_slashes.patch \
+           file://busybox-ntpd \
+           file://busybox-ntpd.conf \
 "
 
 SRC_URI[tarball.md5sum] = "5c94d6301a964cd91619bd4d74605245"
diff --git a/meta/recipes-core/busybox/files/busybox-ntpd b/meta/recipes-core/busybox/files/busybox-ntpd
new file mode 100644
index 0000000..b318cda
--- /dev/null
+++ b/meta/recipes-core/busybox/files/busybox-ntpd
@@ -0,0 +1,54 @@ 
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides:
+# Required-Start:    $local_fs $remote_fs $network $syslog
+# Required-Stop:     $local_fs $remote_fs $network $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Small busybox ntp server
+# Description:       busybox-ntpd is a small and fast busybox ntp applet
+### END INIT INFO
+
+DAEMON=/sbin/ntpd
+NAME=ntpd
+DESC="Busybox NTP Daemon"
+source /etc/busybox-ntpd.conf
+ARGS="-p $PEER"
+
+test -f $DAEMON || exit 0
+
+set -e
+
+case "$1" in
+    start)
+        if [ -z "$PEER" ]; then
+            echo "PEER needs to be specified"
+        else
+            start-stop-daemon -S -b -n $NAME -a $DAEMON -- $ARGS
+            echo "done."
+        fi
+        ;;
+    stop)
+        echo -n "stopping $DESC: $NAME... "
+        start-stop-daemon -K -n $NAME
+        echo "done."
+        ;;
+    restart)
+        echo "restarting $DESC: $NAME... "
+        $0 stop
+        $0 start
+        echo "done."
+        ;;
+    reload)
+        echo -n "reloading $DESC: $NAME... "
+        killall -HUP $(basename ${DAEMON})
+        echo "done."
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart|reload}"
+        exit 1
+        ;;
+esac
+
+exit 0
diff --git a/meta/recipes-core/busybox/files/busybox-ntpd.conf b/meta/recipes-core/busybox/files/busybox-ntpd.conf
new file mode 100644
index 0000000..9d9255c
--- /dev/null
+++ b/meta/recipes-core/busybox/files/busybox-ntpd.conf
@@ -0,0 +1,2 @@ 
+# Specify your peer.
+# PEER=pool.ntp.org

Comments

Laszlo Papp March 2, 2015, 6:15 p.m.
On Mon, Mar 2, 2015 at 10:12 AM, Laszlo Papp <lpapp@kde.org> wrote:
> Signed-off-by: Laszlo Papp <laszlo.papp@polatis.com>
> ---
>  meta/recipes-core/busybox/busybox.inc             | 12 +++--
>  meta/recipes-core/busybox/busybox_1.23.1.bb       |  2 +
>  meta/recipes-core/busybox/files/busybox-ntpd      | 54 +++++++++++++++++++++++
>  meta/recipes-core/busybox/files/busybox-ntpd.conf |  2 +
>  4 files changed, 67 insertions(+), 3 deletions(-)
>  create mode 100644 meta/recipes-core/busybox/files/busybox-ntpd
>  create mode 100644 meta/recipes-core/busybox/files/busybox-ntpd.conf
>
> diff --git a/meta/recipes-core/busybox/busybox.inc b/meta/recipes-core/busybox/busybox.inc
> index 0769d92..b33d624 100644
> --- a/meta/recipes-core/busybox/busybox.inc
> +++ b/meta/recipes-core/busybox/busybox.inc
> @@ -19,7 +19,7 @@ export EXTRA_CFLAGS = "${CFLAGS}"
>  export EXTRA_LDFLAGS = "${LDFLAGS}"
>  export EXTRA_OEMAKE += "'LD=${CCLD}'"
>
> -PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock"
> +PACKAGES =+ "${PN}-httpd ${PN}-udhcpd ${PN}-udhcpc ${PN}-syslog ${PN}-mdev ${PN}-hwclock ${PN}-ntpd"
>
>  FILES_${PN}-httpd = "${sysconfdir}/init.d/busybox-httpd /srv/www"
>  FILES_${PN}-syslog = "${sysconfdir}/init.d/syslog* ${sysconfdir}/syslog-startup.conf* ${sysconfdir}/syslog.conf* ${systemd_unitdir}/system/syslog.service ${sysconfdir}/default/busybox-syslog"
> @@ -27,15 +27,17 @@ FILES_${PN}-mdev = "${sysconfdir}/init.d/mdev ${sysconfdir}/mdev.conf ${sysconfd
>  FILES_${PN}-udhcpd = "${sysconfdir}/init.d/busybox-udhcpd"
>  FILES_${PN}-udhcpc = "${sysconfdir}/udhcpc.d ${datadir}/udhcpc"
>  FILES_${PN}-hwclock = "${sysconfdir}/init.d/hwclock.sh"
> +FILES_${PN}-ntpd = "${sysconfdir}/init.d/busybox-ntpd ${sysconfdir}/busybox-ntpd.conf"
>
> -INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock"
> +INITSCRIPT_PACKAGES = "${PN}-httpd ${PN}-syslog ${PN}-udhcpd ${PN}-mdev ${PN}-hwclock ${PN}-ntpd"
>
>  INITSCRIPT_NAME_${PN}-httpd = "busybox-httpd"
>  INITSCRIPT_NAME_${PN}-hwclock = "hwclock.sh"
>  INITSCRIPT_NAME_${PN}-mdev = "mdev"
>  INITSCRIPT_PARAMS_${PN}-mdev = "start 03 S ."
>  INITSCRIPT_NAME_${PN}-syslog = "syslog"
> -INITSCRIPT_NAME_${PN}-udhcpd = "busybox-udhcpd"
> +INITSCRIPT_NAME_${PN}-udhcpd = "busybox-udhcpd"
> +INITSCRIPT_NAME_${PN}-ntpd = "busybox-ntpd"
>
>  SYSTEMD_PACKAGES = "${PN}-syslog"
>  SYSTEMD_SERVICE_${PN}-syslog = "busybox-syslog.service"
> @@ -273,6 +275,10 @@ do_install () {
>                         install -m 0755 ${WORKDIR}/mdev-mount.sh ${D}${sysconfdir}/mdev
>                 fi
>         fi
> +    if grep "CONFIG_NTPD=y" ${B}/.config; then
> +        install -m 0755 ${WORKDIR}/busybox-ntpd ${D}${sysconfdir}/init.d/
> +        install -m 0644 ${WORKDIR}/busybox-ntpd.conf ${D}${sysconfdir}/
> +    fi
>
>      if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
>          if grep -q "CONFIG_SYSLOGD=y" ${B}/.config; then
> diff --git a/meta/recipes-core/busybox/busybox_1.23.1.bb b/meta/recipes-core/busybox/busybox_1.23.1.bb
> index 1742390..8e57381 100644
> --- a/meta/recipes-core/busybox/busybox_1.23.1.bb
> +++ b/meta/recipes-core/busybox/busybox_1.23.1.bb
> @@ -31,6 +31,8 @@ SRC_URI = "http://www.busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
>             file://recognize_connmand.patch \
>             file://busybox-cross-menuconfig.patch \
>             file://CVE-2014-9645_busybox_reject_module_names_with_slashes.patch \
> +           file://busybox-ntpd \
> +           file://busybox-ntpd.conf \
>  "
>
>  SRC_URI[tarball.md5sum] = "5c94d6301a964cd91619bd4d74605245"
> diff --git a/meta/recipes-core/busybox/files/busybox-ntpd b/meta/recipes-core/busybox/files/busybox-ntpd
> new file mode 100644
> index 0000000..b318cda
> --- /dev/null
> +++ b/meta/recipes-core/busybox/files/busybox-ntpd
> @@ -0,0 +1,54 @@
> +#!/bin/sh
> +
> +### BEGIN INIT INFO
> +# Provides:
> +# Required-Start:    $local_fs $remote_fs $network $syslog
> +# Required-Stop:     $local_fs $remote_fs $network $syslog
> +# Default-Start:     2 3 4 5
> +# Default-Stop:      0 1 6
> +# Short-Description: Small busybox ntp server
> +# Description:       busybox-ntpd is a small and fast busybox ntp applet
> +### END INIT INFO
> +
> +DAEMON=/sbin/ntpd
> +NAME=ntpd
> +DESC="Busybox NTP Daemon"
> +source /etc/busybox-ntpd.conf
> +ARGS="-p $PEER"
> +
> +test -f $DAEMON || exit 0
> +
> +set -e
> +
> +case "$1" in
> +    start)
> +        if [ -z "$PEER" ]; then
> +            echo "PEER needs to be specified"
> +        else
> +            start-stop-daemon -S -b -n $NAME -a $DAEMON -- $ARGS
> +            echo "done."
> +        fi
> +        ;;
> +    stop)
> +        echo -n "stopping $DESC: $NAME... "
> +        start-stop-daemon -K -n $NAME
> +        echo "done."
> +        ;;
> +    restart)
> +        echo "restarting $DESC: $NAME... "
> +        $0 stop
> +        $0 start
> +        echo "done."
> +        ;;
> +    reload)
> +        echo -n "reloading $DESC: $NAME... "
> +        killall -HUP $(basename ${DAEMON})
> +        echo "done."
> +        ;;
> +    *)
> +        echo "Usage: $0 {start|stop|restart|reload}"
> +        exit 1
> +        ;;
> +esac
> +
> +exit 0
> diff --git a/meta/recipes-core/busybox/files/busybox-ntpd.conf b/meta/recipes-core/busybox/files/busybox-ntpd.conf
> new file mode 100644
> index 0000000..9d9255c
> --- /dev/null
> +++ b/meta/recipes-core/busybox/files/busybox-ntpd.conf
> @@ -0,0 +1,2 @@
> +# Specify your peer.
> +# PEER=pool.ntp.org
> --
> 2.3.0

Actually after I raised this "hackish" approach on the busybox mailing
list last year, the maintainer seems to have liked my idea to get it
supported via proper configuration:
http://lists.busybox.net/pipermail/busybox-cvs/2014-March/034533.html

Therefore, I think my change ought to modified to reflect that logic.