Closed mw9 closed 3 years ago
LMS user is hardcoded to 'squeezeboxserver'
For access purposes I run my LMS as an 'ordinary' user. It would be nice if the LMS user can be set in the /etc/default/logitechmediaserver .
For access purposes I run my LMS as an 'ordinary' user. It would be nice if the LMS user can be set in the /etc/default/logitechmediaserver .
With the proposed unit file, a knowledgeable user can override the user setting (or any others), using systemctl edit
. Or just by copying the unit file into /etc/systemd/system and editing to suit.
The existing Init script reads and executes the default file, and then uses start-stop-daemon to set the user. As far as I can see, the Debian package has used this method "for ever".
A systemd unit file does not offer that kind of flexibility. In an attempt to maintain some kind of compatibility with the use of the existing default file, the proposed unit file reads it and sets environment variables to achieve a similar effect. But this approach cannot work with systemd's USER setting in the unit file.
The unit file could choose to honour the SLIMUSER setting in the default file by passing that as an argument to LMS, with LMS launched as root. LMS would then take on the obligation to change the effective user/group after it has launched. I don't think that this code path has been used for many years (on Debian), and I don't have the competence to judge its effectiveness. So I took the cowardly approach and avoided it.
Perhaps there is a better way of launching LMS from a systemd unit file. For example, by using a "pre-launch" script/program to do the job. But that would add additional complexity.
With the proposed unit file, a knowledgeable user can override the user setting (or any others),
Which is what I did a long time ago ;).
If there is no need for a more generic solution let's leave it as is. No problem.
Nice!
Does this support non-systemd versions of debian or ubuntu?
Yes.
Devuan: I don't have a Devuan system, but it is based on Debian, which supports both sysvinit and systemd, so it should just work.
Pre 2015: Tested on Debian 7 & Debian 6. There's a bit of chatter during installation, but installation succeeds. See comment in second commit.
But needs testing in the Real World to confirm that practice matches theory.
@mw9 - thanks for this PR. I'm a bit puzzled by how this would become active, used. You say
squeezeboxserver_safe goes..
But I don't see any related change. How would I tell debpkg
to use this init script instead of the old one?
do you have a copy of the .deb available somewhere I could download? would save me a few minutes building it.
@mherger is there a list of supported versions of debian, ubuntu, red hat, centos?
Or is it more that a valiant attempt is made to support running on any reasonably sane system with perl >= 5.10 ?
@mw9 - thanks for this PR. I'm a bit puzzled by how this would become active, used. You say
squeezeboxserver_safe goes..
But I don't see any related change. How would I tell
debpkg
to use this init script instead of the old one?
You need tell it nothing.
The secret sauce is in how systemd
operates:
If systemd
finds an enabled SysV init script but does not find a unit file for the service, it will generate a unit file on the fly that executes the SysV init script. That generated unit file is then used to launch the service. This is why the existing installation continues to work under systemd
.
If, however, systemd
does find an installed unit file (which will have the same name as the SysV init script), it will ignore the init script altogether, and simply use the installed unit file.
This change installs a unit file for systemd
to use.
A no systemd here
system will not concern itself with the installed unit file, and will run the init script in the usual way.
I hope that helps.
do you have a copy of the .deb available somewhere I could download? would save me a few minutes building it.
Not that would be useful to you. (A somewhat patched armel version of LMS that is not fit for public viewing). Testing the build on systems other than my own would be valuable in proving correct operation.
You need tell it nothing.
The secret sauce is in how
systemd
operates:
So you're saying that if I merged this PR (and it was not broken), things should "just work"? 8.2 is in dev, I could give it a try and let the brave people using 8.2 report issues 😁.
I've tested this on a Devuan 3 (Beowulf) x64 system (equivelant to Debian 10 Buster).
Everything works fine.
It's running on a tiny Linode instance. I'll leave it up for another few days (at a total cost of less than a dollar).
If any of you want to check it out pm me your ssh pubkey.
I think we can now be pretty confident that this will now work on the bulk of debian based systems.
So what testing is still necessary?
This of course is all x86_64.
x86_32 is close enough that it should be covered.
ARM... harder to find cloud-based ARM systems to test on. Plenty of RPi's about tho.
I'd suggest
Test matrix
Distro | init manager | version | status |
---|---|---|---|
Debian | systemd | 10 | tested OK |
9 | tested OK | ||
8 | tested OK | ||
sysvinit | 7 | ||
6 | |||
5 | |||
4 | not supported | ||
Devuan | sysvinit | 3 | tested OK |
2 | |||
Ubuntu | systemd | 20.10 | |
20.04LTS | |||
19.10 | |||
... | |||
upstart/sysv | 15.04 | ||
... |
You need tell it nothing. The secret sauce is in how
systemd
operates:So you're saying that if I merged this PR (and it was not broken), things should "just work"? 8.2 is in dev, I could give it a try and let the brave people using 8.2 report issues 😁.
That is the "design intent". People for whom it won't just work are those who have set SLIMUSER
.
It might be worth waiting on @tomscytale, he was planning to set up a few test rigs.
It might be worth waiting on @tomscytale, he was planning to set up a few test rigs.
Ah, I see that he has.
I can report that it works on armel
based Debian 6 through 10. I don't plan to make a Debian 5 for testing.
I am not aware of any architectural dependencies/nuances that would get in the way.
Thank you very much guys! Let's give this a try.
ubuntu 20.10 looking good
there's a very high probability that this will just work everywhere now.
I will try to test on a few other systems over the coming days - in particular my RPi running aarch64 Ubuntu 20.10
Thank you very much guys! Let's give this a try.
The new nightly arm deb looks good. Doubtless the other debs will be good as well.
Tested on: RPiOS (Buster 10) armhf Ubuntu 20.04LTS aarch64
Summary
As discussed in the forum thread "systemd service file for LMS": https://forums.slimdevices.com/showthread.php?113114-systemd-service-file-for-LMS
This proposed change adds a systemd unit file to the Debian installation package, and will stand in place of the "auto-generated" unit file that systemd currently creates. The "auto-generated" unit file simply calls the existing SysV init script.
Main features:
_squeezeboxserversafe goes, and LMS is started directly by systemd. No "supervisor", if it fails it stops.
Supports setting start up options by using /etc/default/logitechmediaserver, similar to the existing SysV init script. But LMS user is hardcoded to 'squeezeboxserver'.
Checks that /var/log/squeezeboxserver exists and is writeable, and creates it if not. (Good for systems with /var/log mounted as temporary file system). (But only on modern versions of systemd).
Addresses issue whereby LMS may start "too early", before network connections are configured. In systemd-speak, by including an After=network-online.target stanza in the unit file. It is left to the user to configure his system in a manner that gives appropriate meaning to the network-online.target.
I have removed a "Service reload" ('HUP' to LMS) action from the draft unit file that I posted in the forum thread. I am not sure that the function that it supplies is useful. It can be added at a later date if it is, indeed, useful.
I have left a complete set of comments in the unit file itself, which should help to explain why each option is set the way it is, so I won't repeat them here. I'd propose leaving them in there to assist knowledgeable users, but perhaps it is too wordy.
I have successfully built a Debian package on both Debian 9 and Debian 10, and I have installed the resulting package successfully on Debian 7 through 9. It should work equally well on any Debian derived system, with or without systemd, including Ubuntu and Devuan (a non-systemd port of Debian).
So I think it will prove itself in the real world of LMS users, but I shall not be surprised if the real world of LMS users does generate a surprise or two.
Commits
There are three commits:
Debian: Add systemd service unit
Adds boiler plate changes to Debian rules, config file, and the unit file itself. These are as described in the Debian wiki: https://wiki.debian.org/Teams/pkg-systemd/Packaging
Debian: Add systemd service unit - support older systems without 'init-system-helpers'
The boiler plate rules may or may not generate a dependency on a relatively new package, init-system-helpers. This will break older Debian systems if the dependency is not removed, and there still appear to be plenty of users whose systems fall into this category. Installation will proceed successfully without it, although a "deb-systemd-helper: not found" message will be logged. Such users need to upgrade to a more modern system to remove it.
Debian: Add systemd service unit - add explanatory comments to LMS default file
This is not essential, but, I think helpful. It just adds additional explanatory comments in the existing LMS default file /etc/default/logitechmediaserver.
However, we should be aware that anyone who has edited his LMS default file away from the previously installed version will get the usual Debian "Configuration file has been modified" interactive prompt during installation. And that may trigger requests for help in the forum. I would hope not, but it might.