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 http://forum.dsmg600.info/attachment.php?item=497
      # 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/slimserver_standby_daemon.pl" >> 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 SrvrPowerCtrl.zip http://forums.slimdevices.com/attachment.php?attachmentid=7357&d=1241562529
      # unzip SrvrPowerCtrl.zip
      # rm SrvrPowerCtrl.zip
    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/slimserver_standby_daemon.pl" 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 slimserver.sh
    # chmod a+x slimserver_standby_daemon.sh
  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.

Thursday, May 21, 2009

Setting up SqueezeCenter on DNS-323


One of the best features of the Squeezebox Boom (or any other SqueezeBox devices for that matter) is the ability to remotely control it as well as to stream your own music collection to it. But to do this, you will need to install and run a server software called the SqueezeCenter somewhere on your network. The ideal place to host it will be where you store your music library and in my case, that would be my SOHO NAS, the Dlink DNS-323.

Typically, the first question that comes to mind when you need to install and run a software is the OS platform and hardware requirements. The good news is that SqueezeCenter is written in Perl and stores its data in a MySQL database hence will run on any OS platform which supports those two dependencies; And that practically means all common platforms out there e.g. Mac, Linux and Windows.

In terms of hardware requirements, its alittle heavy but nothing a recent PC cannot handle. On the DNS-323 however, it still runs but performance does take quite a hit. In my setup, the memory footprint is around 90MB for SqueezeCenter alone plus another 20MB for MySQL and CPU utilization spikes to 100% often when using the web interface. Note that the DNS-323 has just 64MB of physical RAM and a 500MHz ARM CPU. Having said that, the web interface is still fully usable (no time outs) although you do feel the lagginess with most operations.

Luckily, the weak server hardware does not affect its streaming abilities and so far (er.. that's just a couple of hours usage since I got my box only yesterday), I have not experienced any issues on my SqueezeBox Boom. From my observations, the CPU hardly broke a sweat (>5% usage) when streaming mp3 format natively and the response on SqueezeBox Boom controls are pretty jiffy.

Here's what I did to get SqueezeCenter up and running on the DNS-323:
  1. Get ffp 0.5 up and running (see wiki or my post);
  2. Setup Pre-requisite 1 - MySQL
    1. If you don't already have MySQL running, see this post;
    2. Create a new database and an associated db user for SqueezeCenter (NOTE: db and user should be called slimserver!) :
      # mysql -u root -p
      Enter password: your_root_password

      mysql> create database slimserver;
      mysql> grant all on slimserver.* to slimserver identified by 'your_password';
      mysql> flush privileges;
      mysql> quit
  3. Setup Pre-requisite 2 - Perl
    1. Download and install all the Perl packages found here:
      # wget -r -l1 --no-parent -A.tgz http://www.inreto.de/dns323/fun-plug/0.5/extra-packages/perl/
      # funpkg -i *.tgz
  4. Setup and configure SqueezeCenter
    1. Download and install SqueezeCenter package (squeezecenter-7.3.2-1.tgz);
      # wget http://www.inreto.de/dns323/fun-plug/0.5/extra-packages/squeezecenter/squeezecenter-7.3.2-1.tgz
      # funpkg -i squeezecenter-7.3.2-1.tgz
    2. Configure SqueezeCenter to start automatically when the box boots as well as to start it up now
      # cd /ffp/start
      # chmod a+x slimserver.sh
      # ./slimserver.sh start
    3. When SqueezeCenter starts up, it can take quite a few minutes before the web console becomes accessible. When it does become ready, you can access it via the URL http://[replace with your nas ip or hostname]:9000/
    4. Once you get into the web interface, the first thing you should do is to setup the path to your music collection. If your music collection is scattered all over, you will need create a "holding" directory and create the appropriate symlinks in there as SqueezeCenter only allows you to specify one location.
    5. Next trigger the scanning process to catalog your collection. Given the weak hardware of the DNS-323, the scanning process can take a long time to complete. (My 2000 odd files took 1+ hour to complete!)
  5. SqueezeCenter Tips and Tricks
    1. The location of the SqueezeCenter installation files (including plugins) are found in /ffp/lib/squeezecenter/.
    2. The location of the SqueezeCenter configuration files (including plugins) are found in /ffp/etc/squeezecenter/.
    3. The location of the SqueezeCenter log files are found in /ffp/lib/squeezecenter/Logs/. Since this isn't in line with where all my other logs go, I created a symlink to it at /ffp/var/log/squeezecenter/.
    4. You can set SqueezeCenter to automatically rescan your music collection once a day via the Schedule Rescan function in Settings>Advanced>Rescan Music Library.
    5. To reduce the memory footprint of SqueezeCenter, go to Settings>Plugins and uncheck all the plugins that you do not use. For me, I turned off the following plugins:
      1. Amazon CD Store
      2. Deezer
      3. Digital Inputs
      4. MP3tunes Music Locker
      5. MusicIP
      6. Pandora
      7. Rhapsody
      8. RSS News Ticker
      9. SIRIUS Internet Radio
      10. Slacker
      11. SlimTris
      Restart the slimserver process for the changes to take effect.
    6. If you find the display only shows the time and does not show the date in the "off/Standby" state, it is most likely because of your font setting. Change it (Settings>Player>Display>Standby Font) to "Standard" to see the date information.

    7. The slimserver startup script provided by fonz does not guard against firing multiple instances of the slimserver process. To fix this problem, include the following chunk of code at the top of the slimserver_start() function.

      # check if daemon is already running, if yes, do nothing
      if proc_status $command | grep -q "running as pid"; then
      echo "INFO: ${name} already running! Nothing to do."
      return
      fi
      # check if mysqld is already running, if not, prompt user and exit
      if proc_status "mysqld" | grep -q "not running"; then
      echo "ERROR: mysqld has to be running before ${name} can be started!"
      return
      fi
    8. The pre-configured SqueezeCenter settings uses named pipes for accessing MySQL, if you are having problems like database time-outs; e.g. you can connect to the web console but find that the scanning process did not find all your music files, check in the scanner log (/mnt/usb/ffp/lib/squeezecenter/Logs/scanner.log) for the following error messages:
      Slim::Schema::forceCommit (1496) Warning: Couldn't commit transactions to DB: [DBD::mysql::db commit failed: MySQL server has gone away at /mnt/usb/ffp/lib/squeezecenter/Slim/Schema.pm line 1493.
      ]
      Slim::Schema::Storage::throw_exception (70) Error: DBI Connection failed: DBI connect('database=slimserver','slimserver',...) failed: Can't connect to local MySQL server through socket '/ffp/var/run/mysql/mysql.sock' (2) at /mnt/usb/ffp/lib/squeezecenter/CPAN/DBIx/Class/Storage/DBI.pm line 652
      If it exists, then you may want to change SqueezeCenter to connect to the DB via TCP/IP instead. To do that, in your server config file, change the value of dbsource to "dbi:mysql:hostname=localhost;port=3306".

