Fixing MPD

Once before I had installed MPD, and once before I really liked it. But as always with updates something had to be stuborn. I honestly hadn’t noticed the breakage until I tried to play some music recently with Sonata. I have Sonata configured as to search for new audio on every load up. This time I had added new audio to the music folder and this time I got zip – the playlist showed, well… empty. I looked into /var/lib/mpd/database and sure enough it the listing blanked.

It had been awhile since I installed the Music Player Daemon originally, and though I usually take notes of the process i didn’t’ remember to and I was at a loss at how to repair it. With the Gentoo LInux Wiki down last week, I was at a total loss.

Fixing MPD

The Music Player Daemon for those of you who haven’t tried it, heard it, is exactly as it states: a constant running process on your computer that’s able to play music. I should not say “your” however because many people use MPD on server and listen to audio over a network. What I’m talking about here is setting up MPD as a local daemon as opposed to a remote daemon. Why do this? MPD provides an absurdly low CPU usage and since it is continually running near to zero startup times. Using MPD as a local daemon as opposed to the remote daemon, though both processes will be similar, is different enough. I’ll start at the very beginning.

Install MPD

emerge mpd

Setting Permissions

This is what I had forgotten so many months ago. MPD looks at it’s configuration files and requires them to belong to the audio group and also to the owner listed in the configuration file. I saw this as odd as I failed to see why a daemon needs permissions since it runs as root. This is reasonable I learned if you use MPD as it was originally intended: as a remote daemon. An MPD server would create a user “mpd” and hence have all the proper settings to begin distributing sound. I might argue that MPD is probably installed as a local daemon more often then it is as a remote one…

All these files and folders must have the correct permissions. They need belong to owner:group – youruser:audio.

chown user:audio /var/lib/mpd/* /var/log/mpd/* /var/run/mpd/*

Now we need to tell MPD where to find your audio directory

cd /var/lib/mpd/music
ln -s /home/user/My\ Audio

Setting the Configuration

nano /etc/mpd.conf

There a few details here that will need to be set to have MPD work nicely

To begin make sure info of the pid file is commented out, this is necessary to the init-script to close correctly.

Now replace your username. Since we won’t be running MPD as a separate user we need to set “mpd” for our own.

Configure audio output if you know all the details otherwise the driver settings will be used (which is what you want for most cases.).

Create the Music Database

Now we should have all the settings need to build a proper database.

mpd --create-db

Start the Daemon

/etc/init.d/mpd start

Add the daemon to the run-level

rc-update add mpd default

Troubleshooting MPD

Setting a pid file as a local daemon is little tricky. MPD wants a Personal ID file which is important to close MPD., whether it’s needed or not… In my personal opinion this is an over-site of MPD as it does not create a new pid on initializing but requires one to shutdown. To add the the dilemma, MPD will delete pid on shutdown, meaning that we will have to make one each time MPD is started. The only solution I’ve found to reasonably fix this is to edit the boot script.

nano /etc/init.d/mpd

And add in the checkconfig section:

echo > /var/run/mpd/mpd.pid
chown user:audio /var/run/mpd/mpd.pid

Picking a Client

Since MPD is a daemon it will not play the music directly, we need a client for that. The MPD wiki offers a good number of them.

I no longer use ~.mpdconf because in gentoo I only edit one line to get it up in running. I have in the past though. Only issue is you have to start it manually or via @reboot cron as your username. Init scripts will break with storing the config in your home directory.

Well when I did it i used to have a wrapper script for starting gmpc that would check if mpd was running and start it if it was not. Worked good. I’m the only one on this box though so It was better to let my init scripts manage it in the long run.

Welcome to linuxtidbits.

linuxtidbits is a place for common bits of Linux knowledge. Linux is a good operating system with good people. Being part of Linux, to me, means being a part of something that everyone can contribute to.