diff --git a/buildme.pl b/buildme.pl index fdad4f7c..6b1250dc 100755 --- a/buildme.pl +++ b/buildme.pl @@ -634,9 +634,9 @@ sub buildRPM { ## Copy the various SPEC< Config, etc files into the right dirs... copy("$buildDir/platforms/redhat/lyrionmusicserver.config", "$buildDir/rpm/SOURCES"); - copy("$buildDir/platforms/redhat/lyrionmusicserver.init", "$buildDir/rpm/SOURCES"); copy("$buildDir/platforms/redhat/lyrionmusicserver.logrotate", "$buildDir/rpm/SOURCES"); copy("$buildDir/platforms/redhat/lyrionmusicserver.service", "$buildDir/rpm/SOURCES"); + copy("$buildDir/platforms/redhat/lyrionmusicserver.preset", "$buildDir/rpm/SOURCES"); copy("$buildDir/platforms/redhat/README.systemd", "$buildDir/rpm/SOURCES"); copy("$buildDir/platforms/redhat/README.rebranding", "$buildDir/rpm/SOURCES"); copy("$buildDir/platforms/redhat/lyrionmusicserver.spec", "$buildDir/rpm/SPECS"); diff --git a/redhat/README.rebranding b/redhat/README.rebranding index bf0dfedc..fca59641 100644 --- a/redhat/README.rebranding +++ b/redhat/README.rebranding @@ -16,17 +16,10 @@ stopped also changes. systemctl stop lyrionmusicserver -> Stops the music server systemctl status lyrionmusicserver -> Shows the status of the music server -- SYSV init system - - /etc/init.d/lyrionmusicserver start -> Starts the music server - /etc/init.d/lyrionmusicserver stop -> Stops the music server - /etc/init.d/lyrionmusicserver status -> Shows the status of the music server - Configuration files are in /var/lib/lyrionmusicserver /etc/lyrionmusicserver - /etc/sysconfig/lyrionmusicserver Log files in @@ -52,11 +45,6 @@ locations of the Lyrion Music Server. This will be done if, and only if If these two conditions are not met, then the Lyrion Music Server must be configured from scratch or you can migrate your configuration manually. -** NOTE ** -If you have made changes to /etc/sysconfig/squeezeboxserver, then you must -do those changes to /etc/sysconfig/lyrionmusicserver yourself, if you want -to keep them. - ** NOTE ** If you have created a drop-in file for the systemd service squeezeboxserver, then you must create the corresponding drop-in file for the systemd service diff --git a/redhat/README.systemd b/redhat/README.systemd index ae82deb7..ccb7e814 100644 --- a/redhat/README.systemd +++ b/redhat/README.systemd @@ -1,14 +1,3 @@ -* BACKGROUND - -The fedora, RedHat, CentOS and SUSE distributions have changed the -start-up system to systemd from SYSV. The distributions offer -some backwards compatibility, but in the long run it is better -to migrate the Lyrion Music Server to use a systemd unit file for -start-up. Systemd seems to be the future for these distributions, -whatever we might think about it. - -* More information - Please read the following man pages for in depth information on how the systemd unit files work. @@ -16,30 +5,81 @@ systemd.unit systemd.service +******************************************************************************** * Stop/Start/Check status of Lyrion Music Server +******************************************************************************** sudo systemctl start lyrionmusicserver sudo systemctl stop lyrionmusicserver systemctl status lyrionmusicserver sudo systemctl restart lyrionmusicserver -* To see the contentof the systemd unit file +******************************************************************************** +* To see the content of the systemd unit file +******************************************************************************** systemctl cat lyrionmusicserver -* The user running Lyrion Music server +******************************************************************************** +* Adapting the Lyrion Music Configuration +******************************************************************************** -Due to the way systemd unit files work it has been deemed better not to -allow setting of the user id running the Lyrion Muisc server in the -/etc/sysconfig/lyrionmusicserver file. To change the user running lyrionmusicserver, -please create a so called drop-in file in the directory: +To tweak, extend or change the Lyrion Music Server it is necessary to use drop +in files for systemd. The drop in files for Lyrion Music Server must be created +in: /etc/systemd/system/lyrionmusicserver.service.d -(you will have to create the directory). The file can be called anything, but -it needs the string .conf at the end, e.g. +You will have to create the directory yourself. The drop in file can be called +anything, but it needs the string ".conf" at the end of the name, e.g. + +lyrion_changed_config.conf + +You can create one or more drop in files in that directory. You can have one or +more changes to the configuration in the files. Remember that the files are read +in lexicographic order so that the files read last overrides the files read +earlier if they have overlapping configuration statements. + +NOTE: NEVER MAKE ANY CHANGES TO THE UNIT FILE DELIVERED BY RPM PACKAGE IN THE + LOCATION /usr/lib/systemd/system/lyrionmusicserver.service. ANY CHANGES IN + THIS FILE WILL BE OVERWRITTEN NEXT TIME THE LYRION MUSIC SERVER IS + UPGRADED. + +The default systemd unit file comes with a working configuration. Only change +it, if you know what you are doing. + +In the default unit file the following 5 environment variables are defined. + +Environment="LYRION_CFG_DIR=/var/lib/lyrionmusicserver/prefs" +Environment="LYRION_LOG_DIR=/var/log/lyrionmusicserver" +Environment="LYRION_CACHE_DIR=/var/lib/lyrionmusicserver/cache" +Environment="LYRION_CHARSET=utf8" +Environment="LYRION_ADDITIONAL_ARGS=" -mylyrionuser.conf +These environment variables are used further down in the unit file in the start +command. + +You can change the Lyrion start-up command by changing the value of the four +first variables here above and add any other command line parameter to the start +command by using the variable LYRION_ADDITIONAL_ARGS by adding one or +more drop in files in /etc/systemd/system/lyrionmusicserver.service.d as +described here above. + +You can also change the user id and group id used to run the server with +drop in files. There is an example here below. + +******************************************************************************** +* +* EXAMPLES +* +******************************************************************************** + +******************************************************************************** +* How to change the log directory location +******************************************************************************** + +Create a file in /etc/systemd/system/lyrionmusicserver.service.d, you can call +the file whatever you like, but the name must end with ".conf". The content of the file should be (without the dashed lines) @@ -47,48 +87,65 @@ The content of the file should be (without the dashed lines) [Service] -USER=add-the-user-id-you-want-to-use-here +Environment="LYRION_LOG_DIR=/your/preferred/location" + ----------------------------------------------- +After you created the file you must tell the systemd to pick up the changes. +Execute: + +sudo systemctl daemon-reload + +Then restart Lyrion Music Server so that it picks up the new configuration. + +NOTE: Make sure that you create the new diretory before you restart the service. + +******************************************************************************** * Passing extra arguments to the Lyrion Music server +******************************************************************************** -The way the variable LYRION_ARGS is defined in /etc/sysconfig/lyrionmusicserver -makes it unusable in the systemd unit file. If you have added parameters to -this variable in the file and you want to keep them, then you must instead add -them to the new variable LYRION_ADDITIONAL_ARGS. You can do this by adding -the following in the /etc/sysconfig/lyrionmusicserver file (without the dashed -lines) +If you want to pass extra variables to Lyrion Music Server at startup, then add +them to the variable LYRION_ADDITIONAL_ARGS. To do this create a drop in file in +/etc/systemd/system/lyrionmusicserver.service.d with this content (without the +dashed lines): ------------------------------------------------ -LYRION_ADDITIONAL_ARGS="--d_startup" +[Service] + +Environment="LYRION_ADDITIONAL_ARGS=--d_startup" ------------------------------------------------ *** PLEASE NOTE *** -You can't use nested variables like in the past for LYRION_ARGS. +You can't use nested variables in the definition for LYRION_ADDITIONAL_ARGS. -An alternative is to create a drop-in file for systemd as described here above -for the USER. You can of course use the same drop-in file, just add an -additional line like this +******************************************************************************** +* How to change the user id and group used to run Lyrion Music Server +******************************************************************************** -Environment="LYRION_ADDITIONAL_ARGS=--d_startup" +Create a file in /etc/systemd/system/lyrionmusicserver.service.d, you can call +the file whatever you like, but the name ust end with ".conf". + +The content of the file should be (without the dashed lines) + +----------------------------------------------- + +[Service] + +USER=the-preferred-user-name +GROUP=the-preferred-group-name + +----------------------------------------------- + +After you created the file you must tell the systemd to pick up the changes. +Execute: + +sudo systemctl daemon-reload -Please remember that the content of /etc/sysconfig/lyrionmusicserver will -override the content of the drop-in files in -/etc/systemd/system/lyrionmusicserver.service.d. This means that if you define -LYRION_ADDITIONAL_ARGS both in the drop-in file and in -/etc/sysconfig/lyrionmusicserver, then it is the content of the latter that will -be used. - -################################################################################ -I strongly recommend to either delete the file /etc/sysconfig/lyrionmusicserver -or comment out all lines in the file and entirely rely on the drop in file in -/etc/systemd/system/lyrionmusicserver.service.d if you want to make any changes -to the way the Lyrion Music server is started. - -** NEVER EDIT ** the file /usr/lib/systemd/systemlyrionmusicserver.service. This -file will be overwritten next time you upgrade the Lyrion Music Server. If you -need to change anything in the unit file, then use the drop-in file in -/etc/systemd/system/lyrionmusicserver.service.d as described here above. +NOTE! +Please bear in mind that changing the user and group that runs the Lyrion Music +Server processes is a far reaching change. You will have to ensure that the new +user id and group id have sufficient read and write rights to all the file used +by the Lyrion Music Server. diff --git a/redhat/lyrionmusicserver.config b/redhat/lyrionmusicserver.config index 0b3603c7..d65a7726 100644 --- a/redhat/lyrionmusicserver.config +++ b/redhat/lyrionmusicserver.config @@ -1,33 +1,10 @@ -# Edit this to suit your setup -# But if your server is systemd based you could -# consider to comment out all the lines and instead -# use unit drop-in files in /etc/systemd/system/lyrionmusicserver.service.d - -# The variable LYRION_USER will only be picked up by SYSV systems. -# To change the user running lyrionmusicserver on a systemd server, please -# check /usr/share/ilyrionmusicserver/README.systemd -LYRION_USER="lyrionmusicserver" - -# The following variables are picked up by both SYSV and -# systemd based servers -LYRION_HOME="/usr/libexec" -LYRION_CFG_DIR="/var/lib/lyrionmusicserver/prefs" -LYRION_LOG_DIR="/var/log/lyrionmusicserver" -LYRION_CACHE_DIR="/var/lib/lyrionmusicserver/cache" -LYRION_CHARSET="utf8" - -# The variable LYRION_ARGS will only be picked up by SYSV based servers. -# For systemd based system use the LYRION_ADDITIONAL_ARGS here below. -LYRION_ARGS="--daemon --prefsdir=$LYRION_CFG_DIR --logdir=$LYRION_LOG_DIR --cachedir=$LYRION_CACHE_DIR --charset=$LYRION_CHARSET" - -# The variable LYRION_ADDITIONAL_ARGS will only be picked up by -# systemd based servers. To use it uncomment the line here below and -# add any valid arguments you want between the quotation marks. -# Please note you can't use nested variables. - -# LYRION_ADDITIONAL_ARGS="" - -# Alternatively you could use a systemd unit drop in file to define -# LYRION_ADDITIONAL_ARGS, see /usr/share/lyrionmusicserver/README.systemd -# and the systemd.unit, systemd.service man pages. But in that case the above -# line must remain commented as this file takes precedence oce any unit file. +#------------------------------------------------------------------------------ +# PLEASE NOTE! +# +# As the RPM distribution of Lyrion Music Server no longer supports Sys V +# Init, this file has been obsoleted. +# +# Use systemd drop in files instead to adapt/amend the configuration. +# Read /usr/share/lyrionmusicserver/README.systemd for more information. +# +#------------------------------------------------------------------------------ diff --git a/redhat/lyrionmusicserver.init b/redhat/lyrionmusicserver.init deleted file mode 100644 index dc88459e..00000000 --- a/redhat/lyrionmusicserver.init +++ /dev/null @@ -1,202 +0,0 @@ -#!/bin/bash -# -# lyrionmusicserver Startup script for the Lyrion Music Server -# -# chkconfig: 345 80 30 -# description: Lyrion Music Server powers the Squeezebox, Transporter and SLIMP3 network music \ -# players and is the best software to stream your music to any software MP3 \ -# player. It supports MP3, AAC, WMA, FLAC, Ogg Vorbis, WAV and more! \ -# As of version 7.7 it also supports UPnP clients, serving pictures and movies too! -# processname: lyrionmusicserver -# config: /etc/lyrionmusicserver/lyrionmusicserver.conf -# config: /etc/sysconfig/lyrionmusicserver - -# -### BEGIN INIT INFO -# Provides: lyrionmusicserver -# Required-Start: $syslog $remote_fs -# Should-Start: $time ypbind sendmail -# Required-Stop: $syslog $remote_fs -# Should-Stop: $time ypbind sendmail -# Default-Start: 3 5 -# Default-Stop: 0 1 2 6 -# Short-Description: Startup script for the Lyrion Music Server -# Description: Lyrion Music Server powers the Squeezebox, Transporter and SLIMP3 network music \ -# players and is the best software to stream your music to any software MP3 \ -# player. It supports MP3, AAC, WMA, FLAC, Ogg Vorbis, WAV and more! \ -# As of version 7.7 it also supports UPnP clients, serving pictures and movies too! -### END INIT INFO -# - -if [[ -n $(grep -i -E "(redhat|centos|fedora)" /etc/os-release 2>/dev/null) || -f /etc/redhat-release ]] ; then - redhat=yes - - # Source function library. - . /etc/rc.d/init.d/functions - # Source networking configuration. - . /etc/sysconfig/network - # Check that networking is up. - [ "${NETWORKING}" = "no" ] && exit 0 - - # Check for existence of needed config file and read it - LYRION_CONFIG=/etc/sysconfig/lyrionmusicserver - test -r $LYRION_CONFIG || { echo "$LYRION_CONFIG not existing"; - if [ "$1" = "stop" ]; then exit 0; - else exit 6; fi; } - - # Read config - . $LYRION_CONFIG - - # Check for missing binaries (stale symlinks should not happen) - # Note: Special treatment of stop for LSB conformance - LYRION_BIN="$LYRION_HOME/lyrionmusicserver" - test -x $LYRION_BIN || { echo "$LYRION_BIN not installed"; - if [ "$1" = "stop" ]; then exit 0; - else exit 5; fi; } - - LOCKFILE="/var/lock/subsys/lyrionmusicserver" - RETVAL=0 - - start() { - echo -n "Starting Lyrion Music Server: " - daemon --user $LYRION_USER $LYRION_BIN $LYRION_ARGS - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch $LOCKFILE - return $RETVAL - } - - stop() { - echo -n "Stopping Lyrion Music Server: " - # Support old versions of RHEL and still fix bug 5620 - KILLPROC_ARGS="" - if [ `grep -c 'Usage: killproc.*-d delay' /etc/init.d/functions` -ge 1 ]; then - KILLPROC_ARGS="-d 6" - fi - killproc $KILLPROC_ARGS $LYRION_BIN - RETVAL=$? - if [ $RETVAL -ne 0 ]; then - # If killproc fails, try killall (fix for RHEL4) - killall lyrionmusicserver - RETVAL=$? - [ $RETVAL -eq 0 ] && echo_success - [ $RETVAL -ne 0 ] && echo_failure - fi - echo - [ $RETVAL -eq 0 ] && rm -f $LOCKFILE - return $RETVAL - } - - restart() { - stop - sleep 5 - start - } - - condrestart() { - [ -f $LOCKFILE ] && restart || : - } - - fdr_status() { - status $LYRION_BIN - RETVAL=$? - } - -elif [[ -n $(grep -i -E "(suse|sles)" /etc/os-release 2>/dev/null) || -f /etc/SuSE-release ]]; then - suse=yes - - # Check for existence of needed config file and read it - LYRION_CONFIG=/etc/sysconfig/lyrionmusicserver - test -r $LYRION_CONFIG || { echo "$LYRION_CONFIG not existing"; - if [ "$1" = "stop" ]; then exit 0; - else exit 6; fi; } - - # Read config - . $LYRION_CONFIG - - # Check for missing binaries (stale symlinks should not happen) - # Note: Special treatment of stop for LSB conformance - LYRION_BIN="$LYRION_HOME/lyrionmusicserver" - test -x $LYRION_BIN || { echo "$LYRION_BIN not installed"; - if [ "$1" = "stop" ]; then exit 0; - else exit 5; fi; } - - # Source rc.status and reset - . /etc/rc.status - rc_reset - - start() { - echo -n "Starting Lyrion Music Server: " - export HOME=$LYRION_HOME - startproc -u $LYRION_USER $LYRION_BIN $LYRION_ARGS - rc_status -v - } - - stop() { - echo -n "Stopping Lyrion Music Server: " - killproc -TERM $LYRION_BIN - rc_status -v - } - - restart() { - $0 stop - $0 start - rc_status - } - - condrestart() { - $0 status - if test $? = 0; then - $0 restart - else - rc_reset - fi - rc_status - } - - fdr_status() { - /sbin/checkproc $LYRION_BIN - rc_status -v - } - -else - echo "Unable to detect Linux distribution." - exit 1 -fi - -# Do not change this, it will most likely break the lyrionmusicserver -# installation. The directory /usr/lib/perl5/vendor_perl is where the RPM -# package drops the Slim perl modules. Setting PERL5LIB to this location will -# make sure that the Lyrion Music server executable looks here before it scans the -# directories in the perl @INC array. -export PERL5LIB="/usr/lib/perl5/vendor_perl" - -# See how we were called. -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|reload|force-reload) - restart - ;; - condrestart|try-restart) - condrestart - ;; - status) - fdr_status - ;; - *) - echo "Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}" - exit 1 -esac - -if [[ -n "$redhat" ]]; then - exit $RETVAL -elif [[ -n "$suse" ]]; then - rc_exit -else - exit 1 -fi diff --git a/redhat/lyrionmusicserver.logrotate b/redhat/lyrionmusicserver.logrotate index 90dfbf22..eb49db02 100644 --- a/redhat/lyrionmusicserver.logrotate +++ b/redhat/lyrionmusicserver.logrotate @@ -1,9 +1,14 @@ +# We rely on some of the settings made +# in the global logrotate.conf. That way +# the set-up will be in line with the +# different distribution's defaults. /var/log/lyrionmusicserver/server.log { missingok notifempty sharedscripts postrotate - /bin/kill -USR1 `pgrep lyrionmusicserver >/dev/null 2>&1` >/dev/null 2>&1 || true + # send USR1 to main lyrionmusicserver process to reset logging + /usr/bin/systemctl --kill-whom=main --signal=USR1 kill lyrionmusicserver.service endscript } diff --git a/redhat/lyrionmusicserver.preset b/redhat/lyrionmusicserver.preset new file mode 100644 index 00000000..8be4cda0 --- /dev/null +++ b/redhat/lyrionmusicserver.preset @@ -0,0 +1,6 @@ +#------------------------------------------------------------------------------- +# We want the lyrionmusicserver to be enabled immediately after installation. +# The reason is that all configuration is performed via the web-GUI. There is +# no configurations to be done on the command line or manually in files. +#------------------------------------------------------------------------------- +enable lyrionmusicserver.service diff --git a/redhat/lyrionmusicserver.service b/redhat/lyrionmusicserver.service index da7e7e00..c255014a 100644 --- a/redhat/lyrionmusicserver.service +++ b/redhat/lyrionmusicserver.service @@ -8,20 +8,12 @@ After=network.target # directory /etc/systemd/system/lyrionmusicserver.service.d # Read man page for systemd.unit and systemd.service. # -# Or they can be overriden in /etc/sysconfig/lyrionmusicserver -# The first option is recommended. -Environment="LYRION_HOME=/usr/libexec" Environment="LYRION_CFG_DIR=/var/lib/lyrionmusicserver/prefs" Environment="LYRION_LOG_DIR=/var/log/lyrionmusicserver" Environment="LYRION_CACHE_DIR=/var/lib/lyrionmusicserver/cache" Environment="LYRION_CHARSET=utf8" Environment="LYRION_ADDITIONAL_ARGS=" -# The content of this file will override any setting made with the Environment -# variables here above. It will also override any Environment variables set -# in /etc/systemd/system/lyrionmusicserver.service.d/*.conf -EnvironmentFile=-/etc/sysconfig/lyrionmusicserver - # Do not change this, it will most likely break the lyrionmusicserver # installation. The directory /usr/lib/perl5/vendor_perl is where the RPM # package drops the Slim perl modules. Setting PERL5LIB to this location will @@ -29,7 +21,6 @@ EnvironmentFile=-/etc/sysconfig/lyrionmusicserver # directories in the perl @INC array. Environment="PERL5LIB=/usr/lib/perl5/vendor_perl" -#Type=simple User=lyrionmusicserver Group=lyrionmusicserver ExecStart=/usr/libexec/lyrionmusicserver --prefsdir $LYRION_CFG_DIR --logdir $LYRION_LOG_DIR --cachedir $LYRION_CACHE_DIR --charset $LYRION_CHARSET $LYRION_ADDITIONAL_ARGS diff --git a/redhat/lyrionmusicserver.spec b/redhat/lyrionmusicserver.spec index 3e2b9460..f06ef5bb 100644 --- a/redhat/lyrionmusicserver.spec +++ b/redhat/lyrionmusicserver.spec @@ -84,15 +84,17 @@ License: GPL and proprietary URL: https://www.lyrion.org Source0: %{src_basename}.tgz Source1: %{shortname}.config -Source2: %{shortname}.init Source3: %{shortname}.logrotate Source4: %{shortname}.service Source5: README.systemd Source6: README.rebranding +Source7: %{shortname}.preset BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot Vendor: Lyrion Community +BuildRequires: systemd-rpm-macros +%systemd_requires Requires(pre): /usr/bin/getent Requires(pre): /usr/bin/touch Requires(pre): /usr/sbin/groupadd @@ -103,8 +105,14 @@ Requires(post): /usr/bin/ln Requires(post): /usr/bin/mv Requires(post): /usr/bin/rm Requires(post): /usr/sbin/usermod -Requires: perl >= 5.10.0 -Recommends: perl(IO::Socket::SSL) +# The following is needed to ensure that we get the right version of Perl. +# The perl(:VERSION) is for RedHat flavours, the perl >= is for SUSE flavours. +Requires: ((perl >= 5.22 or perl(:VERSION) >= 5.22) with ( perl < 5.43 or perl(:VERSION) < 5.43)) + +# This one is needed on RedHat flavour versions 8 and 9 +# Without it there will be necessary perl modules missing. +Requires: perl +Requires: perl(IO::Socket::SSL) Provides: %{src_basename} = %{version}-%{release} Obsoletes: logitechmediaserver @@ -145,7 +153,8 @@ rm -rf CPAN/arch/*/MSWin32-x86-multi-thread rm -rf $RPM_BUILD_ROOT # FHS compatible directory structure -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d +mkdir -p $RPM_BUILD_ROOT%{_unitdir} +mkdir -p $RPM_BUILD_ROOT%{_presetdir} mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{shortname} mkdir -p $RPM_BUILD_ROOT%{_usr}/lib/perl5/vendor_perl @@ -181,13 +190,13 @@ cp -p gdresized.pl $RPM_BUILD_ROOT%{_usr}/libexec/%{shortname}-resized ln -s %{_var}/lib/%{shortname}/Plugins \ $RPM_BUILD_ROOT%{_datadir}/%{shortname}/Plugins -# Install init, configuration and log files +# Install service, configuration and log files install -Dp -m755 %SOURCE1 $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/%{shortname} -install -Dp -m755 %SOURCE2 $RPM_BUILD_ROOT%{_datadir}/%{shortname}/%{shortname}.SYSV install -Dp -m644 %SOURCE3 $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{shortname} -install -Dp -m644 %SOURCE4 $RPM_BUILD_ROOT%{_datadir}/%{shortname}/%{shortname}.service +install -Dp -m644 %SOURCE4 $RPM_BUILD_ROOT%{_unitdir}/%{shortname}.service install -Dp -m644 %SOURCE5 $RPM_BUILD_ROOT%{_datadir}/%{shortname}/README.systemd install -Dp -m644 %SOURCE6 $RPM_BUILD_ROOT%{_datadir}/%{shortname}/README.rebranding +install -Dp -m644 %SOURCE7 $RPM_BUILD_ROOT%{_presetdir}/50-%{shortname}.preset touch $RPM_BUILD_ROOT%{_var}/lib/%{shortname}/prefs/server.prefs touch $RPM_BUILD_ROOT%{_var}/lib/%{shortname}/prefs/log.conf cp -p convert.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{shortname} @@ -281,7 +290,10 @@ function checkConfigMigration () { return 0 } +test -f /tmp/squeezerpmdebug && echo "pre script" test -f /tmp/squeezerpmdebug && set -x + +# Create user and group if needed. /usr/bin/getent group %{groupd} >/dev/null || /usr/sbin/groupadd -r %{groupd} /usr/bin/getent passwd %{userd} >/dev/null || \ /usr/sbin/useradd -r -g %{groupd} -d %{_datadir}/%{shortname} -s /sbin/nologin \ @@ -292,97 +304,14 @@ test -f /tmp/squeezerpmdebug && set -x # configuration is necessary checkConfigMigration +# The following deals with the handling of the unit file so that +# the service is initialised according to the packaging rules. +%systemd_pre %{shortname}.service + exit 0 %post -function parseSysconfigSqueezeboxserver { - - test -f /tmp/squeezerpmdebug && set -x - - # Some simple checks on the /etc/sysconfig/squeezeboxserver - # No guarantees that these checks will catch all changes that may have - # been made that might have an impact on the move to systemd - . %{_sysconfdir}/sysconfig/%{shortname} - if [ "$LYRION_USER" != "%{userd}" ] ; then - echo "" - echo "#######################################################################" - echo "You seem to have changed the user id used to run %{shortname}." - echo "Please read %{_datadir}/%{shortname}/README.systemd to find out" - echo "how transfer this change to the new systemd set-up." - echo "#######################################################################" - echo "" - fi - - # Check if any additions to the LYRION_ARGS variable have been made. - # Do that by filter out the ones we know should be there. - extra=`echo $LYRION_ARGS |/usr/bin/perl -lane 'print foreach grep { not m/^(?:--daemon|--prefsdir|--logdir|--cachedir|--charset)(?:=|$)/ } @F'` || : - if [ -n "$extra" ] ; then - echo "" - echo "#######################################################################" - echo "You seem to have changed the LYRION_ARGS variable in %{_sysconfdir}/sysconfig/%{shortname}." - echo "Please read %{_datadir}/%{shortname}/README.systemd to find out" - echo "how transfer this change to the new systemd set-up." - echo "#######################################################################" - echo "" - fi -} - -function setSYSV { - - test -f /tmp/squeezerpmdebug && set -x - - # This is a SYSV server. Copy SYSV script to the correct place. - /usr/bin/cp -p %{_datadir}/%{shortname}/%{shortname}.SYSV %{_sysconfdir}/init.d/%{shortname} >/dev/null 2>&1 || : - - # Koozali SME Server pre version 10 uses SYSV init and uses runlevel 7 - # I have no idea if the release file is still called /etc/e-smit-release. - if [ -f /etc/e-smith-release -a -d /etc/rc7.d ] ; then - /usr/bin/ln -sf %{_sysconfdir}/init.d/%{shortname} /etc/rc7.d/S80%{shortname} >/dev/null 2>&1 || : - db configuration set %{shortname} service status enabled >/dev/null 2>&1 || : - fi - - # Check if we are moving from squeezeboxserver to lyrionmusicserver - # if we are, then we must explicitly stop the squeezeboxserver, - # otherwise the start of the lyrionmusicserver will fail. - if [ -f /var/tmp/SqueezeToLyrion ]; then - /sbin/service squeezeboxserver stop || : - /usr/bin/rm -f /var/tmp/SqueezeToLyrion || : - fi - - /sbin/chkconfig --add %{shortname} >/dev/null 2>&1 || : - /sbin/service %{shortname} restart >/dev/null 2>&1 || : -} - -function setSystemd { - - test -f /tmp/squeezerpmdebug && set -x - # The SME server (now a days Koozali SME) started using systemd with - # version 10 (based on CentOS 7). Next version is based on Rocky Linux. - # So we don't need any special handling for Koozali SME here. - - if [ -n "$migrate" ] ; then - # If we currently are running through a SYSV script. First stop - /sbin/service %{shortname} stop >/dev/null 2>&1 || : - /sbin/chkconfig --del %{shortname} >/dev/null 2>&1 || : - # We should not remove the old SYSV init file. The RPM - # package will take care of this when we do an upgrade. - fi - - # Check if we are moving from squeezeboxserver to lyrionmusicserver - # if we are, then we must explicitly stop the squeezeboxserver, - # otherwise the start of the lyrionmusicserver will fail. - if [ -f /var/tmp/SqueezeToLyrion ]; then - /usr/bin/systemctl stop squeezeboxserver.service >/dev/null 2>&1 || : - /usr/bin/rm -f /var/tmp/SqueezeToLyrion || : - fi - - /usr/bin/cp -p %{_datadir}/%{shortname}/%{shortname}.service /usr/lib/systemd/system/%{shortname}.service || : - /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || : - /usr/bin/systemctl enable %{shortname}.service >/dev/null 2>&1 || : - /usr/bin/systemctl restart %{shortname}.service >/dev/null 2>&1 || : -} - function migrateSqueezeboxServerConfig { test -f /tmp/squeezerpmdebug && set -x @@ -450,105 +379,75 @@ function migrateSqueezeboxServerConfig { echo "Server. All Components of the software have been re-branded from" echo "squeezeboxserver to lyrionmusicserver." echo "To stop and start the software use:" - echo "systemd start lyrionmusicserver (on systemd systems)" - echo "/sbin/service lyrionmusicserver start (on SYSV Init systems)." + echo "systemd start lyrionmusicserver" echo "and analogous for stop, status etc." echo "" - echo "If you have made changes to /etc/sysconfig/squeezeboxserver, then you" - echo "must transfer those changes yourself to /etc/sysconfig/%{shortname}." echo "" echo "For more information, read %{_datadir}/%{shortname}/README.rebranding." + echo "For more information, read %{_datadir}/%{shortname}/README.systemd." echo "################################################################################" echo "" } +test -f /tmp/squeezerpmdebug && echo "post script" test -f /tmp/squeezerpmdebug && set -x -# Source /etc/os-release to find out what kind of system we are on. -# We will use ID_LIKE and ID from this file -. /etc/os-release || : - -# If the SYSV init script exists and the server uses systemd -# then migrate to systemd unit file. -if [ -e /etc/init.d/%{shortname} -a -x /usr/bin/systemctl ] ; then - migrate=true -fi - # Check if we need to migrate a squeezeboxserver config to lyrion music server - if [ -f /var/tmp/migrateSqueezeboxserverConfig ]; then migrateSqueezeboxServerConfig fi -if [ ! -x /usr/bin/systemctl ] ; then - setSYSV +# The following continues the initialisation of the service from +# the pre script. It will use the systemd.preset files to decide +# whether the service should be enabled or disabled by default. +%systemd_post %{shortname}.service + +# Here is an anomaly that I introduce to honour the long standing +# tradition that the Lyrion Music Server is started immediately +# if it is a first time installation. This of course contradicts +# the packaging rules of Fedora/SUSE et al +if [ "$1" -eq "1" ] ; then + # This is a first time install. + /usr/bin/systemctl start %{shortname}.service || : + + PORT=`/usr/bin/perl -lane 'if ( /^httpport:/) {print $F[1]; exit}' %{_var}/lib/%{shortname}/prefs/server.prefs` || : + [ -z "$PORT" ] && PORT=9000 + HOSTNAME=`uname -n` || : + echo "Point your web browser to http://$HOSTNAME:$PORT/ to configure Lyrion Music Server." || : else - setSystemd + # The following should normally be done in the postun script, + # but as versions before 9.2 did not use the systemd_* macros to initialise + # the service according to the packaging rules and the postun script was + # empty, we need to do this here. + # This bit of code should eentually be removed when we think most of the users are on + # version 9.2 or newer. + /usr/bin/systemctl try-restart %{shortname}.service || : fi -PORT=`/usr/bin/perl -lane 'if ( /^httpport:/) {print $F[1]; exit}' %{_var}/lib/%{shortname}/prefs/server.prefs` -[ -z "$PORT" ] && PORT=9000 -HOSTNAME=`uname -n` - -if [ -n "$migrate" ] ; then - echo "Lyrion Music Server was migrated from old style SYSV to systemd start-up." - parseSysconfigSqueezeboxserver || : -fi +exit 0 -echo "Point your web browser to http://$HOSTNAME:$PORT/ to configure Lyrion Music Server." %preun +test -f /tmp/squeezerpmdebug && echo "preun script" test -f /tmp/squeezerpmdebug && set -x -function unsetSYSV { +# Use this macro to ensure proper +# handling of the service. +%systemd_preun %{shortname}.service - /sbin/service %{shortname} stop >/dev/null 2>&1 || : - if [ -f /etc/e-smith-release -a -d /etc/rc7.d ] ; then - #SME Server uses runlevel 7 - db configuration set %{shortname} service status disabled >/dev/null 2>&1 || : - /usr/bin/rm /etc/rc7.d/S80%{shortname} || : - fi - /sbin/chkconfig --del %{shortname} >/dev/null 2>&1 || : - # Remove the SYSV file we copied in the post script. - /usr/bin/rm -f /etc/init.d/%{shortname} || : -} - -function unsetSystemd { - - # systemd - /usr/bin/systemctl unmask %{shortname}.service >/dev/null 2>&1 || : - /usr/bin/systemctl disable %{shortname}.service >/dev/null 2>&1 || : - /usr/bin/systemctl stop %{shortname}.service >/dev/null 2>&1 || : - # Remove the unit file we copied in the post script. - /usr/bin/rm -f /usr/lib/systemd/system/%{shortname}.service || : - /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || : - -} - -. /etc/os-release || : - -if [ "$1" -eq "0" ] ; then - # If not upgrading - - # First stop and removethe start-up script/unit file. - if [ ! -x /usr/bin/systemctl ] ; then - - unsetSYSV - - else - - unsetSystemd - - fi - -fi +%postun +test -f /tmp/squeezerpmdebug && echo "postun script" +test -f /tmp/squeezerpmdebug && set -x +# Use this macro to ensure proper +# handling of the service. +%systemd_postun_with_restart %{shortname}.service -%postun +exit 0 %files @@ -578,6 +477,10 @@ fi %attr(0644,%{userd},%{groupd}) %ghost %{_var}/log/%{shortname}/server.log %attr(0644,%{userd},%{groupd}) %ghost %{_var}/log/%{shortname}/scanner.log +# Systemd service file and preset file. +%attr(0644,root,root) %{_unitdir}/%{shortname}.service +%attr(0644,root,root) %{_presetdir}/50-%{shortname}.preset + # Configuration files and init script %dir %{_sysconfdir}/%{shortname} %attr(0755,%{userd},%{groupd}) %dir %{_var}/lib/%{shortname}/prefs @@ -605,6 +508,21 @@ fi %changelog +* Sat Feb 28 2026 Johan Saaw +- Removed support for Sys V Init. RedHat and SUSE based distros + moved to systemd many years ago. Also removed support for + /etc/sysconfig/lyrionmusicserver +- Added systemd as pre-requisite with the %systemd_requires macro. +- Added BuildRequires systemd-rpm-macros +- Added use of systemd_pre, systemd_preun, systemd_post and + systemd_postun_with_restart to initialise and handle the unit + file and service correctly. +- Added a systemd preset file to enable lyrionmusicserver at + installation time. +- Added logic to start lyrionmusicserver immediately during + install if it is a first time installation. Upgrades will + follow the packaging rules. + * Mon Oct 20 2025 Peter Oliver - Drop support for Perl versions not currently seen in usage stats.