Skip to content

Commit

Permalink
Merge pull request #72 from atolab/feat/systemd-service
Browse files Browse the repository at this point in the history
Systemd service
  • Loading branch information
J-Loudet authored Dec 17, 2021
2 parents 0202474 + d0ff4d4 commit 8f7d905
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 1 deletion.
9 changes: 8 additions & 1 deletion zenoh-flow-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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" }
"../var/placeholder" = { path = "/var/zenoh-flow/placeholder" }
"../resources/zenoh-flow.service" = { path = "/lib/systemd/system/zenoh-flow.service" }
42 changes: 42 additions & 0 deletions zenoh-flow-daemon/resources/debian/postinst
Original file line number Diff line number Diff line change
@@ -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:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# 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
38 changes: 38 additions & 0 deletions zenoh-flow-daemon/resources/debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# postrm script for fog05
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# 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
60 changes: 60 additions & 0 deletions zenoh-flow-daemon/resources/rpm/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
%define __spec_install_post %{nil}
%define __os_install_post %{_dbpath}/brp-compress
%define debug_package %{nil}

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}

License: EPL-2.0 OR Apache-2.0

Group: System Environment/Daemons
Group: Applications/System
Source0: %{name}-%{version}.tar.gz
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
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 zenoh-flow.service
/usr/bin/chown zenohflowd:zenohflowd -R /var/zenoh-flow

%preun
%systemd_preun zenoh-flow.service
/usr/sbin/userdel zenohflowd

%postun
%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
%{_unitdir}/zenoh-flow.service
18 changes: 18 additions & 0 deletions zenoh-flow-daemon/resources/zenoh-flow.service
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f7d905

Please sign in to comment.