package/mrp: add init script and systemd unit file
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Tue, 8 Sep 2020 18:21:18 +0000 (20:21 +0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Thu, 15 Oct 2020 21:40:43 +0000 (23:40 +0200)
Add init script and systemd unit for MRP because it is using a daemon.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
package/mrp/S65mrp [new file with mode: 0644]
package/mrp/mrp.mk
package/mrp/mrp.service [new file with mode: 0644]

diff --git a/package/mrp/S65mrp b/package/mrp/S65mrp
new file mode 100644 (file)
index 0000000..0ce1f80
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# Start mrp
+#
+
+DAEMON="mrp_server"
+
+PIDFILE="/var/run/$DAEMON.pid"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/mrp_server" ] && . "/etc/default/mrp_server"
+
+start() {
+       printf "Starting mrp daemon: "
+       start-stop-daemon -S -b -q -m -p $PIDFILE \
+               -x /usr/bin/$DAEMON
+       status=$?
+       if [ "$status" -eq 0 ]; then
+               echo "OK"
+       else
+               echo "FAIL"
+       fi
+       return $status
+}
+
+stop() {
+       printf "Stopping mrp 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 $?
index 4d8a1fc92a688d4ac5e43ce205690703e4a5266e..7e31e442ce0469dfa192cbe84e288bc63e8b5d20 100644 (file)
@@ -10,4 +10,14 @@ MRP_DEPENDENCIES = libev libmnl libnl
 MRP_LICENSE = GPL-2.0
 MRP_LICENSE_FILES = LICENSE
 
+define MRP_INSTALL_INIT_SYSV
+       $(INSTALL) -m 755 -D $(MRP_PKGDIR)/S65mrp \
+               $(TARGET_DIR)/etc/init.d/S65mrp
+endef
+
+define MRP_INSTALL_INIT_SYSTEMD
+       $(INSTALL) -D -m 644 $(MRP_PKGDIR)/mrp.service \
+               $(TARGET_DIR)/usr/lib/systemd/system/mrp.service
+endef
+
 $(eval $(cmake-package))
diff --git a/package/mrp/mrp.service b/package/mrp/mrp.service
new file mode 100644 (file)
index 0000000..05006a7
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=Media Redundancy Protocol
+After=network.target
+
+[Service]
+ExecStart=/usr/bin/mrp
+Restart=always
+
+[Install]
+WantedBy=multi-user.target