Overall, I'm very pleased with the setup. The only gripe is that my HDDs no longer spin down when the NAS is idle due to the virtual memory swapping caused by the SqueezeCenter process (which still consumes some CPU even when no clients are active!). I contemplated putting the swap space on the USB stick where ffp lives to circumvent this but decided not to as I'm not confident that my relatively new USB stick can take that kind of abuse (flash drives have limited write cycles). Perhaps its time to go for the 128MB memory upgrade hack!

Saturday, May 2, 2009

Squeezebox Boom is on the way!

As part of my ongoing project to build a connected home, I wanted to add a dedicated network music player for accessing my digital music library. This will complement my current pool of access points which comprises of solely multi-purpose network media players (i.e. XBMC on Xbox, VMC on HTPC and WMP on laptops).

This device will be used mostly as a bedside music player for my kids to access their music collection (yes, they have one!). In addition, I intend to also use it as a portable boombox around the house such as the patio and yard area where I can't access my other media players.

I started looking around for such a device last year and shortlisted a few; the Logictech Squeezebox Boom, Revo Pico WiFi Radio and the Sangean's WFR-20 Wi-Fi Internet Radio.

My top choice is the Squeezebox Boom as I really like the fact that it can work standalone as well as part of a multi-player system (i.e. together with other Squeezebox devices and/or compatible software based player running off standard PC based hardware). Moreover, both modes can be centrally and more importantly, remotely controlled via a web-based interface. This means that I can control my players in or out of the house and via any connected device with a web-browser (e.g. my mobile phone)! And to top it off, you can control them either via a locally hosted application (called the SqueezeCenter) or via the internet version hosted by Logitech (called the SqueezeNetwork).

Unfortunately, the Squeezebox Boom was not available locally and almost a year later, it still isn't. In the mean time, my kids have been bugging me relentlessly about having no access to their music in bed. So yesterday, I took the plunge and bought a Squeezebox Boom off ebay Australia for AUD$300 inclusive of local shipping.

Why Australia? Well, for one thing, I am going to get the overseas shipping free thanks to my cousin Yuan who has a friend returning from Australia in a couple of weeks time. And secondly, it is priced cheaper in Australia than the US. So its a no-brainer really.

ETA for my set to reach my hands is 20th May. In the mean time, I need to start figuring out how to get SqueezeCenter working off my DNS-323!