Skip to content

Commit 24c199e

Browse files
authored
Merge pull request #160 from icedieler/ntp_initd
net::ntp: add sysvinit start script
2 parents 74214cb + 2120261 commit 24c199e

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

recipes/net/ntp.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
inherit: [autoconf, autotools, patch]
1+
inherit: [autoconf, autotools, patch, init]
22

33
metaEnvironment:
44
PKG_VERSION: "4.2.8p18"
@@ -51,5 +51,10 @@ buildScript: |
5151
ntp -1 ntp -1 * - - - ntpd user
5252
EOF
5353
54+
# add init script
55+
if initIsAnySysvinit; then
56+
install -D -m 0755 $<@ntp/S49ntpd.sh@> install/etc/init.d/S49ntpd.sh
57+
fi
58+
5459
packageScript: autotoolsPackageTgt
5560
provideDeps: [ "*-tgt" ]

recipes/net/ntp/S49ntpd.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
#
3+
# Starts Network Time Protocol daemon
4+
#
5+
6+
DAEMON="ntpd"
7+
PIDFILE="/var/run/$DAEMON.pid"
8+
9+
NTPD_ARGS="-4 -g -u ntp:ntp -s /var/run/ntp -c /etc/ntpd.conf -l /var/log/ntpd.log"
10+
11+
# shellcheck source=/dev/null
12+
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
13+
14+
mkdir -p /var/run/ntp && chown ntp:ntp /var/run/ntp
15+
16+
start() {
17+
printf 'Starting %s: ' "$DAEMON"
18+
# shellcheck disable=SC2086 # we need the word splitting
19+
start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/bin/$DAEMON" \
20+
-- $NTPD_ARGS -p "$PIDFILE"
21+
status=$?
22+
if [ "$status" -eq 0 ]; then
23+
echo "OK"
24+
else
25+
echo "FAIL"
26+
fi
27+
return "$status"
28+
}
29+
30+
stop() {
31+
printf 'Stopping %s: ' "$DAEMON"
32+
start-stop-daemon -K -q -p "$PIDFILE"
33+
status=$?
34+
if [ "$status" -eq 0 ]; then
35+
rm -f "$PIDFILE"
36+
echo "OK"
37+
else
38+
echo "FAIL"
39+
fi
40+
return "$status"
41+
}
42+
43+
restart() {
44+
stop
45+
sleep 1
46+
start
47+
}
48+
49+
case "$1" in
50+
start|stop|restart)
51+
"$1";;
52+
reload)
53+
# Restart, since there is no true "reload" feature.
54+
restart;;
55+
*)
56+
echo "Usage: $0 {start|stop|restart|reload}"
57+
exit 1
58+
esac

0 commit comments

Comments
 (0)