daliserver icon indicating copy to clipboard operation
daliserver copied to clipboard

Multiple device support using upstart or systemd

Open sde1000 opened this issue 9 years ago • 13 comments

This is a re-work of my earlier pull request (now closed) regarding startup scripts for systems that need to support more than one DALI USB device being plugged in at a time, with stable mapping between physical device and TCP port number.

This pull request 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 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.

sde1000 avatar Oct 17 '16 16:10 sde1000

Woah, nice work. I'll still have to review and test it, but it looks like this is a good solution. I wonder though if separate packages are really needed. Isn't it common to ship startup scripts for all supported init systems within a single package? There may be conflicts though, as systemd picks up sysvinit scripts and automatically creates corresponding units internally.

onitake avatar Oct 17 '16 17:10 onitake

I couldn't figure out how to make a single package that did everything. systemd automatically creating a unit for the sysvinit script is one issue; having a systemd dependency in the udev rules file (which isn't required for systems using upstart or sysvinit) is another.

sde1000 avatar Oct 17 '16 17:10 sde1000

You can have a choice of requirements in your dependency list, for example: sysvinit-core | systemd | upstart I'm not sure how other projects handle this, but it's likely something similar.

onitake avatar Oct 17 '16 17:10 onitake

Fiddling with the Debian package dependencies won't help in this case. Having /etc/init.d/daliserver in the package at the same time as /lib/systemd/system/[email protected] and the udev rule would mean that daliserver would be started with the default arguments by the sysvinit script (trying to drive the first device it found) and would also be started with appropriate arguments to -u for each DALI USB device attached to the system. The ordering of what would happen here is not well-defined, and at least one of those invocations of daliserver would fail.

sde1000 avatar Oct 17 '16 17:10 sde1000

Good point - I came to the same conclusion after contemplating it a bit. I still think splitting init scripts out into separate packages is wrong, though. How about using debconf to present a dialogue to the user?

onitake avatar Oct 18 '16 06:10 onitake

If you can figure out how to make it work, go ahead. What questions would debconf ask, and what would it do after they were answered?

sde1000 avatar Oct 18 '16 09:10 sde1000

My suggestion is something like this:

Would you like to run a separate instance of daliserver for each connected DALIUSB device? Note that you need to configure a different TCP port for each instance.

If selecting yes, it could then ask for the port or something.

onitake avatar Oct 18 '16 20:10 onitake

I think that question is pointless because the answer will universally be "yes" - and then on a sysvinit system you would have to say "sorry, not possible".

sde1000 avatar Oct 19 '16 09:10 sde1000

I've updated this pull request: I've rebased to current master, and I've fixed an escaping-related issue that stopped the systemd support working sometime after systemd release 229. See systemd#7109 and systemd#10321 for details.

sde1000 avatar Feb 05 '19 13:02 sde1000