Sunday, May 24, 2009

On demand start/stop SqueezeCenter possible?

My main gripe with SqueezeCenter is the ridiculous amount of RAM (around 90MB) it requires to run. On the DNS-323 which has only 64MB of RAM, this means constant virtual memory swapping even when the process is idle (i.e. not serving any clients).

This is rather annoying as it means the disks in the NAS can no longer spin down even when there are no user accessing the box. It has also made redundant all my previous efforts in getting the disks to spin down as often as possible (e.g. moving ffp, mysql db and www pages to a USB stick).

To get back my desired behaviour, I have three options:
  1. Upgrade to 128MB of physical RAM
  2. Run Squeezed (a lightweight alternative) instead of SqueezeCenter
  3. Start/Stop SqueezeCenter on demand
The first option is my preferred option as it should improve overall performance and not just for SqueezeCenter. However, it is extremely risky (changes of bricking your box is very high) as it involves some hardware modification and low level bios code hacking. Not recommended for the faint hearted and those under warranty. (And I just so happen to fall into both categories)

The second option seems like a good idea but it is really basic right now and lacks a lot of SqueezeCenter's features. Perhaps some time in the future I will reconsider this option.

The third option is a good compromise between having the full feature set of SqueezeCenter and getting my power-saving mode back when my SqueezeBox Boom is turned off. The only drawback is that there is a 2-3 minutes wait (for starting the monster up on the DNS-323) before the SqueezeBox Boom gets connected to SqueezeCenter when it is powered on.

I followed the instructions in Yannick's post and managed to get it working on my box with little trouble. I also made a number of changes to make it more robust, configurable and fit the ffp environment better. If you have followed my previous post on getting SqueezeCenter running on the DNS-323, you may find this approach more friendly.

In addition, I created a startup script for the standby daemon so that ffp will start the standby daemon rather than SqueezeCenter on boot/reboot. The assumption here is that I most likely do not need SqueezeCenter when I boot/reboot the box and I rather let a SqueezeBox client trigger the startup of SqueezeCenter than to have it unnecessarily load up my boot process and increase the boot time.

Here's a log of what I did to get this setup working in my environment:
  1. Set up standby daemon script
    1. Download and install script (link)
      # cd /ffp
      # wget -O standby_daemon.tar.gz
      # tar -xzvf standby_daemon.tar.gz
      # rm standby_daemon.tar.gz
    2. Configure sudoers to allow user nobody to trigger the script without password. [IMPT: do not blindly copy the code below! replace {your_hostname} with your real hostname!]
      # cd /ffp/etc
      # chmod u+w sudoers
      # echo "nobody {your_hostname}= NOPASSWD: /ffp/sbin/" >> sudoers
      # chmod u-w sudoers
  2. Set up SqueezeCenter plugin - Server Power Control
    1. Download and install plugin from here
      # cd /ffp/lib/squeezecenter/Plugins/
      # wget -O
      # unzip
      # rm
    2. Restart SqueezeCenter to load the newly installed plugin.
    3. Go to the settings page of the plugin (Settings>Plugins, look for Server Power Control and click on settings on the right) after SqueezeCenter has restarted
    4. Check the first two options (Shutdown and Shutdown to SqueezeNetwork) and enter "sudo /ffp/sbin/" in the textbox below it (both of them). Leave the rest of the options unchecked as we can't use them on the DNS-323.
    5. At the end of the settings dialog, select the option Monitor idle Players and select Shutdown server for the field Action to take after idle time. Optionally you can also setup the same in End of day action with a shorter idle time.
    6. Save the settings and you are done.

  3. [Optional] Start standby daemon instead of SqueezeCenter on boot/reboot
    # cd /ffp/start
    # chmod a-x
    # chmod a+x
  4. Tips and Tricks
    1. The standby daemon outputs a log file called standby_daemon.log in SqueezeCenter's log directory (i.e. /ffp/lib/squeezecenter/Logs/). It records the timestamps of the shutdown and startup events which I find useful for tracking the uptimes as well as for debugging purposes.
    2. The default settings in the standby daemon script does not shutdown MySQL. (My instance of MySQL is used for other purposes hence I have to let it run independently). If you wish to have the script manage that, change the var $stop_mysql from 0 to 1. The script will, however, start MySQL if its not already running regardless of this setting. (Make sense right?!)

A couple of things still need to be sorted out in this setup:
  1. Wakeup prior to alarm - Since SqueezeCenter is no longer running all the time, alarms that plays from SqueezeCenter will not work. Initial idea is to modify script to set up a cron job to wake SqueezeCenter a few minutes prior to the alarm being triggered. Note that this should not affect you if your alarms are set on SqueezeNetwork and you have configured Server Power Control to automatically switch you to SqueezeNetwork when SqueezeCenter is being shutdown.
  2. Scheduled music library scans - Since SqueezeCenter is no longer running all the time, the scheduled daily scans may not be taking place anymore. Initial idea is to modify script to look for this setting and setup a cron job for it when the daemon is active.
I do not have any urgency to get these features working as I currently do not use them. I will probably get round to them if there is demand for it.


Anonymous said...

Hi Sidney,
it is great that you could improve my original script on this (I am really not a perl programmer ;-).
Note that I have posted a solution how to reduce the 2min waiting time before the server is up in the slimdevices forum:


Anonymous said...

Hi Sidney,
Is it an idea to make the shutdown part in the script easier by using the CLI-interface of Squeeze Server itself? There is a "shutdown" command. I don't know (but you surely do) how to send that string to the correct port (default is 9090). Is that easy to do?