diff --git a/recipes/net/ntp.yaml b/recipes/net/ntp.yaml index a5ed87a2..9b8d73b7 100644 --- a/recipes/net/ntp.yaml +++ b/recipes/net/ntp.yaml @@ -1,4 +1,4 @@ -inherit: [autoconf, autotools, patch] +inherit: [autoconf, autotools, patch, init] metaEnvironment: PKG_VERSION: "4.2.8p18" @@ -51,5 +51,10 @@ buildScript: | ntp -1 ntp -1 * - - - ntpd user EOF + # add init script + if initIsAnySysvinit; then + install -D -m 0755 $<@ntp/S49ntpd.sh@> install/etc/init.d/S49ntpd.sh + fi + packageScript: autotoolsPackageTgt provideDeps: [ "*-tgt" ] diff --git a/recipes/net/ntp/S49ntpd.sh b/recipes/net/ntp/S49ntpd.sh new file mode 100755 index 00000000..18102a56 --- /dev/null +++ b/recipes/net/ntp/S49ntpd.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# +# Starts Network Time Protocol daemon +# + +DAEMON="ntpd" +PIDFILE="/var/run/$DAEMON.pid" + +NTPD_ARGS="-4 -g -u ntp:ntp -s /var/run/ntp -c /etc/ntpd.conf -l /var/log/ntpd.log" + +# shellcheck source=/dev/null +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" + +mkdir -p /var/run/ntp && chown ntp:ntp /var/run/ntp + +start() { + printf 'Starting %s: ' "$DAEMON" + # shellcheck disable=SC2086 # we need the word splitting + start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/bin/$DAEMON" \ + -- $NTPD_ARGS -p "$PIDFILE" + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +stop() { + printf 'Stopping %s: ' "$DAEMON" + start-stop-daemon -K -q -p "$PIDFILE" + status=$? + if [ "$status" -eq 0 ]; then + rm -f "$PIDFILE" + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +restart() { + stop + sleep 1 + start +} + +case "$1" in + start|stop|restart) + "$1";; + reload) + # Restart, since there is no true "reload" feature. + restart;; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac