From patchwork Sat Oct 12 18:39:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Freihofer, Adrian" X-Patchwork-Id: 1175746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::43d; helo=mail-wr1-x43d.google.com; envelope-from=swupdate+bncbaabbzv3rdwqkgqetxy4zoi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=siemens.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="s7Y9moF7"; dkim-atps=neutral Received: from mail-wr1-x43d.google.com (mail-wr1-x43d.google.com [IPv6:2a00:1450:4864:20::43d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46rDBh1TpLz9sP4 for ; Sun, 13 Oct 2019 05:39:40 +1100 (AEDT) Received: by mail-wr1-x43d.google.com with SMTP id h4sf407502wrx.15 for ; Sat, 12 Oct 2019 11:39:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1570905575; cv=pass; d=google.com; s=arc-20160816; b=bXsFVkdPUPO69vdIdrKZl3lsp6HVy5eDdANVz5+KNk47u/H5KTQDiRagYlDGGHyEoN AMT7Eo6Bpdo0avsFO1qxWnmzElBPnVebhGGrMliEv88BF3dkBElzwugbXeeLXQ2MuFm1 GUWfRC3u5jvldGNZZ73pq2f070pAY2dSSv3Ji3kugkNuizcshfXyGnSyrNWc95IMQXdH 8XV5Lx/Y/1V4TR+awiSg0Us3C3qgXS5EmePyx1eQv1Uq7OM6vbar8baffJHR1pCLsE7n /39VV5HkXX2AnFzGrOp/uS01uhKh3EEm9IYI9JhacleIJFUKKX2mN21ocbmMX1Cp2JQp NyFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:mime-version:sender:dkim-signature; bh=bJBquw3S31hq57uJWovbiEe0myBDZIoWOyDdV3AFvKo=; b=S43yzMCDqR66TmNrJK5PZnUr+UNQxytxUa8OuuzDUR2cpw+QMsBgsdnchiJ/M4k5ci ha/FwxlVv0xrEpjPfNsyVSyFgeHcjEVEp3YgFLmauH5m8Z3pHCzpHDx35sfNfBWpGyu/ ZY6zTZ6L3Sh+lhdabomLttnCi787vY037HudJfuzsQhwa8G991BH6zDl2bMZbpjdiRhz EYUg4tXZAdAo/L9FssxgcUqZ7ydpRkahtssqhdSo6XksUToNqH7hEFKAW4+TzVOGt0S7 8xE9G0Rj3rS6CYgG6xdjP7KqWQaPi6x9yapmoqA3C+S98FVPak0z5y7d/T64s9w2Uj5w pGTQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=bJBquw3S31hq57uJWovbiEe0myBDZIoWOyDdV3AFvKo=; b=s7Y9moF71pjvwfQ5NhrtwS9Yl/qTXtSXgvCUb/3lGer7JlJZiaemw2mvGi6t92e224 DR7AusxjAQ5UcSIh2pwvn0lExDeQTOKcm+tdMw9f4MmkAEot0u463Ni5ths28IlwhQ2U 5MnLNiUgr2O+uBbaEaHasFzo6YQ9anMRsXZU2GjpNiSFk+bgghaDS8dBNdr5DboJjaUV /egbscvYSM9SQblOeck6t19Nms6eYM3uJydWhLgTJ2IRCoDI+6DAFMTpLuAImYD/ZU4e F5KzHCAYI87hgA5MMMV9cbu84jSB9xAn6QMNw4rXG31HDAIcmjLwUWEqnBqwZAF518TW whHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=bJBquw3S31hq57uJWovbiEe0myBDZIoWOyDdV3AFvKo=; b=FINPpBFoESZPdWUrlz7U7pRc3rVr/7CA3FydGczP2miyLREvz+SdwMPc+GFsV8ZcoS mjMh1HF6uz3/fJ+WUVCTgBNNRFLCar3eGFN5mctC0jzWmkFxJ5tKl43BfYgS3CWlyZz+ /DSzM1dRK0u+9CCruPMXdCFYmiDZSjj9LilDrR0lctbqFyQ8q5Vfl45nNws/m2lj22G8 9NHS5KsrVhYwY04dK/RTb6YJRJSnbzXoK6JERnhTiuV5Q6B/3SZ4m09kDxUp4Rs1xLnz IuOy8sIoqIeijqJNm73JLfa+DdlqP8/sdWiQuDT+3AiU9/S63330gnyuoz7TFp84k3/e ILaw== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAWH+OMr+FP6xCGVjyknNjjmvNai/TGe2CNgSNT+7534V5aNQJ3W Lg1ksI0I8Q8UAAQ+c3K2Y70= X-Google-Smtp-Source: APXvYqwM4n6Zmu+swq9ZvouO1XFspgtrzUnIYoB/NgRE/DirijJcowM9t7mTsAOtNHYlFiXiYbLldA== X-Received: by 2002:a05:6000:12d1:: with SMTP id l17mr7539759wrx.2.1570905574859; Sat, 12 Oct 2019 11:39:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:adf:fe43:: with SMTP id m3ls3777075wrs.4.gmail; Sat, 12 Oct 2019 11:39:34 -0700 (PDT) X-Received: by 2002:a5d:52c8:: with SMTP id r8mr18987319wrv.132.1570905574410; Sat, 12 Oct 2019 11:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570905574; cv=none; d=google.com; s=arc-20160816; b=G1TlO74kHUJJWZX7fNGJMZXsUy6Mct8Kf+tqWVRGvFT8mXGhD5rVIhQ0L4MY+9mxCk dn3CPiA4vtKeFfI1H0LLvXCCRi9a6HCitwNapmYDwQuOYfWI1ZkiO92BTV2J6Wndugk4 fY/5fP/bJG4vw4nV0FXxzy0T89TH1BRm77dL62gKJ9fiOVg3x4pZriP462SNrakyiVmM c6CKytsvCSgtqKIw67ZmbZe2zVjs2QiKOvoVCIoanWvfePYe4TQOwQVXh7JZRgm5xC5E 1HDH4KJPu+5qFb0GujSxTcSV1gmej0M1i5YyO4IlNV+JmFfi5iimgRkCdgTv2QCuatQK Td8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=zGUOxu8i3MipDz3pcXqpfDGl0thlO672waoAka9s+Jw=; b=IAUsKmjCmwYNp9TmrYDWzIMIS1QahGLU0IE+uvdWGbFPCwGiHzvYurMrCBHut9E+WK C+mmHhHwTum5+tSHOAHA0Ge29R/CQNtwbGOavlkHUEztownI8eYQ6AEqXqG3184Jq6Zc 7cjfuDDYFfbCapXOnfkjPdujWBVGmpzZtyd5SeJR+PhUlwxRkpUUhPiCWK9Ny92Q7n3N HkcO67W5wf036uq6LVAJA2TG6QjyAEaYbOzO3Dj0SbiKk25U9uwXLFmRnevqrjbU8GcI r8XUx9qBebvmrLYyv0OW/fMWuvINoi6H0qYFn1AQI9VhcCwv2pXzLC+PW95Y0JRPwWwZ aalA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id x8si1027567wmk.2.2019.10.12.11.39.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Oct 2019 11:39:34 -0700 (PDT) Received-SPF: pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id x9CIdXcG018555 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 12 Oct 2019 20:39:34 +0200 Received: from dev.vm6.ccp.siemens.com ([139.22.34.187]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id x9CIdWF6010466; Sat, 12 Oct 2019 20:39:32 +0200 Received: from dev.localdomain (localhost [127.0.0.1]) by dev.vm6.ccp.siemens.com (Postfix) with ESMTP id 6DCE42353A50; Sat, 12 Oct 2019 20:39:32 +0200 (CEST) From: Adrian Freihofer To: swupdate@googlegroups.com Cc: Adrian Freihofer Subject: [swupdate] [PATCH v3 1/2] systemd generic startup Date: Sat, 12 Oct 2019 20:39:27 +0200 Message-Id: <20191012183928.27004-2-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191012183928.27004-1-adrian.freihofer@siemens.com> References: <20191012183928.27004-1-adrian.freihofer@siemens.com> X-Original-Sender: adrian.freihofer@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , If SYSTEMD_SYSTEM_UNITDIR environment variable is passed to make install, a generic set of systemd service and socket files gets installed. For most projects starting swupdate requires some logic implemented in shell scripts. Therefore swupdate is started by a new shell script /usr/lib/swupdate/swupdate.sh. swupdate.sh evaluates code snippets from /usr/lib/swupdate/conf.d and /etc/swupdate/conf.d before swupdate gets started. All modes (file, webserver, webclient) of swupdate are supported. Users or distro maintainers are enabled to add simple code snippets adding arguments for swupdate to the following three variables: - SWUPDATE_ARGS - SWUPDATE_WEBSERVER_ARGS - SWUPDATE_DOWNLOAD_ARGS This allows to provide a "just works" configuration for Mongoose if it gets compiled. This was not the case with systemd before. Signed-off-by: Adrian Freihofer --- Makefile | 20 ++++++++++++++++++++ doc/source/swupdate.rst | 29 +++++++++++++++++------------ startup/systemd/10-mongoose-args | 1 + startup/systemd/swupdate-progress.service | 9 +++++++++ startup/systemd/swupdate-usb.rules | 2 ++ startup/systemd/swupdate-usb@.service | 8 ++++++++ startup/systemd/swupdate.service | 10 ++++++++++ startup/systemd/swupdate.sh | 28 ++++++++++++++++++++++++++++ startup/systemd/swupdate.socket | 11 +++++++++++ startup/systemd/tmpfiles-swupdate.conf | 2 ++ 10 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 startup/systemd/10-mongoose-args create mode 100644 startup/systemd/swupdate-progress.service create mode 100644 startup/systemd/swupdate-usb.rules create mode 100644 startup/systemd/swupdate-usb@.service create mode 100644 startup/systemd/swupdate.service create mode 100644 startup/systemd/swupdate.sh create mode 100644 startup/systemd/swupdate.socket create mode 100644 startup/systemd/tmpfiles-swupdate.conf diff --git a/Makefile b/Makefile index d60c58e..2c23bef 100644 --- a/Makefile +++ b/Makefile @@ -461,6 +461,26 @@ install: all install -d ${DESTDIR}/usr/lib/lua/$(LUAVER); \ install -m 0755 ${lua_swupdate} $(DESTDIR)/usr/lib/lua/$(LUAVER); \ fi + if [ "x${SYSTEMD_SYSTEM_UNITDIR}" != "x" ]; then \ + install -d ${DESTDIR}${SYSTEMD_SYSTEM_UNITDIR}; \ + install -d ${DESTDIR}/usr/lib/swupdate/conf.d; \ + install -m 755 startup/systemd/swupdate.sh ${DESTDIR}/usr/lib/swupdate; \ + install -m 644 startup/systemd/swupdate-progress.service ${DESTDIR}${SYSTEMD_SYSTEM_UNITDIR}; \ + install -m 644 startup/systemd/swupdate-usb@.service ${DESTDIR}${SYSTEMD_SYSTEM_UNITDIR}; \ + install -m 644 startup/systemd/swupdate.socket ${DESTDIR}${SYSTEMD_SYSTEM_UNITDIR}; \ + ctrl_path=${CONFIG_SOCKET_CTRL_PATH}; progr_path=${CONFIG_SOCKET_PROGRESS_PATH}; \ + sed -i -e "s,@@SOCKET_CTRL_PATH@@,$${ctrl_path},g" \ + -e "s,@@SOCKET_PROGRESS_PATH@@,$${progr_path},g" \ + ${DESTDIR}${SYSTEMD_SYSTEM_UNITDIR}/swupdate.socket; \ + install -m 644 startup/systemd/swupdate.service ${DESTDIR}${SYSTEMD_SYSTEM_UNITDIR}; \ + install -d ${DESTDIR}/usr/lib/tmpfiles.d; \ + install -m 0644 startup/systemd/tmpfiles-swupdate.conf ${DESTDIR}/usr/lib/tmpfiles.d/swupdate.conf; \ + install -d ${DESTDIR}/etc/udev/rules.d; \ + install -m 0644 startup/systemd/swupdate-usb.rules ${DESTDIR}/etc/udev/rules.d/; \ + if [ "x$(CONFIG_MONGOOSE)" == "xy" ]; then \ + install -m 644 startup/systemd/10-mongoose-args ${DESTDIR}/usr/lib/swupdate/conf.d/; \ + fi; \ + fi PHONY += run-tests tests: \ diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst index 1ff08ef..0eea82b 100644 --- a/doc/source/swupdate.rst +++ b/doc/source/swupdate.rst @@ -520,22 +520,27 @@ configuration switch ``CONFIG_SYSTEMD``. If enabled, SWUpdate signals systemd about start-up completion and can make optional use of systemd's socket-based activation feature. -A sample systemd service unit file ``/etc/systemd/system/swupdate.service`` -may look like the following starting SWUpdate in suricatta daemon mode: +To install a generic set of service and socket files, pass the +`SYSTEMD_SYSTEM_UNITDIR` parameter, which points to `/lib/systemd/system` +for example, to the "make install" command. -:: +For further runtime adjustments, some shell code snippets can be added +to the `/usr/lib/swupdate/conf.d` or `/etc/swupdate/conf.d` folders. The +code snippets are processed by a full-featured shell in alphabetical order. +Files from /etc overwrite files from /usr/ with the same name. - [Unit] - Description=SWUpdate daemon - Documentation=https://github.com/sbabic/swupdate - Documentation=https://sbabic.github.io/swupdate +The purpose of these code snippets is to assign reasonable command line +parameters to swupdate. The following variables may be set: - [Service] - Type=notify - ExecStart=/usr/bin/swupdate -u '-t default -u http://localhost -i 25' +- SWUPDATE_ARGS +- SWUPDATE_WEBSERVER_ARGS +- SWUPDATE_DOWNLOAD_ARGS - [Install] - WantedBy=multi-user.target +A sample configuration file ``/usr/lib/swupdate/conf.d/10-suricatta`` +may look like the following starting SWUpdate in suricatta daemon mode: +:: + + SWUPDATE_DOWNLOAD_ARGS='-t default -u http://localhost -i 25' Started via ``systemctl start swupdate.service``, SWUpdate (re)creates its sockets on startup. For using socket-based diff --git a/startup/systemd/10-mongoose-args b/startup/systemd/10-mongoose-args new file mode 100644 index 0000000..896e66b --- /dev/null +++ b/startup/systemd/10-mongoose-args @@ -0,0 +1 @@ +SWUPDATE_WEBSERVER_ARGS="-r /www ${SWUPDATE_MONGOOSE_EXTRA_ARGS:--p 8080}" diff --git a/startup/systemd/swupdate-progress.service b/startup/systemd/swupdate-progress.service new file mode 100644 index 0000000..212d151 --- /dev/null +++ b/startup/systemd/swupdate-progress.service @@ -0,0 +1,9 @@ +[Unit] +Description=swupdate progress service +Before=swupdate.service + +[Service] +ExecStart=/usr/bin/swupdate-progress -r -w + +[Install] +WantedBy=swupdate.service diff --git a/startup/systemd/swupdate-usb.rules b/startup/systemd/swupdate-usb.rules new file mode 100644 index 0000000..7bba227 --- /dev/null +++ b/startup/systemd/swupdate-usb.rules @@ -0,0 +1,2 @@ +ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", TAG+="systemd", ENV{SYSTEMD_WANTS}+="swupdate-usb@%k.service" + diff --git a/startup/systemd/swupdate-usb@.service b/startup/systemd/swupdate-usb@.service new file mode 100644 index 0000000..eda9d15 --- /dev/null +++ b/startup/systemd/swupdate-usb@.service @@ -0,0 +1,8 @@ +[Unit] +Description=usb media swupdate service +Requires=swupdate-progress.service + +[Service] +ExecStartPre=/bin/mount /dev/%I /mnt +ExecStart=/bin/sh -c "swupdate-client -v /mnt/*.swu" +ExecStopPost=/bin/umount /mnt diff --git a/startup/systemd/swupdate.service b/startup/systemd/swupdate.service new file mode 100644 index 0000000..89fd4dd --- /dev/null +++ b/startup/systemd/swupdate.service @@ -0,0 +1,10 @@ +[Unit] +Description=SWUpdate daemon +Documentation=https://github.com/sbabic/swupdate +Documentation=https://sbabic.github.io/swupdate + +[Service] +ExecStart=/usr/lib/swupdate/swupdate.sh + +[Install] +WantedBy=multi-user.target diff --git a/startup/systemd/swupdate.sh b/startup/systemd/swupdate.sh new file mode 100644 index 0000000..d93ec85 --- /dev/null +++ b/startup/systemd/swupdate.sh @@ -0,0 +1,28 @@ +#!/bin/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_DOWNLOAD_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 + +# handle variable escaping in a simmple way. Use exec to forward open filedescriptors from systemd open. +if [ "$SWUPDATE_WEBSERVER_ARGS" != "" -a "$SWUPDATE_DOWNLOAD_ARGS" != "" ]; then + exec /usr/bin/swupdate $SWUPDATE_ARGS -w "$SWUPDATE_WEBSERVER_ARGS" -u "$SWUPDATE_DOWNLOAD_ARGS" +elif [ "$SWUPDATE_WEBSERVER_ARGS" != "" ]; then + exec /usr/bin/swupdate $SWUPDATE_ARGS -w "$SWUPDATE_WEBSERVER_ARGS" +elif [ "$SWUPDATE_DOWNLOAD_ARGS" != "" ]; then + exec /usr/bin/swupdate $SWUPDATE_ARGS -d "$SWUPDATE_DOWNLOAD_ARGS" +else + exec /usr/bin/swupdate $SWUPDATE_ARGS +fi diff --git a/startup/systemd/swupdate.socket b/startup/systemd/swupdate.socket new file mode 100644 index 0000000..aeb7310 --- /dev/null +++ b/startup/systemd/swupdate.socket @@ -0,0 +1,11 @@ +[Unit] +Description=SWUpdate socket listener +Documentation=https://github.com/sbabic/swupdate +Documentation=https://sbabic.github.io/swupdate + +[Socket] +ListenStream=@@SOCKET_CTRL_PATH@@ +ListenStream=@@SOCKET_PROGRESS_PATH@@ + +[Install] +WantedBy=sockets.target diff --git a/startup/systemd/tmpfiles-swupdate.conf b/startup/systemd/tmpfiles-swupdate.conf new file mode 100644 index 0000000..4743672 --- /dev/null +++ b/startup/systemd/tmpfiles-swupdate.conf @@ -0,0 +1,2 @@ +X /tmp/datadst +X /tmp/scripts