From patchwork Tue Oct 15 08:24:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Freihofer, Adrian" X-Patchwork-Id: 1176804 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::53b; helo=mail-ed1-x53b.google.com; envelope-from=swupdate+bncbaabbumes3wqkgqe4oivrwy@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="ZJJfZ9rx"; dkim-atps=neutral Received: from mail-ed1-x53b.google.com (mail-ed1-x53b.google.com [IPv6:2a00:1450:4864:20::53b]) (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 46spPy13fnz9sPT for ; Tue, 15 Oct 2019 19:24:52 +1100 (AEDT) Received: by mail-ed1-x53b.google.com with SMTP id a21sf11710589edt.19 for ; Tue, 15 Oct 2019 01:24:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1571127889; cv=pass; d=google.com; s=arc-20160816; b=sGX9gjYOJ/NV/pitb/cCPOEGhsnfHkip5S5QfxxsmN9oiAJIdqlznCOJc3Rtmf7w6k ZCSaXFVbr/a/fjAAVDcNXrYh6rKdv0WVKHpR7rpXauD+xlGJuEEKhruBbfJZdi8RgrCq zCpZFOnYFTHUwLh/lkxCvtCZamLvpvcP4Xd3VIr6J4C2shyEUvzB9QVeP03c9gvJk91/ ie2SlYp8rlb4SX8RvkJoa0Y4wyPNnr4oXOXB/bGBopWcfcu6JdXAwdHYuA5POK+jR2Kh y1qXs1yXj160bZY5lUhRoLT4F/i7hpMgXHxLkHPe3Y0Lh8NvAStgxlCbps2XMt3LGsw/ XfoQ== 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=mMCh5b8iB+Gww5NK0NbEhgBqQ01nT5h7lQOlIXsh5NA=; b=AiVePgf0QFSf9jvOnPPktmNHhchpflSd8WADz5GVmjXj49C9yEsGlIolO1XRite4wH 2jUhG9gIRRMfomy9GaD+9fdJlg9hkXyPOuwX8/mm/cWSNBwWu9KRfWsch/ScvtMS9qib toFR4lNlVoPQozI2/nEDt4bnq4hSuh05ezTJ7SulRqJcCH4TO+StaALjDat5icQh6RmH 9ziiXcYuLx0zSi5rONnIq9DlOyjTYpMBs5CrdZOhQU+SGxuthYupU3NdlM0Px0wmFxRk yN4KKoRXTrjBE2gZaGRCFWy6bx2wBvo1eeH9TpwQQNdiUQ5GjWLlwcvxuw82mCyq0tQu v21w== 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=mMCh5b8iB+Gww5NK0NbEhgBqQ01nT5h7lQOlIXsh5NA=; b=ZJJfZ9rxb0GUYbR7PpVWC+ZLDOs4caItmFluS7p09tHqMW9Ey9uG20nkm0JicqK9c0 vyfoSQrTtn1YFauxCm/tbsbcuyFG2yNi/dVA+btJFF/xZz8muHsP7V4gfgabv9pNU6rI hX8GeZt5bdbiQItG9ssRl+LwvuIvRUTCIZl/h7ViA3IaPE+C+P3bWR+Jw7KVi4aiG1C0 HB91YuWXpJDJCf3iUnzYdfe1QTEchO0J7578kz9QEZapYoe6oR4lyCAE9duO/4InO9Ua SYk+7EC66WOrJQjrf9ArY6hB1xTfhYBzGt/Fl7j88jH5ANTiD9/Sr8/zOz4kEgAf5ziD Uviw== 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=mMCh5b8iB+Gww5NK0NbEhgBqQ01nT5h7lQOlIXsh5NA=; b=o71XQVRD3o5WBgoCW0hAatbflJah5feLZ4iMXD4togj8SFD5VN2fulYxlgGegjbeLt oqDl7PL3HpWgU/CwarVNgFncQDMHs0JcBSawgMiMNdJVEp/hxoX4doGrH8GHNYzU93TH zftExOP+npbLMkVByLxMymcDdZnYdbF13xjZ3M3thzWTtvokCOGobY9u4zMBJ3toE6G/ llr5EJg85zOW1mJPpdfutAAalHjidbsjII+fOs+JT3mRz8ICYQeXWc68jpOZS9tR2tqD mZ/JlMFf+uPpvWxc4tbLZO1Uhya6ZwDbyYa9BNs6DTEvyfxq2OifTWCB0+h4L0mRSpFB 9tKQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAWw9dxYLl1EcJMMMOIeDyP1EJGc6CIbPbNFjzMIhXbMHyoP5BAP HdblzNkGgf2g8a/hhBycOHY= X-Google-Smtp-Source: APXvYqzmoYioS9UyW2F8Tszp9Ta28qIdLuyXQoj5Dvakfry7L7RBzoBCRmrdrxNgQj9qShp/Sp+FCQ== X-Received: by 2002:a17:906:c801:: with SMTP id cx1mr33759349ejb.266.1571127889224; Tue, 15 Oct 2019 01:24:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:907:11c8:: with SMTP id va8ls4456446ejb.15.gmail; Tue, 15 Oct 2019 01:24:48 -0700 (PDT) X-Received: by 2002:a17:907:119c:: with SMTP id uz28mr33211643ejb.115.1571127888828; Tue, 15 Oct 2019 01:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571127888; cv=none; d=google.com; s=arc-20160816; b=lOGtLYnLAwydqZQViuwc2qcbwUGufAT7fu8yJLINmkmqnFfbG+f7ebj4wf84qTrHsz up2hUAXb5rGesbbiq+tvPMxOvWI9SfHdiexfXjFuwGrwGCFLiy6lFDmxReTBbykttBxG A8l58JsLD/xO/Yl1+KKOuJOjx+LFPa5UG0iLBn1tPLnU8640U3Bw+gapq79p2oK30AXI 8gD6nbWQxjXATD6pW1gRHOfxSoIieZ60o8QwYizvW119vkgOlyq/c+2RvE8xR1gLlfR3 4E6ORsmgnEwtcT4iuP/YqGbrAFka8FoVKKBLAhVWfohIyifZSMXbBc0WoQB3weT6Dadz ma/g== 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=gxZ8PraoG7LZsKmIDabqDCiaIwtqPY9blyyUTZlzSIU=; b=P0XgdvD7QkL/5HHHViI4hxDBq66doYj2TnZ4ygBBMaG9C4PWnXRPA5pD0IhFMynU0b 4wRzJeUzoAhuLKJ049trQ23Bqy2QWbeYpOCBZKYUQKs6VeVnCDNYObgR0IY23+Z0bXwM UtckXUy80VcU4bqHnXb7t+HL8rg6IVzZUwzNFQPOXJa17sTDUt+f4it0se5kHjtM9MNM YV21LrXrkVv0c3EJqLzXZ+jknYWcQyyQ+pI43E88lPAul4cISQR0NvI/OY0ZBDWzUYVA Xc5qpVSxqRDADIL/M1Jg50+Tqry3MYltlNlw9v6Cw88g3knYj4VQWONARyUXtCalNiBM 1V9A== 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 d14si1095805edb.4.2019.10.15.01.24.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Oct 2019 01:24:48 -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 mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id x9F8Om8P028474 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 15 Oct 2019 10:24:48 +0200 Received: from dev.vm6.ccp.siemens.com ([167.87.48.196]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id x9F8OlJY017875; Tue, 15 Oct 2019 10:24:47 +0200 Received: from dev.localdomain (localhost [127.0.0.1]) by dev.vm6.ccp.siemens.com (Postfix) with ESMTP id E3F072353A50; Tue, 15 Oct 2019 10:24:46 +0200 (CEST) From: Adrian Freihofer To: swupdate@googlegroups.com Cc: Adrian Freihofer Subject: [swupdate] [PATCH v4 1/2] systemd generic startup Date: Tue, 15 Oct 2019 10:24:33 +0200 Message-Id: <20191015082434.6750-2-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191015082434.6750-1-adrian.freihofer@siemens.com> References: <20191015082434.6750-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 | 11 +++++++++++ startup/systemd/swupdate.sh | 28 ++++++++++++++++++++++++++++ startup/systemd/swupdate.socket | 11 +++++++++++ startup/systemd/tmpfiles-swupdate.conf | 2 ++ 10 files changed, 109 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..a3d8d19 --- /dev/null +++ b/startup/systemd/swupdate.service @@ -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/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