Skip to content

Commit

Permalink
Merge pull request #18 from mw9/feature/systemd
Browse files Browse the repository at this point in the history
Debian: Add a systemd service file for LMS
  • Loading branch information
mherger committed Feb 7, 2021
2 parents 9fce776 + 6922f53 commit 14334b3
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 4 deletions.
5 changes: 3 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ Source: logitechmediaserver
Section: sound
Priority: optional
Maintainer: Logitech/Slim Devices <debian@slimdevices.com>
Build-Depends: debhelper (>= 9)
Build-Depends: debhelper (>= 9), dh-systemd (>= 1.5)
Standards-Version: 3.9.5

Package: logitechmediaserver
Architecture: all
Conflicts: slimp3,slimserver,squeezecenter,squeezeboxserver
Replaces: slimp3,slimserver,squeezecenter,squeezeboxserver
Depends: perl (>= 5.8.8), adduser, libc6, libgcc1, libstdc++6, zlib1g, libio-socket-ssl-perl, ca-certificates
Depends: ${misc:Depends}, perl (>= 5.8.8), adduser, libc6, libgcc1, libstdc++6, zlib1g, libio-socket-ssl-perl, ca-certificates
Pre-Depends: ${misc:Pre-Depends}
Description: Streaming Audio Server
Logitech Media Server is a cross-platform streaming media server that supports a wide range
of formats, including AAC, AIFF, FLAC, Ogg Vorbis, MP3, WAV, and WMA.
8 changes: 7 additions & 1 deletion debian/logitechmediaserver.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# User to run Logitech Media Server as
# User to run Logitech Media Server as.
# Only applicable to platforms that do not use systemd.
# Running the server as a user other than the default squeezeboxserver
# is not recommended.
SLIMUSER=squeezeboxserver

# Additional options for the server.
# For example: SLIMOPTIONS="--failsafe --nomysqueezebox"
# Use '/usr/sbin/squeezeboxserver --help' to obtain a full listing.
SLIMOPTIONS=""
174 changes: 174 additions & 0 deletions debian/logitechmediaserver.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#=======================================================================
# Unit section
#=======================================================================

[Unit]

Description=Logitech Media Server

# Ensures LMS is shutdown before network. And that the network service
# has at least been started.

After=network.target

# Make LMS wait for network-online.target (if it gets started).
# See notes below.

After=network-online.target

#-----------------------------------------------------------------------
# Some notes on networking targets:
#-----------------------------------------------------------------------

# We leave it to the user to specify 'Wants=network-online.target' if he
# chooses, because it may not suit all users. But we specify
# 'After=network-online.target' because the SysV init script has
# essentially behaved that way by virtue of the 'Required-Start: $all'
# stanza included within it.
# This is also the approach taken in Debian's & Ubuntu's implementation
# of 'rc.local.service'.
#
# On systemd >= 217, user might execute:
# 'systemctl add-wants logitechmediaserver.service network-online.target'
#
# The effects of the 'After' and 'Wants' 'network-online' stanzas are
# very system dependent. They may or may not ensure that LMS starts up
# after network connections have been established, and they may or may
# not cause a delay in LMS start up.
#
# 'After=network-online.target' schedules LMS to start after the network
# is fully up, whatever that may mean. But it is only effective if the
# 'network-online.target' is active and, even then, it is only effective
# if the user's system has been, or can be, configured to wait
# appropriately for network connections to be established before
# reaching this target.
#
# 'Wants=network-online.target' would activate (pull in) that target.
#

#=======================================================================
# Service section
#=======================================================================

[Service]

#-----------------------------------------------------------------------
# Set run time variables, essentially replicating the SysV init script.
#-----------------------------------------------------------------------

# Use of '/etc/default/logitechmediaserver' to set run time variables
# is supported, for consistency with the init script.
# But setting 'SLIMUSER' is not supported. This unit file will always
# start LMS as user 'squeezeboxserver'.
# The user may override that, the methods available depend on the
# installed version of systemd.

# Note one consequence of this approach: LMS can now see environment
# variables that correspond to the defined run time variables, should it
# choose to look (it doesn't at present). This behaviour is an artefact
# of the approach adopted by this unit file and may well change. It
# should not be relied upon in any way.

