package/linuxptp: make initscript options configurable
authorHeiko Thiery <heiko.thiery@gmail.com>
Thu, 12 Mar 2020 19:04:34 +0000 (20:04 +0100)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sat, 14 Mar 2020 14:32:42 +0000 (15:32 +0100)
The "package/busybox/S01sysklogd" is taken as template to change the
init script of the linuxptp daemon. The init script is split two parts
because there are 2 daemons (ptp4l and phc2sys).

Let the user supply its own options in /etc/default/ptp4l and
/etc/default/phc2sys.

This patch also fixes an issue with the creation of the pid file that is
needed to properly stop the daemon again.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
Tested-by: Carlos Santos <unixmania@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
package/linuxptp/S65linuxptp [deleted file]
package/linuxptp/S65ptp4l [new file with mode: 0644]
package/linuxptp/S66phc2sys [new file with mode: 0644]
package/linuxptp/linuxptp.mk

diff --git a/package/linuxptp/S65linuxptp b/package/linuxptp/S65linuxptp
deleted file mode 100644 (file)
index 46b8921..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/sh
-#
-# Start linuxptp
-#
-
-start() {
-       printf "Starting linuxptp daemon: "
-       start-stop-daemon -S -b -q -p /var/run/linuxptp-ptp4l.pid \
-               -x /usr/sbin/ptp4l -- -f /etc/linuxptp.cfg
-       [ $? = 0 ] && echo "OK" || echo "FAIL"
-
-       printf "Starting linuxptp system clock synchronization: "
-       start-stop-daemon -S -b -q -p /var/run/linuxptp-phc2sys.pid \
-               -x /usr/sbin/phc2sys -- -s eth0 -c CLOCK_REALTIME -w -S 1.0
-       [ $? = 0 ] && echo "OK" || echo "FAIL"
-}
-
-stop() {
-       printf "Stopping linuxptp system clock synchronization: "
-       start-stop-daemon -K -q -p /var/run/linuxptp-phc2sys.pid \
-               -x /usr/sbin/phc2sys
-       echo "OK"
-
-       printf "Stopping linuxptp daemon: "
-       start-stop-daemon -K -q -p /var/run/linuxptp-ptp4l.pid \
-               -x /usr/sbin/ptp4l
-       echo "OK"
-}
-
-case "$1" in
-  start)
-       start
-       ;;
-  stop)
-       stop
-       ;;
-  restart|reload)
-       stop
-       start
-       ;;
-  *)
-       echo "Usage: $0 {start|stop|restart}"
-       exit 1
-esac
-
-exit $?
diff --git a/package/linuxptp/S65ptp4l b/package/linuxptp/S65ptp4l
new file mode 100644 (file)
index 0000000..1b9e3c9
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Start linuxptp
+#
+
+DAEMON="ptp4l"
+
+PIDFILE="/var/run/$DAEMON.pid"
+
+PTP4L_ARGS="-f /etc/linuxptp.cfg"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/ptp4l" ] && . "/etc/default/ptp4l"
+
+start() {
+       printf "Starting linuxptp daemon: "
+       start-stop-daemon -S -b -q -m -p $PIDFILE \
+               -x /usr/sbin/$DAEMON -- $PTP4L_ARGS
+       status=$?
+       if [ "$status" -eq 0 ]; then
+               echo "OK"
+       else
+               echo "FAIL"
+       fi
+       return $status
+}
+
+stop() {
+       printf "Stopping linuxptp 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
+}
+
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
+       ;;
+  restart|reload)
+       stop
+       start
+       ;;
+  *)
+       echo "Usage: $0 {start|stop|restart}"
+       exit 1
+esac
+
+exit $?
diff --git a/package/linuxptp/S66phc2sys b/package/linuxptp/S66phc2sys
new file mode 100644 (file)
index 0000000..fd1ec59
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Start linuxptp
+#
+
+DAEMON="phc2sys"
+
+PIDFILE="/var/run/$DAEMON.pid"
+
+PHC2SYS_ARGS="-a -r -S 1.0"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/phc2sys" ] && . "/etc/default/phc2sys"
+
+start() {
+       printf "Starting linuxptp system clock synchronization: "
+       start-stop-daemon -S -b -q -m -p $PIDFILE \
+               -x /usr/sbin/$DAEMON -- $PHC2SYS_ARGS
+       status=$?
+       if [ "$status" -eq 0 ]; then
+               echo "OK"
+       else
+               echo "FAIL"
+       fi
+       return $status
+}
+
+stop() {
+       printf "Stopping linuxptp system clock synchronization: "
+       start-stop-daemon -K -q -p $PIDFILE
+       status=$?
+       if [ "$status" -eq 0 ]; then
+               rm -f "$PIDFILE"
+               echo "OK"
+       else
+               echo "FAIL"
+       fi
+       return $status
+}
+
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
+       ;;
+  restart|reload)
+       stop
+       start
+       ;;
+  *)
+       echo "Usage: $0 {start|stop|restart}"
+       exit 1
+esac
+
+exit $?
index 97e4af7be73afd72172d3d72edc0cb24091fd14c..ba57396f86d2c2508a003b78e83d6e60d0fd1d21 100644 (file)
@@ -33,8 +33,10 @@ define LINUXPTP_INSTALL_TARGET_CMDS
 endef
 
 define LINUXPTP_INSTALL_INIT_SYSV
-       $(INSTALL) -m 755 -D $(LINUXPTP_PKGDIR)/S65linuxptp \
-               $(TARGET_DIR)/etc/init.d/S65linuxptp
+       $(INSTALL) -m 755 -D $(LINUXPTP_PKGDIR)/S65ptp4l \
+               $(TARGET_DIR)/etc/init.d/S65ptp4l
+       $(INSTALL) -m 755 -D $(LINUXPTP_PKGDIR)/S66phc2sys \
+               $(TARGET_DIR)/etc/init.d/S66phc2sys
 endef
 
 define LINUXPTP_INSTALL_INIT_SYSTEMD