From 306aaec05ad8d53999b03207495aa0156b004a39 Mon Sep 17 00:00:00 2001 From: gabrik Date: Fri, 17 Dec 2021 11:57:08 +0100 Subject: [PATCH 1/2] systemd service Signed-off-by: gabrik --- zenoh-flow-daemon/Cargo.toml | 9 ++- zenoh-flow-daemon/resources/debian/postinst | 42 +++++++++++ zenoh-flow-daemon/resources/debian/postrm | 38 ++++++++++ zenoh-flow-daemon/resources/rpm/template.hbs | 70 +++++++++++++++++++ .../resources/zenoh-flow.service | 18 +++++ 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 zenoh-flow-daemon/resources/debian/postinst create mode 100644 zenoh-flow-daemon/resources/debian/postrm create mode 100644 zenoh-flow-daemon/resources/rpm/template.hbs create mode 100644 zenoh-flow-daemon/resources/zenoh-flow.service diff --git a/zenoh-flow-daemon/Cargo.toml b/zenoh-flow-daemon/Cargo.toml index fb20a191..df6a2884 100644 --- a/zenoh-flow-daemon/Cargo.toml +++ b/zenoh-flow-daemon/Cargo.toml @@ -56,6 +56,12 @@ assets = [ ["var/*", "/var/zenoh-flow", "644"], ] +conf-files = ["/etc/zenoh-flow/runtime.yaml"] + +[package.metadata.deb.systemd-units] +unit-scripts = "resources/" +unit-name = "zenoh-flow.service" + # RPM package configuration [package.metadata.rpm] @@ -69,4 +75,5 @@ zenoh-flow-daemon = { path = "/usr/bin/zenoh-flow-daemon" } [package.metadata.rpm.files] "../etc/runtime.yaml" = { path = "/etc/zenoh-flow/runtime.yaml", mode = "644" } -"../var/placeholder" = { path = "/var/zenoh-flow/placeholder" } \ No newline at end of file +"../var/placeholder" = { path = "/var/zenoh-flow/placeholder" } +"../resources/zenoh-flow.service" = { path = "/lib/systemd/system/zenoh-flow.service" } \ No newline at end of file diff --git a/zenoh-flow-daemon/resources/debian/postinst b/zenoh-flow-daemon/resources/debian/postinst new file mode 100644 index 00000000..5c806581 --- /dev/null +++ b/zenoh-flow-daemon/resources/debian/postinst @@ -0,0 +1,42 @@ +#!/bin/sh +# postinst script for zenoh flow runtime +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + id -u zenohflowd >/dev/null 2>&1 || sudo useradd -r -s /bin/false zenohflowd + sudo chown zenohflowd:zenohflowd -R /var/zenoh-flow + systemctl daemon-reload + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/zenoh-flow-daemon/resources/debian/postrm b/zenoh-flow-daemon/resources/debian/postrm new file mode 100644 index 00000000..730bb371 --- /dev/null +++ b/zenoh-flow-daemon/resources/debian/postrm @@ -0,0 +1,38 @@ +#!/bin/sh +# postrm script for fog05 +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + userdel zenohflowd + rm -rf /var/zenoh-flow + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 \ No newline at end of file diff --git a/zenoh-flow-daemon/resources/rpm/template.hbs b/zenoh-flow-daemon/resources/rpm/template.hbs new file mode 100644 index 00000000..d8c25012 --- /dev/null +++ b/zenoh-flow-daemon/resources/rpm/template.hbs @@ -0,0 +1,70 @@ +%define __spec_install_post %{nil} +%define __os_install_post %{_dbpath}/brp-compress +%define debug_package %{nil} + +Name: {{ name }} +Summary: {{ summary }} +Version: @@VERSION@@ +Release: @@RELEASE@@%{?dist} +{{#if license ~}} +License: {{ license }} +{{/if ~}} +{{#if service ~}} +Group: System Environment/Daemons +{{else ~}} +Group: Applications/System +{{/if ~}} +Source0: %{name}-%{version}.tar.gz +{{#if url ~}} +URL: {{ url }} +{{/if}} +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root +BuildRequires: systemd +Requires(pre): /usr/sbin/useradd, /usr/sbin/groupadd, /usr/bin/getent, /usr/sbin/usermod, /usr/bin/id, /usr/bin/echo, /usr/bin/tee +Requires(post): systemd, /usr/bin/chown +Requires(preun): systemd +Requires(postun): systemd, /usr/sbin/userdel +%description +%{summary} + +%prep +%setup -q + +%pre +/usr/bin/getent group zenohflowd || /usr/sbin/fos -r myservice +/usr/bin/getent passwd zenohflowd || /usr/sbin/useradd -r -s /bin/false zenohflowd + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot} +cp -a * %{buildroot} + +%clean +rm -rf %{buildroot} + + +%post +%systemd_post {{service}} +/usr/bin/chown zenohflowd:zenohflowd -R /var/zenoh-flow + +%preun +%systemd_preun {{service}} +/usr/sbin/userdel zenohflowd + +%postun +%systemd_postun_with_restart {{service}} + + +%files +%defattr(-,root,root,-) +%config(noreplace) /etc/zenoh-flow/runtime.yaml +/var/zenoh-flow/placeholder +/lib/systemd/system/zenoh-flow.service +{{#if use_sbin ~}} +%{_sbindir}/* +{{else ~}} +%{_bindir}/* +{{/if ~}} +{{#if service ~}} +%{_unitdir}/{{service}} +{{/if ~}} \ No newline at end of file diff --git a/zenoh-flow-daemon/resources/zenoh-flow.service b/zenoh-flow-daemon/resources/zenoh-flow.service new file mode 100644 index 00000000..ce0959d9 --- /dev/null +++ b/zenoh-flow-daemon/resources/zenoh-flow.service @@ -0,0 +1,18 @@ +[Unit] +Description = Eclipse Zenoh Flow runtime + +[Service] +Type=simple +Environment=RUST_LOG="zenoh-flow=info" +PIDFile=/var/zenoh-flow/runtime.pid +ExecStart = /usr/bin/zenoh-flow-daemon -c /etc/zenoh-flow/runtime.yaml +KillMode=mixed +KillSignal=SIGINT +RestartKillSignal=SIGINT +Restart=on-failure +User=zenohflowd +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=zenoh-flow-runtime +[Install] +WantedBy=multi-user.target From d0ff4d46286627a92e034f17230c384733309dda Mon Sep 17 00:00:00 2001 From: gabrik Date: Fri, 17 Dec 2021 13:17:45 +0100 Subject: [PATCH 2/2] updated template.hbs Signed-off-by: gabrik --- zenoh-flow-daemon/resources/rpm/template.hbs | 34 +++++++------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/zenoh-flow-daemon/resources/rpm/template.hbs b/zenoh-flow-daemon/resources/rpm/template.hbs index d8c25012..6c9c1b0b 100644 --- a/zenoh-flow-daemon/resources/rpm/template.hbs +++ b/zenoh-flow-daemon/resources/rpm/template.hbs @@ -2,22 +2,18 @@ %define __os_install_post %{_dbpath}/brp-compress %define debug_package %{nil} -Name: {{ name }} -Summary: {{ summary }} +Name: zenoh-flow-daemon +Summary: Zenoh-Flow: zenoh-based data-flow programming framework for computations that span from the cloud to the device. Version: @@VERSION@@ Release: @@RELEASE@@%{?dist} -{{#if license ~}} -License: {{ license }} -{{/if ~}} -{{#if service ~}} + +License: EPL-2.0 OR Apache-2.0 + Group: System Environment/Daemons -{{else ~}} Group: Applications/System -{{/if ~}} Source0: %{name}-%{version}.tar.gz -{{#if url ~}} -URL: {{ url }} -{{/if}} +URL: http://zenoh.io + BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: systemd Requires(pre): /usr/sbin/useradd, /usr/sbin/groupadd, /usr/bin/getent, /usr/sbin/usermod, /usr/bin/id, /usr/bin/echo, /usr/bin/tee @@ -44,27 +40,21 @@ rm -rf %{buildroot} %post -%systemd_post {{service}} +%systemd_post zenoh-flow.service /usr/bin/chown zenohflowd:zenohflowd -R /var/zenoh-flow %preun -%systemd_preun {{service}} +%systemd_preun zenoh-flow.service /usr/sbin/userdel zenohflowd %postun -%systemd_postun_with_restart {{service}} +%systemd_postun_with_restart zenoh-flow.service %files %defattr(-,root,root,-) %config(noreplace) /etc/zenoh-flow/runtime.yaml +/usr/bin/zenoh-flow-daemon /var/zenoh-flow/placeholder /lib/systemd/system/zenoh-flow.service -{{#if use_sbin ~}} -%{_sbindir}/* -{{else ~}} -%{_bindir}/* -{{/if ~}} -{{#if service ~}} -%{_unitdir}/{{service}} -{{/if ~}} \ No newline at end of file +%{_unitdir}/zenoh-flow.service