# Set PATH - same value as set by SysV init script.

Environment="PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"

# Default run time settings. These are used as arguments to LMS when it
# is launched.

Environment="LOGDIR=/var/log/squeezeboxserver/"
Environment="PREFSDIR=/var/lib/squeezeboxserver/prefs"
Environment="CACHEDIR=/var/lib/squeezeboxserver/cache"
Environment="CHARSET=utf8"

# Supplementary run time settings may be defined in
# '/etc/default/logitechmediaserver'. Entries made here would override
# the defaults defined above.

EnvironmentFile=-/etc/default/logitechmediaserver

#
# If you want to add additional options use
# /usr/sbin/squeezeboxserver --help
# for the supported options and place them into the file:
# /etc/default/logitechmediaserver.
# For example:
# SLIMOPTIONS="--failsafe --nomysqueezebox"
#

#-----------------------------------------------------------------------
# Set up user and logging.
#-----------------------------------------------------------------------

# Remark: User can't be parameterized in a unit file. We could choose to
# run LMS as root, and pass the USER option to it. But that adds
# unnecessary risk.

User=squeezeboxserver
Group=nogroup

# LMS will fail to start if a writeable log directory does not exist and
# it cannot create it. This can easily happen where '/var/log' is
# mounted on a temporary file system and requires root permissions to
# create.
# This stanza instructs systemd to create the standard directory
# '/var/log/squeezeboxserver' if it does not exist, with appropriate
# permissions and ownership.
# The user may specify a different directory by setting the 'LOGDIR'
# run time variable, but it is then his responsibility to ensure that
# it exists and is writeable.
# Note: Only effective in systemd >= 235. Earlier releases will see
# harmless 'Unknown lvalue' messages logged.

LogsDirectory=squeezeboxserver
LogsDirectoryMode=0755

#-----------------------------------------------------------------------
# Execution start
#-----------------------------------------------------------------------

# We want LMS to handle SIGPIPE, as it can help terminate misbehaving
# transcoder pipelines.

IgnoreSIGPIPE=no

# LMS is stable. So we don't want systemd to restart it if it fails.
# That just obscures errors.

Restart=no

# We do not instruct LMS to daemonize with the '--daemon' option,
# systemd prefers that we don't. We need 'Type=simple', or 'Type=exec'.

# Type currently defaults to 'simple', but may usefully default to
# 'exec' in future ('exec' available in systemd >= 240). So left unset.

#Type=simple

ExecStart=/usr/sbin/squeezeboxserver --prefsdir $PREFSDIR --logdir $LOGDIR --cachedir $CACHEDIR --charset $CHARSET $SLIMOPTIONS

#-----------------------------------------------------------------------
# Execution termination
#-----------------------------------------------------------------------

KillMode=control-group
KillSignal=SIGTERM

# Never send HUP, LMS uses this to reinitialize cache, etc.
SendSIGHUP=no

# Same timeout as SysV init script. We definitely want to send that
# final SIGKILL.
TimeoutStopSec=30
SendSIGKILL=Yes

#=======================================================================
# Install section
#=======================================================================

[Install]
# Directly equivalent to run levels 2,3,4.
# Also run level 5, 'graphical.target', because that pulls in
# 'multi-user.target'.

WantedBy=multi-user.target
11 changes: 10 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ source=$(CURDIR)/../server

# main packaging script based on dh7 syntax
%:
dh $@
dh $@ --with=systemd

# Be nice to older systems (Debian version <= 7) by removing an 'init-system-helpers'
# package dependency if it has been generated. These systems cannot satisfy the
# dependency, and the LMS package cannot be easily installed if it is left in place.
# (debhelper <= 11 may add the dependency.)
# LMS will install successfully with or without this package.
override_dh_gencontrol:
dh_gencontrol
sed -i '/^Depends/s/init-system-helpers[^,]*,\s*//' ${base}/DEBIAN/control

# Overrides for variances within Logitech Media Server file locations
override_dh_perl:
Expand Down

0 comments on commit 14334b3

Please sign in to comment.