package/swupdate: add basic systemd/sysv service
authorSam Voss <sam.voss@rockwellcollins.com>
Sat, 18 Apr 2020 00:31:10 +0000 (19:31 -0500)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sat, 18 Apr 2020 12:50:12 +0000 (14:50 +0200)
Signed-off-by: Sam Voss <sam.voss@rockwellcollins.com>
Signed-off-by: Matt Weber <matthew.weber@rockwellcollins.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
package/swupdate/S80swupdate [new file with mode: 0644]
package/swupdate/swupdate.mk
package/swupdate/swupdate.service [new file with mode: 0644]
package/swupdate/swupdate.sh [new file with mode: 0644]

diff --git a/package/swupdate/S80swupdate b/package/swupdate/S80swupdate
new file mode 100644 (file)
index 0000000..4421084
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+DAEMON="swupdate"
+DAEMON_WRAPPER="/usr/lib/swupdate/swupdate.sh"
+PIDFILE="/var/run/$DAEMON.pid"
+
+start() {
+       printf 'Starting %s: ' "$DAEMON"
+       start-stop-daemon -S -q -b -m -p "$PIDFILE" -x $DAEMON_WRAPPER
+       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
+               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 (does not
+               # reconfigure/restart on SIGHUP, just closes all open files).
+               restart;;
+       *)
+               echo "Usage: $0 {start|stop|restart|reload}"
+               exit 1
+esac
index 2b51edb66d950df78a1736f681a98b5c0999505c..4b19ec0f5fef80711315028c0aa10ea9732b7a8d 100644 (file)
@@ -189,4 +189,23 @@ $(error No Swupdate configuration file specified, check your BR2_PACKAGE_SWUPDAT
 endif
 endif
 
+ifeq ($(BR2_PACKAGE_SWUPDATE_INSTALL_WEBSITE),y)
+define SWUPDATE_INSTALL_COMMON
+       mkdir -p $(TARGET_DIR)/etc/swupdate/conf.d \
+               $(TARGET_DIR)/usr/lib/swupdate/conf.d
+       $(INSTALL) -D -m 755 package/swupdate/swupdate.sh \
+               $(TARGET_DIR)/usr/lib/swupdate/swupdate.sh
+endef
+define SWUPDATE_INSTALL_INIT_SYSTEMD
+       $(SWUPDATE_INSTALL_COMMON)
+       $(INSTALL) -D -m 644 package/swupdate/swupdate.service \
+               $(TARGET_DIR)/usr/lib/systemd/system/swupdate.service
+endef
+define SWUPDATE_INSTALL_INIT_SYSV
+       $(SWUPDATE_INSTALL_COMMON)
+       $(INSTALL) -D -m 755 package/swupdate/S80swupdate \
+               $(TARGET_DIR)/etc/init.d/S80swupdate
+endef
+endif
+
 $(eval $(kconfig-package))
diff --git a/package/swupdate/swupdate.service b/package/swupdate/swupdate.service
new file mode 100644 (file)
index 0000000..a3d8d19
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=SWUpdate daemon
+Documentation=https://github.com/sbabic/swupdate
+Documentation=https://sbabic.github.io/swupdate
+
+[Service]
+ExecStart=/usr/lib/swupdate/swupdate.sh
+KillMode=mixed
+
+[Install]
+WantedBy=multi-user.target
diff --git a/package/swupdate/swupdate.sh b/package/swupdate/swupdate.sh
new file mode 100644 (file)
index 0000000..17d99ef
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# Based on example script created by Adrian Freihofer
+# https://github.com/sbabic/meta-swupdate/blob/master/recipes-support/swupdate/swupdate/swupdate.sh
+
+# Override these variables in sourced script(s) located
+# in /usr/lib/swupdate/conf.d or /etc/swupdate/conf.d
+SWUPDATE_ARGS="-v ${SWUPDATE_EXTRA_ARGS}"
+SWUPDATE_WEBSERVER_ARGS=""
+SWUPDATE_SURICATTA_ARGS=""
+
+# source all files from /etc/swupdate/conf.d and /usr/lib/swupdate/conf.d/
+# A file found in /etc replaces the same file in /usr
+for f in `(test -d /usr/lib/swupdate/conf.d/ && ls -1 /usr/lib/swupdate/conf.d/; test -d /etc/swupdate/conf.d && ls -1 /etc/swupdate/conf.d) | sort -u`; do
+  if [ -f /etc/swupdate/conf.d/$f ]; then
+    . /etc/swupdate/conf.d/$f
+  else
+    . /usr/lib/swupdate/conf.d/$f
+  fi
+done
+
+if [ "$SWUPDATE_WEBSERVER_ARGS" != "" -a  "$SWUPDATE_SURICATTA_ARGS" != "" ]; then
+  exec /usr/bin/swupdate $SWUPDATE_ARGS -w "$SWUPDATE_WEBSERVER_ARGS" -u "$SWUPDATE_SURICATTA_ARGS"
+elif [ "$SWUPDATE_WEBSERVER_ARGS" != "" ]; then
+  exec /usr/bin/swupdate $SWUPDATE_ARGS -w "$SWUPDATE_WEBSERVER_ARGS"
+elif [ "$SWUPDATE_SURICATTA_ARGS" != "" ]; then
+  exec /usr/bin/swupdate $SWUPDATE_ARGS -u "$SWUPDATE_SURICATTA_ARGS"
+else
+  exec /usr/bin/swupdate $SWUPDATE_ARGS
+fi