Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Senior Member
    Join Date
    May 2010
    Location
    London, UK
    Posts
    622

    systemd service file for LMS

    Following some recent comments in this forum, I have had a go at constructing a systemd unit service file for use on Debian based systems. It is attached to this post.

    If it, or something like it, passes muster, it could be incorporated into the Debian installer package so as to co-exist peacefully with the existing SysV init script. That will take a little more research.

    Points:

    • squeezeboxserver_safe 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).
    • Service reload sends 'HUP' to LMS, initiating some kind of LMS reinitialization.
      This may not be useful, I've never used it.
    • 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 service file.
      It is left to the user to configure his system in a manner that gives appropriate meaning to the 'network-online.target'.


    I've left rather too many notes in the file, but they record my thoughts.

    I've tested it on Debian 8 (Jessie, systemd 215), Debian 9 (Stretch, systemd 232), and Debian 10 (Buster, systemd 241), and all seems to work as expected. I shall continue to run with it for a few weeks to see if any problems emerge.

    To install manually onto an existing system:

    • Stop LMS with systemctl stop logitechmediaserver.service
    • Install the service file as /etc/systemd/system/logitechmediaserver.service
    • Reload systemd configuration with systemctl daemon-reload
    • Restart LMS with systemctl start logitechmediaserver.service


    Comments welcome.
    Attached Files Attached Files

  2. #2
    jvromans@squirrel.nl
    Guest

    systemd service file for LMS

    Good job!

  3. #3
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,476

    systemd service file for LMS

    > Following some recent comments in this forum, I have had a go at
    > constructing a systemd unit service file for use on Debian based
    > systems. It is attached to this post.


    Great, thanks! This has been a topic for a while now.

    > If it, or something like it, passes muster, it could be incorporated
    > into the Debian installer package so as to co-exist peacefully with the
    > existing SysV init script. That will take a little more research.


    I'm not a Debian guy. Actually... while I've been using some sort of
    Linux for decades, I'm not really a Linux guy, mostly just a user. So...
    Are you saying it would be possible to have old and new in parallel? If
    so, how would the system decide what to use?

    And would we expect this work with Ubuntu and its numerous descendants, too?

    --

    Michael

  4. #4
    Senior Member
    Join Date
    Jan 2010
    Location
    Hertfordshire
    Posts
    5,356
    Quote Originally Posted by mrw View Post
    Following some recent comments in this forum, I have had a go at constructing a systemd unit service file for use on Debian based systems. It is attached to this post.

    If it, or something like it, passes muster, it could be incorporated into the Debian installer package so as to co-exist peacefully with the existing SysV init script. That will take a little more research.

    Points:

    • squeezeboxserver_safe 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).
    • Service reload sends 'HUP' to LMS, initiating some kind of LMS reinitialization.
      This may not be useful, I've never used it.
    • 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 service file.
      It is left to the user to configure his system in a manner that gives appropriate meaning to the 'network-online.target'.


    I've left rather too many notes in the file, but they record my thoughts.

    I've tested it on Debian 8 (Jessie, systemd 215), Debian 9 (Stretch, systemd 232), and Debian 10 (Buster, systemd 241), and all seems to work as expected. I shall continue to run with it for a few weeks to see if any problems emerge.

    To install manually onto an existing system:

    • Stop LMS with systemctl stop logitechmediaserver.service
    • Install the service file as /etc/systemd/system/logitechmediaserver.service
    • Reload systemd configuration with systemctl daemon-reload
    • Restart LMS with systemctl start logitechmediaserver.service


    Comments welcome.
    I run MusicIP on my Pi and LMS startup has to be delayed until after MusicIP has started. At the moment I restart LMS after 30 seconds with a line in rc.local. Would this be possible with the proposed system?

    Sent from my Pixel 3a using Tapatalk

  5. #5
    jvromans@squirrel.nl
    Guest

    systemd service file for LMS

    > I run MusicIP on my Pi and LMS startup has to be delayed until after
    > MusicIP has started. At the moment I restart LMS after 30 seconds with a
    > line in rc.local. Would this be possible with the proposed system?


    You can add a systemctl service for MusicPI, and have starting LMS depend
    on the MusicPI target.

  6. #6
    Senior Member
    Join Date
    May 2010
    Location
    London, UK
    Posts
    622
    Quote Originally Posted by mherger View Post
    Are you saying it would be possible to have old and new in parallel?
    Yes.

    Quote Originally Posted by mherger View Post
    how would the system decide what to use?
    Nice question ! Can you let me know on what platform/version the Debian build process is currently being run on ? A detailed answer may depend on that, somewhat.

    As a flavour, on my Debian 10 (Buster) system, the Debian package builder's generated installation scripts provide that:

    • Starting and stopping LMS is undertaken by invoke-rc.d.

      Despite its name, on a systemd system it invokes systemd commands to do its work, in place of executing the SysV init script.

      invoke-rc.d has, I think, been present on Debian based systems for many years, so it should be OK. The Debian package currently distributed uses this tool, so unless you are aware of any complaints...

      It's currently provided by the 'essential' package init-system-helpers, but previously by sysvinit related packages.

    • Enabling/disabling/masking a systemd unit file is undertaken by deb-systemd-helper.

      I suspect that its absence may not actually cause any problems, but it remains a subject for research.

    • It requires a very minor change to the existing control and rules files.


    Earlier versions of the Debian package builder will have done things a little differently. So I need to research that.

    Quote Originally Posted by mherger View Post
    And would we expect this work with Ubuntu and its numerous descendants, too?
    Yes. I'd be astonished if Ubuntu departed from Debian in this area, and I'm not seeing any sign of it. There again, I have been astonished on many occasions in the past...

    Ultimately we have the ability to put whatever we want into the generated installation scripts. Best avoided, though. I'm not a "Debian guy", either, but I have the time to research right now. Ideally one wants an essentially maintenance free approach.

    Best case is that it all just works well enough with the very minor changes to the control and rules files. But we need, I think, to specify a minimum supported build platform. I'm thinking, perhaps, Debian 8 (Jessie), or Ubuntu equivalent. Research required.

    Worst case would be that we find ourselves adding the necessary stanzas by hand into the installation scripts, to suit our target audience(s). The snippets would not be extensive, so it is a perfectly do-able approach. But not so "maintenance free", and would require some (perhaps minimal) knowledge of Debian packaging. Experience may dictate that this approach is needed, but I'm hopeful that it won't be.

  7. #7
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,476

    systemd service file for LMS

    >> how would the system decide what to use?
    >
    > Nice question ! Can you let me know on what platform/version the Debian
    > build process is currently being run on ? A detailed answer may depend
    > on that, somewhat.


    It's a x86_64 (VM) Debian 9.

    --

    Michael

  8. #8
    Senior Member
    Join Date
    May 2010
    Location
    London, UK
    Posts
    622
    Quote Originally Posted by mherger View Post
    It's a x86_64 (VM) Debian 9.
    Thanks. I have a Debian 9 container available, I'll make sure to check build result on that.

  9. #9
    Senior Member philchillbill's Avatar
    Join Date
    Jan 2019
    Location
    The Netherlands
    Posts
    434
    Quote Originally Posted by slartibartfast;
    I run MusicIP on my Pi and LMS startup has to be delayed until after MusicIP has started. At the moment I restart LMS after 30 seconds with a line in rc.local. Would this be possible with the proposed system?
    In the [Service] section, you could add
    Code:
    ExecStartPre=/bin/sleep 30
    to cause a 30 second sleep before LMS is started.

    A look at the ngrok.service script associated with the MediaServer skill will show many similarities to this script.

  10. #10
    formerly known as Fletch
    Join Date
    May 2005
    Posts
    2,296
    I haven't used Redhat/Fedora/CentOS/etc in a very long time, but I believe they have also moved to systemd. Is there any reason to believe that your work wouldn't also be applicable to the rpm packages?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •