From fb1adfb4855eeb9957fa824640678f223b19cbf5 Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Mon, 17 Oct 2016 17:18:00 +0100 Subject: [PATCH 1/2] Multiple device support using upstart or systemd Alters the Debian packaging rules to generate three separate binary packages: daliserver, daliserver-upstart and daliserver-systemd. The daliserver package is unchanged, i.e. it contains the debhelper-generated sysvinit startup script. The daliserver-upstart package has an upstart configuration file. This configuration file runs an instance of daliserver when a DALI USB device is plugged in, and stops it when the device is unplugged. A lookup table in /etc/default/daliserver-upstart enables daliserver options to be set based on the serial number of the device that is plugged in. The daliserver-systemd package has a systemd unit template file and a udev rule that runs an instance of daliserver when a DALI USB device is plugged in, and stops it when the device is unplugged. A lookup table in /etc/default/daliserver-systemd enables daliserver options to be set based on the serial number of the device that is plugged in. A helper script in /usr/lib/daliserver-systemd looks up the serial number, bus number and device number based on the systemd template instance name. --- .gitignore | 12 +++++---- debian/control | 40 ++++++++++++++++++++++++------ debian/daliserver-systemd-start | 12 +++++++++ debian/daliserver-systemd.default | 12 +++++++++ debian/daliserver-systemd.install | 2 ++ debian/daliserver-systemd.postinst | 5 ++++ debian/daliserver-systemd.postrm | 5 ++++ debian/daliserver-systemd.udev | 1 + debian/daliserver-systemd@.service | 7 ++++++ debian/daliserver-upstart.default | 12 +++++++++ debian/daliserver-upstart.upstart | 23 +++++++++++++++++ debian/rules | 9 +++++++ 12 files changed, 128 insertions(+), 12 deletions(-) create mode 100755 debian/daliserver-systemd-start create mode 100644 debian/daliserver-systemd.default create mode 100644 debian/daliserver-systemd.install create mode 100644 debian/daliserver-systemd.postinst create mode 100644 debian/daliserver-systemd.postrm create mode 100644 debian/daliserver-systemd.udev create mode 100644 debian/daliserver-systemd@.service create mode 100644 debian/daliserver-upstart.default create mode 100644 debian/daliserver-upstart.upstart diff --git a/.gitignore b/.gitignore index 4518ef9..f2b3341 100644 --- a/.gitignore +++ b/.gitignore @@ -14,15 +14,17 @@ /config.status /config.sub /configure -/debian/daliserver.debhelper.log -/debian/daliserver.postinst.debhelper -/debian/daliserver.postrm.debhelper -/debian/daliserver.prerm.debhelper -/debian/daliserver.substvars +/debian/.debhelper/ +/debian/*.debhelper.log +/debian/*.debhelper +/debian/*.substvars /debian/daliserver/ +/debian/daliserver-upstart/ +/debian/daliserver-systemd/ /debian/files /debian/autoreconf.* /debian/.debhelper +/debian/debhelper-build-stamp /depcomp /install-sh /missing diff --git a/debian/control b/debian/control index 583d4f0..fc65469 100644 --- a/debian/control +++ b/debian/control @@ -11,10 +11,36 @@ Vcs-Browser: https://github.com/onitake/daliserver Package: daliserver Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, lsb-base -Description: Command multiplexing server for DALI lighting buses - Exposes a DALI (Digital Addressable Lighting Interface) bus to the - local machine by interfacing with the Tridonic DALI USB adapter. - . - Multiple clients can connect to the multiplexer to send commands to and - receive responses from devices connected to the bus. +Depends: ${shlibs:Depends}, ${misc:Depends}, libusb-1.0-0, lsb-base +Conflicts: daliserver-upstart, daliserver-systemd +Description: daliserver + daliserver is a command multiplexing server for the Tridonic DALI USB adapter, + allowing access to a DALI bus from any USB-equipped computer that supports + libusb. This package includes init scripts for sysvinit-based systems, or + systems that include a sysvinit compatibility layer. Only one DALI USB + adapter is supported at a time by this package, and adapters cannot be + hotplugged. + +Package: daliserver-upstart +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libusb-1.0-0, upstart +Conflicts: daliserver, daliserver-systemd +Replaces: daliserver +Description: daliserver-upstart + daliserver is a command multiplexing server for the Tridonic DALI USB adapter, + allowing access to a DALI bus from any USB-equipped computer that supports + libusb. This package includes init scripts for upstart-based systems. + Multiple simultaneous DALI USB adapters are supported, and adapters can + be hotplugged. + +Package: daliserver-systemd +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libusb-1.0-0, systemd +Conflicts: daliserver, daliserver-upstart +Replaces: daliserver +Description: daliserver + daliserver is a command multiplexing server for the Tridonic DALI USB adapter, + allowing access to a DALI bus from any USB-equipped computer that supports + libusb. This package includes init scripts for systemd-based systems. + Multiple simultaneous DALI USB adapters are supported, and adapters can + be hotplugged. diff --git a/debian/daliserver-systemd-start b/debian/daliserver-systemd-start new file mode 100755 index 0000000..3d4c064 --- /dev/null +++ b/debian/daliserver-systemd-start @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +DEVPATH=/"$(/bin/systemd-escape --unescape ${1})" +BUSNUM=$(cat ${DEVPATH}/busnum) +DEVNUM=$(cat ${DEVPATH}/devnum) +ID_SERIAL_SHORT=$(cat ${DEVPATH}/serial) + +source /etc/default/daliserver-systemd + +exec /usr/bin/daliserver $DALISERVER_OPTS -u $BUSNUM:$DEVNUM diff --git a/debian/daliserver-systemd.default b/debian/daliserver-systemd.default new file mode 100644 index 0000000..f2745a0 --- /dev/null +++ b/debian/daliserver-systemd.default @@ -0,0 +1,12 @@ +# Additional options for daliserver +# -n enables testing mode without USB connectivity +# -l sets the listening address (use 0.0.0.0 to listen on all interfaces) +# -p changes the port +# -f sets the log file name +DALISERVER_OPTS="-f /var/log/daliserver.log" + +# Options set based on serial number of DALI USB for -systemd package variant: +case "$ID_SERIAL_SHORT" in +# 000030A1) DALISERVER_OPTS="-p 55826 -f /var/log/daliserver-cellar.log" ;; +# 0000249A) DALISERVER_OPTS="-p 55827 -f /var/log/daliserver-groundfloor.log" ;; +esac diff --git a/debian/daliserver-systemd.install b/debian/daliserver-systemd.install new file mode 100644 index 0000000..289ee19 --- /dev/null +++ b/debian/daliserver-systemd.install @@ -0,0 +1,2 @@ +debian/daliserver-systemd@.service lib/systemd/system +debian/daliserver-systemd-start usr/lib/daliserver-systemd/ diff --git a/debian/daliserver-systemd.postinst b/debian/daliserver-systemd.postinst new file mode 100644 index 0000000..230725e --- /dev/null +++ b/debian/daliserver-systemd.postinst @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true +fi diff --git a/debian/daliserver-systemd.postrm b/debian/daliserver-systemd.postrm new file mode 100644 index 0000000..230725e --- /dev/null +++ b/debian/daliserver-systemd.postrm @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true +fi diff --git a/debian/daliserver-systemd.udev b/debian/daliserver-systemd.udev new file mode 100644 index 0000000..75f4c62 --- /dev/null +++ b/debian/daliserver-systemd.udev @@ -0,0 +1 @@ +SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="17b5", ATTR{idProduct}=="0020", TAG+="systemd", PROGRAM="/bin/systemd-escape -p --template=daliserver-systemd@.service %S%p", ENV{SYSTEMD_WANTS}="%c" diff --git a/debian/daliserver-systemd@.service b/debian/daliserver-systemd@.service new file mode 100644 index 0000000..b2cfe13 --- /dev/null +++ b/debian/daliserver-systemd@.service @@ -0,0 +1,7 @@ +[Unit] +Description=Command multiplexing server for Tridonic DALI USB on %i +BindsTo=%i.device +After=%i.device network.target + +[Service] +ExecStart=/usr/lib/daliserver-systemd/daliserver-systemd-start %i diff --git a/debian/daliserver-upstart.default b/debian/daliserver-upstart.default new file mode 100644 index 0000000..46e751d --- /dev/null +++ b/debian/daliserver-upstart.default @@ -0,0 +1,12 @@ +# Additional options for daliserver +# -n enables testing mode without USB connectivity +# -l sets the listening address (use 0.0.0.0 to listen on all interfaces) +# -p changes the port +# -f sets the log file name +DALISERVER_OPTS="-f /var/log/daliserver.log" + +# Options set based on serial number of DALI USB for -upstart package variant: +case "$ID_SERIAL_SHORT" in +# 000030A1) DALISERVER_OPTS="-p 55826 -f /var/log/daliserver-cellar.log" ;; +# 0000249A) DALISERVER_OPTS="-p 55827 -f /var/log/daliserver-groundfloor.log" ;; +esac diff --git a/debian/daliserver-upstart.upstart b/debian/daliserver-upstart.upstart new file mode 100644 index 0000000..85a0a48 --- /dev/null +++ b/debian/daliserver-upstart.upstart @@ -0,0 +1,23 @@ +# daliserver +# +# daliserver is a command multiplexing server for the Tridonic DALI +# USB adapter, allowing access to a DALI bus from any USB-equipped +# computer that supports libusb. + +description "Command multiplexing server for Tridonic DALI USB" +author "Gregor Riepl " + +start on usb-device-added ID_MODEL_ID='0020' ID_VENDOR_ID='17b5' +stop on usb-device-removed ID_MODEL_ID='0020' ID_VENDOR_ID='17b5' + +instance daliserver:$BUSNUM:$DEVNUM + +respawn + +# The device serial number is in ID_SERIAL_SHORT; this can be +# used in /etc/default/daliserver to set options per device. + +script + . /etc/default/daliserver-upstart + exec /usr/bin/daliserver $DALISERVER_OPTS -u $BUSNUM:$DEVNUM +end script diff --git a/debian/rules b/debian/rules index 63844c9..259a85e 100755 --- a/debian/rules +++ b/debian/rules @@ -4,3 +4,12 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all %: dh $@ --with autoreconf + +override_dh_auto_install: + dh_auto_install -p daliserver --destdir debian/daliserver + dh_auto_install -p daliserver-upstart --destdir debian/daliserver-upstart + dh_auto_install -p daliserver-systemd --destdir debian/daliserver-systemd + +override_dh_installinit: + dh_installinit -p daliserver + dh_installinit -p daliserver-upstart -p daliserver-systemd --no-start From 35214dc5ac3388a50ddcb498a13660886b0cc594 Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Tue, 5 Feb 2019 12:30:42 +0000 Subject: [PATCH 2/2] Update systemd support to use built-in udev unit template support Useful references: - https://github.com/systemd/systemd/issues/7109 - https://github.com/systemd/systemd/issues/10321 - https://github.com/systemd/systemd/commit/dcebc9bae4dcc3e844f01558c6127fc0d8745c8e Quick summary: there are still escaping-related misfeatures in systemd that can't be worked around using systemd-escape. For our particular use-case, @poettering has implemented a workaround that happens to do what we want; this commit switches over to using it (although this introduces a requirement that we use systemd version 236 or later). The general case is still broken. --- debian/control | 6 +++--- debian/daliserver-systemd.udev | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/debian/control b/debian/control index fc65469..b46ec62 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ Vcs-Browser: https://github.com/onitake/daliserver Package: daliserver Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libusb-1.0-0, lsb-base +Depends: ${shlibs:Depends}, ${misc:Depends}, lsb-base Conflicts: daliserver-upstart, daliserver-systemd Description: daliserver daliserver is a command multiplexing server for the Tridonic DALI USB adapter, @@ -23,7 +23,7 @@ Description: daliserver Package: daliserver-upstart Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libusb-1.0-0, upstart +Depends: ${shlibs:Depends}, ${misc:Depends}, upstart Conflicts: daliserver, daliserver-systemd Replaces: daliserver Description: daliserver-upstart @@ -35,7 +35,7 @@ Description: daliserver-upstart Package: daliserver-systemd Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libusb-1.0-0, systemd +Depends: ${shlibs:Depends}, ${misc:Depends}, systemd (>= 236) Conflicts: daliserver, daliserver-upstart Replaces: daliserver Description: daliserver diff --git a/debian/daliserver-systemd.udev b/debian/daliserver-systemd.udev index 75f4c62..3dba275 100644 --- a/debian/daliserver-systemd.udev +++ b/debian/daliserver-systemd.udev @@ -1 +1 @@ -SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="17b5", ATTR{idProduct}=="0020", TAG+="systemd", PROGRAM="/bin/systemd-escape -p --template=daliserver-systemd@.service %S%p", ENV{SYSTEMD_WANTS}="%c" +SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="17b5", ATTR{idProduct}=="0020", TAG+="systemd", ENV{SYSTEMD_WANTS}="daliserver-systemd@.service"