package/chrony: rewrite start script

This patch brings package/chrony/S49chronyd in line with the start
script standards. Note that users will need to update the location of
any script config from /etc/default/chrony to /etc/default/chronyd.

One deviation from the standard remains (and thus the check-package
override): The PID file is placed in /var/run/chrony/$DAEMON.pid. This
is necessary because chronyd drops privileges, and would not be able
to delete the PID file from root-owned /var/run on shutdown.

Signed-off-by: Fiona Klute (WIWA) <fiona.klute@gmx.de>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Fiona Klute (WIWA) 2024-10-29 20:04:19 +01:00 committed by Thomas Petazzoni
parent 55d48e866e
commit 01177dcc81
4 changed files with 67 additions and 28 deletions

View File

@ -360,7 +360,7 @@ package/cfm/S65cfm lib_sysv.Indent lib_sysv.Variables
package/cgroupfs-mount/S30cgroupfs Shellcheck lib_sysv.Indent lib_sysv.Variables
package/chipmunk/0001-Fix-build-failure-on-musl.patch lib_patch.Upstream
package/chocolate-doom/0001-Remove-redundant-demoextend-definition.patch lib_patch.Upstream
package/chrony/S49chrony Shellcheck lib_sysv.Indent lib_sysv.Variables
package/chrony/S49chronyd lib_sysv.Variables
package/cmake/0001-rename-cmake-rootfile.patch lib_patch.Upstream
package/cmocka/0001-Don-t-redefine-uintptr_t.patch lib_patch.Upstream
package/collectd/0001-src-netlink.c-remove-REG_NOERROR.patch lib_patch.Upstream

View File

@ -1,26 +0,0 @@
#!/bin/sh
#
# Start chrony
[ -r /etc/default/chrony ] && . /etc/default/chrony
case "$1" in
start)
printf "Starting chrony: "
chronyd $CHRONY_ARGS && echo "OK" || echo "FAIL"
;;
stop)
printf "Stopping chrony: "
killall chronyd && echo "OK" || echo "FAIL"
;;
restart|reload)
"$0" stop
sleep 1
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

65
package/chrony/S49chronyd Normal file
View File

@ -0,0 +1,65 @@
#!/bin/sh
#
# Start chrony
DAEMON="chronyd"
# /var/run/chrony is owned by the chrony user, this allows chrony to
# delete the PID file during shutdown, long after dropping privileges.
PIDFILE="/var/run/chrony/$DAEMON.pid"
CHRONY_ARGS=""
# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
start() {
printf "Starting %s: " "$DAEMON"
# shellcheck disable=SC2086 # we need the word splitting
start-stop-daemon --start --pidfile "$PIDFILE" \
--exec "/usr/sbin/$DAEMON" \
-- $CHRONY_ARGS
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
return "$status"
}
stop() {
printf "Stopping %s: " "$DAEMON"
start-stop-daemon --stop --pidfile "$PIDFILE" \
--exec "/usr/sbin/$DAEMON"
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
while [ -f "$PIDFILE" ]; do
sleep 0.1
done
return "$status"
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

View File

@ -79,7 +79,7 @@ define CHRONY_INSTALL_TARGET_CMDS
endef
define CHRONY_INSTALL_INIT_SYSV
$(INSTALL) -D -m 755 package/chrony/S49chrony $(TARGET_DIR)/etc/init.d/S49chrony
$(INSTALL) -D -m 755 package/chrony/S49chronyd $(TARGET_DIR)/etc/init.d/S49chronyd
endef
define CHRONY_INSTALL_INIT_SYSTEMD