Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Test whether Moode startup has completed from systemd service file
#1
Hi

The mpd_oled package for Moode installs a systemd service that should start mpd_oled after the Moode startup has completed. This is done with the following (example) service file


Code:
[Unit]
Description=MPD OLED Display

[Service]
ExecStartPre=/usr/bin/mpd_oled_launch_test
ExecStart=/usr/bin/mpd_oled  -o 6 -b 10 -g 1 -f 30 -c alsa,plughw:Loopback,1
TimeoutSec=3min

[Install]
WantedBy=multi-user.target

and the helper script mpd_oled_launch_test:



Code:
#!/bin/bash

sysname="unknown"

moodeutl_path="/usr/local/bin/moodeutl"
volumio_path="/volumio"
raudio_path="/srv/http/command/rune_shutdown"

if test -f "$moodeutl_path" ; then
  sysname="moode"
  # wait for worker to start to ensure start flag is set to 0
  until ps -C worker.php > /dev/null; do
     sleep 2
  done
  sleep 1     # extra time allow to set flag
  until test $(moodeutl -q "select value from cfg_system where param='wrkready'") = "1"; do
     sleep 4
  done

elif test -f "$volumio_path" ; then
  sysname="volumio"
  until ps -C mpd > /dev/null; do
     sleep 10
  done
elif test -f "$raudio_path" ; then
  sysname="raudio"
  until ps -C mpd > /dev/null; do
     sleep 10
  done
fi

With Moode 8.3.2, when mpd_oled is installed the Moode startup never completes, and wrkready is never set to 1, and mpd_oled_launch_test never makes it past the check for this. Eventually the mpd_oled service times out and wrkready is still set to 0.

moodeutil -l says

Code:
pi@moode832:~ $ moodeutl -l
20230503 120814 worker: --
20230503 120814 worker: -- Start moOde 8 series
20230503 120814 worker: --
20230503 120814 worker: Successfully daemonized
20230503 120814 worker: Waiting for Linux startup...
20230503 121133 worker: ERROR: Linux startup failed to complete after waiting 180 seconds

Maybe this relates to the following recent Moode commit

   https://github.com/moode-player/moode/co...a9119e7efc

Is there a way to work around this? How I can test the Moode startup has completed from a systemd service file?

Adrian.
Reply
#2
It looks like a race condition issue given the error below which indicates worker.php has exited after testing for Linux startup complete for 3 minutes. 

Code:
20230503 121133 worker: ERROR: Linux startup failed to complete after waiting 180 seconds

The command being used is:
Code:
systemctl is-system-running

It returns "running" if all systemd units started successfully or "degraded" if one or more units fails to start. It can also return other values but Worker tests for only "running" and "degraded" and considers these values to mean that Linux startup has completed and Worker can proceed with moOde startup which eventually ends with the 'wrkready' param being set to '1'.

So basically worker is in the 3 minute is-system-running loop waiting for all systemd units to complete with success or fail while mpd_oled systemd unit is in the launch test loop waiting for wrkready = 1. This means the mpd_oled systemd unit will not complete and still be in that loop after 3 minutes. At that time worker exits and 'wrkready' param is still  '0'.

Maybe running the launch test script from mpd_oled itself might work because this would allow the systemd unit to complete???
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Hi Tim

I might be able to have the mpd_oled service run the launch check as the ExecStart program, and start mpd_oled in this script after it waits for Moode to start. If this works out, then configuring the service this way should also work on other Player OSs.

Adrian.
Reply
#4
Hi Tim

This is essentially working. mpd_oled starts correctly at boot, the service can be started and stopped. The only issue is that stopping the service now leaves some pixels lit on the OLED, so it appears that when the service stops a script that runs mpd_oled it is not the same as when the service directly stops the mpd_oled process. I can probably fix this with an ExecStop in the service file to stop the mpd_oled process with an appropriate signal.

Adrian.
Reply
#5
Sounds like it should work :-)

I have a question about the until loops. Won't the condition part always return true?

until ps -C worker.php > /dev/null; do

I usually use something like pgrep -c worker.php != 0
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
Hi Tim

When worker.php is not running the ps -C exit status is 1, which is not a success, and the until loop does not break out.
When worker.php is running the ps -C exit status is 0, which is a success, and the until loop breaks out.

E.g. see  https://stackoverflow.com/a/21982743

Adrian.
Reply
#7
Ah yes the shell status $?

Nvm
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#8
Hi everyone,
Could it be possible to test the state of mpd? I tried mpc play and mpc stop immediately: there is probably a better and more elegant way to test this.
Sorry for butting in and best regards,
Francesco
Reply
#9
From script you can test the status if mpd is running as following
Code:
mpc
echo $?

Exit status is 0 when running.
Alternative you can use the exit status of `systemctl status mpd`.

You can also monitor the status of mpd by code. See for example my python script mpd2cdspvolume.
Reply
#10
Hi Francesco

On Volumio and RuneAudio the mpd_oled service waits for mpd to be running before starting mpd_oled. On Moode there is a flag to say that the system startup has completed, and it should help avoid issues to wait for it to be set before running mpd_oled.


Adrian.
Reply


Forum Jump: