Sunday, September 9, 2012

Installing MPD on Ubuntu Server

I have been working on a project for my 1 1/2 year old daughter this weekend and just got it working before church this morning. We have a stereo/cd deck in her room and while useful for helping her to go sleep from time to time, there was no way to turn it on or control it without going into her room. Generally, she would wake up more seeing us in her room and would cry/beg for us to get her out of bed if we had to go back in and put some music on to help her go to sleep.

Enter MPD (Music Player Daemon). MPD is a service (a.k.a. daemon in GNU/Linux terms) that allows you to play music from a remote system's hard drive through that same remote system's audio hardware letting you control it from your local system (as I am using it; it does more, but I haven't fully explored it yet). There are many clients you can use to control the music service (Android, Linux, Microsoft, Apple).

The Setup

I already have a FoxConn nt330i nettop running Ubuntu 10.04 x86 Server dedicated to my daughter Summer hosting a motion server that streams a webcam feed of her crib to our local network allowing my wife to check on her during nap times (the grandparents have access too since they live in other states). I figured I could find a way to add in some sort of media playback even though this is a "headless" server (no keyboard or screen hooked up to it, and no GUI running; just a command line server). I found some cheap Harmon/Kardon desktop speakers I had stored away in a box and plugged them in, turned them on, and set them at a medium volume level. I did some Google searches and came across several explanations of basic setups for MPD on desktop versions of Ubuntu, but nothing clear on how to set this all up start to finish on a headless box which does not have any audio playback support by default. This lead me to document what I did in this blog entry should I need to do it again or should someone else be in the same boat as me and not know what pieces are missing from the server version to get the full audio setup working.

Getting It Working

These steps will get you from a clean Ubuntu 10.04 x86 Server install to working MPD controlled by a remote client.
  1. Install Ubuntu 10.04 Server (x86-64 should work, I have only tested on x86). Install options shouldn't affect the rest of this guide, so pick what you normally do when setting up a new box. This should work on other versions of Ubuntu, Debian, Debian-based, or any other version of Linux, but you might have to find your own sources for these packages, resolve dependencies, and compile from source. Test in a virtual machine if you want to try out a different OS. Or you could use Ubuntu.
  2. Install software that is needed for audio, MP3, and MPD.
  3. sudo apt-get install alsa lame mpd
  4. Set your sound levels using the Alsa sound mixer
    sudo alsamixerYou will see a picture like below with your sound output options. Make sure the output you are using is turned up and that the box at the bottom of that channel doesn't have an "m" in it ("m" signifies it is muted). I am using the front audio out jack so I have adjusted the channels marked "master" and "front" using the left and right arrows to select each channel, the "m" key to unmute it, and the up and down arrow keys to adjust the volume level (by default everything is muted and turned all the way down).
    Alsa Mixer
  5. Set your MPD options. Generally all you need to do is make note of the music_directory parameter and the bind_to_address parameter. The music_directory can be anything you want (I set mine to /music and copied all my music into that folder). The bind_to_address is set to "localhost" by default in Ubuntu even though the config file says the default is "any". I set mine to any just in case my IP address changes. You can hard code yours to match your IP address if you want.
    sudo nano /etc/mpd.conf
    update the two lines below in this file
    music_directory        /music
    bind_to_address       any
    press ctrl+o to save (output) the file, followed by ctrl+x to exit the file
  6. Create your music directory if it does not exist.
    sudo mkdir /music
  7. Copy your music into the music directory. You can copy it from a USB flash drive or somewhere on the network for example. I have a central home server that all my data is backed up to and hosted on, so I used rsync to copy all of my MP3s to Summer's computer. Notice the trailing slashes on the paths in rsync. Those are important (and a discussion for another time).
    sudo rsync username@sourceserver:/all/of/my/music/ /music/
  8. Set the music directory permissions. As noted in the mpd.conf file, the mpd user needs read access on the music, and since this isn't private tax data, I just set it to read all for all users.
    sudo chmod -R a+r /music
  9. Restart MPD to apply new settings.
    sudo service mpd restart
    If you get any error messages after issuing this command such as "could not bind to address x.x.x.x" or "failure to read from /music (or whatever you put for your music_directory)" double check the edits you just made by revisiting step 5 paying special attention to anything that might have a typo or wrong IP address in it.
  10. Connect to the server using whatever MPD supporting client you wish (I use an Android app on my tablet, my wife uses a Windows 7 client on her laptop). A list of these clients can be found on the MPD wikia link above. Consult the application's documentation for how to configure connection settings.
  11. Queue up music and see if it works! You might want to start with lower audio levels than what I did, these setting worked for me, but yours may turn out a lot louder depending on what soundcard and speakers you have.
Now Summer falls asleep from time to time with the soothing sounds of Native American flutes or classic lullabies. Since she is still teething, the music helps her relax and fall asleep faster, and can help calm her down when she wakes up with a particularly bad tooth ache. I just started some more quiet flute music for her while typing this when I noticed her fuss a little in her sleep on the webcam.

Thursday, August 16, 2012

Monitoring the Network

I have been deploying PRTG at my new job this week and thought I would write a quick post about the subject. Basically PRTG is an all encompassing solution for monitoring local and remote IT infrastructure. We have a central office with four remote offices that are staffed, and systems in an additional three datacenters. I need to know instantly when the internet goes down at either of two remote sites that have particularly bad DSL service so I can call the staff and have them power cycle the DSL modem as an attempt to restore service. I have PRTG configured to e-mail me if anything goes wrong, day or night, as well as the Android app on my phone and tablet if I happen to be at home and not watching my company inbox. The solution is fast and reliable, with remote probes at each site to continue logging performance and uptime on servers in spite of poor internet reliability. In short, it tells me exactly what is wrong before users call and complain. For more info, take a look at http://www.paessler.com/prtg. Enjoy!

Change: The Only Constant

It has been a while since I have written any updates, mainly because so much has been changing lately, I have not had any time to sit and type. I got laid off from Computronix USA Inc due to downsizing, found a new job at almost double the pay managing the entire network/server infrastructure including the main office, four remote offices around the mid-west, and three remote datacenters. Things are growing so fast, that I'm working a ton to keep up with fixes and deploying new equipment, but the work is good, and I enjoy it.

Summer is still growing like a weed, and is learning more sign language and is trying to talk a little. She runs to the door to greet me every day when I get home. She is a wonderful child!

Tuesday, February 7, 2012

Feeling Secure Does Not Mean You Are Secure

I am putting together a presentation on basic Internet security best practices for our Annual General Meeting this Friday that I will be presenting with my brother-in-law to our office as part of a day of informative sessions covering work-related and non-work topics. We are planning to cover the basics of passwords, firewalls, and anti-malware software, and there might even be a guest appearance of a weaponized pineapple or perhaps a reaver will show up and ruin someone's day. You just never know what might happen on the Internet these days.... Now, where do I find some lolcatz hacking into people's e-mail accounts.

Saturday, January 7, 2012

Winter Sports

Had a great day shooting today. My rifle scope is way off, so I'll be working on that in the coming weeks if I get time. The shotgun is performing well, and the pistols are still very nice. I need to work out a steadier trigger pull, but other than that, my shooting is staying on target. It sure is cold sighting in a rifle with snow pouring down....

Wednesday, January 4, 2012

Sunshine in Winter

Summer is a wonderful child. She is soooooo cute! She is perfectly happy to play all on her own as long as you are sitting on the floor by the couch in our living room. If you sit on the couch, she comes over and bugs you to play with her. She is such a social ladybug!