-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debian: Add a systemd service file for LMS #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why you'd stick with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've chosen to stick with what the existing installer does, this proposed change only adds a systemd unit file to the existing installation. The existing installation is somewhat "conflicted". It creates the user
The systemd unit file that this change installs is named A tidying up exercise might be nice to do, but I wouldn't wish to incorporate it into this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd agree that keeping things as similar as possible to the current set up is the way to go. At the expense of maintaining the current inconsistency in naming. |
||
# is not recommended. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a brief note explaining how to change the user with systemd
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly. Bear in mind that the Debian installer sets everything up to run under user squeezeboxserver. I would not personally be inclined to encourage users to depart from that. Knowledgeable users can figure it out for themselves. That's my take, anyway. But I'm more than happy to change if that's what's wanted. |
||
SLIMUSER=squeezeboxserver | ||
|
||
# Additional options for the server. | ||
# For example: SLIMOPTIONS="--failsafe --nomysqueezebox" | ||
# Use '/usr/sbin/squeezeboxserver --help' to obtain a full listing. | ||
SLIMOPTIONS="" |
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the very detailed comments |
||
# | ||
# '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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by "defined run time variables" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean the shell variables that are defined in the init script and defaults file. These are used to build the LMS command line. Perhaps I might have said "defined run time parameters". Or something else. I'll try to find some better words. A systemd unit file does not provide for parameter substitution (no "local variables"), so I am using environment variables to achieve the same trick, i.e. read the defaults file to set environment variables, which we can then use. But that, of necessity, leads to a rather full environment. I believe that some other projects may have adopted the same approach. This is all predicated on the notion that we really do wish to support use of the existing defaults file. I suspect that its main role is in defining SLIMOPTIONS. Another way of doing it would be to abandon the defaults file altogether and teach users how to edit their unit files, possibly after explaining to them why the upgrade didn't "just work"... :( |
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,16 @@ source=$(CURDIR)/../server | |
|
||
# main packaging script based on dh7 syntax | ||
%: | ||
dh $@ | ||
dh $@ --with=systemd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does adding this arg do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It triggers debhelper into adding the necessary boiler plate to the install scripts to install the systemd unit file, and enable the unit. Explained here:
|
||
|
||
# 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: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW: Perl 5.10 is now the minimum supported :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that's Debian 4 (Etch) out of the running !
I'll put in another PR.