From patchwork Fri Oct 11 15:27:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Freihofer, Adrian" X-Patchwork-Id: 1175283 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::53d; helo=mail-ed1-x53d.google.com; envelope-from=swupdate+bncbaabbin7qlwqkgqec5iztoy@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="AfcMc0ok"; dkim-atps=neutral Received: from mail-ed1-x53d.google.com (mail-ed1-x53d.google.com [IPv6:2a00:1450:4864:20::53d]) (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 46qX0m50pvz9sPk for ; Sat, 12 Oct 2019 02:28:39 +1100 (AEDT) Received: by mail-ed1-x53d.google.com with SMTP id s3sf5982702edr.15 for ; Fri, 11 Oct 2019 08:28:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1570807714; cv=pass; d=google.com; s=arc-20160816; b=yxH2ApASUIVoFI1vURBAWJWbJkJMnG3xxG8ig755DT9U/4mg4+JJewW0mHV+UsRxYk e9IvdeQgVTTGXUes4A/I+uV7is4QmFPciAE1QzukjXrs/2EqzztFZpata94+DGWWngCe PWUngos4XZZf8dl7ZwRB4JnlVY9+3J+rrz3To0BWBYVxDA6GdEstUwkM2snET39JK0uA 15n/8HyFjqWPZefZgAomsMbIaPc/NiDdeDc4Fsduw0JzPDR4hvxZzxvxsasDUqzc7kKB Jghc4JzRnwZulvg9EKVWaptzwEq0WwChYZf+ze6sCSG8Nc9u97Si4ptRsBJkifyb1fzx kWqw== 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=jCO7acju5hZJBRDtexDoa0PboH11vTrM7XTiZkpZTYg=; b=oatvUfbMHo17GVUqr2Gyor29pvS8NoTglhFB0cFDFebM9b0G9nqRz8udy3tSELxwFs HFk2myfMqgNAEurLP+oMcGEbQesK2e5Ja21kio/K3nLv/JbCTDo91dhvjN1ISr5Dl8BF chkGovryeD7cwTkw7zMJfbZ03v7ddSWPmQt0nLVfNCyxfR2Hyne/uoJYzj69wcWbZisp XA83IIOevo2vXw3+qQPFgoYqOPm55wxPkGsCSDu3sl52YvoFn3JkgaUgoVcMS7S56W4A 4aeeuInA4h/V5WoH3d4e4v2fBsBUkWhccYNcxaXBFrhaVwHOogEgqEXPnh+OF1HBKXc0 uxTA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.28 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=jCO7acju5hZJBRDtexDoa0PboH11vTrM7XTiZkpZTYg=; b=AfcMc0okeeN2eSwmNDiOUxaTfQbmKTQlBGFje8r+WTPm2gm6f3+8ogkyMDsP/LGRKK KFoHvAC18HS52YqzXWkym2sE/7p6Iyrz/U+KSgBOWmFQnkAzj8ePUf/m4nyuCzM6A1IH xiHDj5q0yg6yPdCAalxbOeRY8bBPStuil2hUuPcCWy3x5CTkmmXcWnEgOHQinuVKj1ZH 25wxyPo4QJYB5yOcfaT/jlDAKs4xNwpSjxjznedV+lSkqQYNBssV4VTTVf6q8vME3qI5 VKQu/kj1eL8vT+sxhuwMu0At6k2/qOYosrlo0MhEh7C5I9PSf5Jb1qp0cLRRf5s9Oaxq VOpw== 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=jCO7acju5hZJBRDtexDoa0PboH11vTrM7XTiZkpZTYg=; b=OwoAqtfAegehLhxsBWhnXTjh/j5rXzi311c0AE929h6EA4+U5PulN+gQLHnNptcTcv NHmJdo+rt5+I/haTAddWhQGtOw8AhUUgFkttGKKeav0LxLm4LVKEH4MHZ20gmidpaW0k CtVQXgsC9cQbZFU1eKAVhRbLPTAyCR0gOSEK86yot/UZ3LqxDlQtGJDrVrL9QNzKUKss drlG8k0NBBYU3NUSEdbpXW7x958X1eszo20eDoMtvwVNUAoOocEAu+226K1ZE2syeudu gpgVXluQj8Us8NGp36Qb05QNuhTdKjBfpXl9AZljOiPHcqXEeaK9oVtZQmSrBhzfmGaB A3fw== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAVXza8kbPMfX/3M4AD4NjqI3WTY3H9GkIeSkhu0YwNITqD2IFaY bSHa3d6xkjrdLGfukRUp70U= X-Google-Smtp-Source: APXvYqxcNSExY/SMwHl2zH/+5QYsIuAKuTN9Gh2RvPCz+UOX5kyEErqlcmJ+v7qFQOKCa2wCnrFayA== X-Received: by 2002:a05:6402:1548:: with SMTP id p8mr14130504edx.43.1570807714138; Fri, 11 Oct 2019 08:28:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:906:4c51:: with SMTP id d17ls2015914ejw.8.gmail; Fri, 11 Oct 2019 08:28:33 -0700 (PDT) X-Received: by 2002:a17:907:2132:: with SMTP id qo18mr14135560ejb.247.1570807713643; Fri, 11 Oct 2019 08:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570807713; cv=none; d=google.com; s=arc-20160816; b=Z/C0bkQ9/DWjz+zWyBi7c9Hpi7VJL2Idl/0ItAQFvD9nVCJLoXB8Tbia75QZqBUirM NXNTXnPdz1ONjAcye4qePXWY+7Ul5Kc0bUNLllMxuzsmy5vEzx6UrxvoKcFzxaYOfT93 FyuFRqcMK/DSldLRuHFzT5Anx8zOhTqF90Gm8tLbxYe/isOnAB8Z4m0Ua82SLC1te7gu hNixoF+lny/nBk2M6CBVrB1DFsIi/MFB5duJn/i7L/cMZwqCh+eyzYNxJ0lPA9Y0gkJJ DZ9VZobxLcvWIe9uurRbgrVOzVgWHgCOhOR+K/8QBbn9pFyXa+RfdB3rNTFEhucgrHi6 sudg== 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=IFncCTtDPfA9PDpUnHGqYnsWiGdlvsQCtiZqvTBJglBBKurGCp4Nw0peFagM55S2TP Vs9QybAMSc/eyaGTYhYK8tfZ2MrEdiUsWeLiUoOkVzwQprxU39MxZIFNt1MvMqQ59nm2 ONb84+W7DiHF6wjNZio2uybTEgxPqeGFeezOmKrejf6TheLPk2WC0yg1pGKasHUMIGw4 J4JgmtJWfsAtqsyvz6G3NeeZiG5AuRszZ6KI1qruiZhUnIKrz7cD4JoYtmznwUYbdkVG FkPohVNv5do0lp3HOlB3mXxfEkBnB0eygR/WN5wkFJWxAsfq8aNYDU0zTUHShsu85MS0 4+6g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id a15si90526ejj.0.2019.10.11.08.28.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Oct 2019 08:28:33 -0700 (PDT) Received-SPF: pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id x9BFSX1Q008939 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 11 Oct 2019 17:28:33 +0200 Received: from dev.vm6.ccp.siemens.com (md1w1dqc.ad001.siemens.net [139.16.78.161] (may be forged)) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id x9BFSWua029478; Fri, 11 Oct 2019 17:28:32 +0200 Received: from dev.vm6.ccp.siemens.com (localhost [127.0.0.1]) by dev.vm6.ccp.siemens.com (Postfix) with ESMTP id 5274E2353A51; Fri, 11 Oct 2019 17:28:32 +0200 (CEST) From: Adrian Freihofer To: swupdate@googlegroups.com Cc: Adrian Freihofer Subject: [swupdate] [PATCH v2 1/1] systemd generic startup Date: Fri, 11 Oct 2019 17:27:11 +0200 Message-Id: <20191011152711.15948-2-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191011152711.15948-1-adrian.freihofer@siemens.com> References: <20191011152711.15948-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.28 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