Walkthrough: Install MPD from Source as a daemon on Ubuntu

Need help with MPD?
Post Reply
rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Walkthrough: Install MPD from Source as a daemon on Ubuntu

Post by rhoering »

Much of this information came from multiple conversations with a pair of very patient and helpful forum mates, Ran and Conta as well as some spelunking of the old wikia site.


1. Get the Source

From the tar file:

Change to the user's home directory [e.g. 'cd /home/username']

Download the compressed tar file from http://www.musicpd.org/download.html
Decompress the tar to a directory [e.g. '/home/username/mpd-version']
Change to that directory [e.g. 'cd /home/username/mpd-version']

From Git repository:

Change to the user's home directory [e.g. 'cd /home/username']

If you followed my previous SUDO-ized version of the walkthrough [OR you just want to get to a known state]. Remove the old copy of mpd you 'git cloned'

sudo rm -fr mpd

git clone git://git.musicpd.org/master/mpd.git
cd /home/username/mpd
./autogen.sh



2. Set up init.d

The fastest route to getting the init.d setup is to install MPD package using 'sudo apt-get install mpd'.

Please keep in mind the package is most likely an old or even very old version of mpd, so we are do this to just get the init.d script installed.

Copy the /etc/init.d/mpd script to you home directory for safe keeping.

Now uninstall the old MPD package using 'sudo apt-get remove mpd'.


3. Read the INSTALL file and install all the dependencies listed for compiling mpd.

The User Guide [http://www.musicpd.org/doc/user/install_source.html] has a list of dependencies but please confirm that list with the INSTALL file.

[NOTE: The URL changed. If it does again, start at http://www.musicpd.org/ and look for the user manual link]


In my case I was compiling from Git and needed to also install "libicu-dev", i.e. run 'sudo apt-get install libicu-dev'.


4. Confirm you are at the top of the mpd source directory.


5. Run './configure'

Verify that there are no errors and/or missing dependencies.


6. Run 'make'

7. Run 'sudo make install'


Better init.d and/or systemd instructions to be added soon.

If you made a copy of the /etc/init.d/mpd script to your home directory you should be able copy it back. [This seemed to work for me.]


12. Confirm the version of mpd using 'mpd --version'

Hopefully you will see the new version of mpd and you will be off and running.
Attachments
mpd-initd-script.gz
Un-GZip and rename to "mpd". Place in /etc/inet.d directory.
(1.14 KiB) Downloaded 130 times
Last edited by rhoering on September 17th, 2014, 2:51 am, edited 13 times in total.

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

I just found this reference on GIT. It is very cool.

http://rogerdudler.github.io/git-guide/

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

The next part I want to write up is the mpd user, their perms and the init.d setup.

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

Edited to remove sudo.

Addendum for compiling from GIT

After cloning the repository you need to create the configure file [and probably other files] using the following command in the directory where the local git copy is:
./autogen.sh
Now you can run the configure script as stated above and continue.
Last edited by rhoering on September 2nd, 2014, 4:06 am, edited 1 time in total.

Rasi
Forum team
Posts: 141
Joined: January 16th, 2013, 7:29 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by Rasi »

i see absolutely no reason why one should run ./autogen with root privilegs.

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

Rasi,

I hear you. It is probably just habit as I run into so many times where I have to elevate the rights of the account I am logged in as.

That is part of why I want to get the user perms and init.d documented.

Thanks,

Ron

Rasi
Forum team
Posts: 141
Joined: January 16th, 2013, 7:29 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by Rasi »

there are some very bad instructions there.

first of all you run every single command with sudo, which is potentially dangerous, NEVER do that.
then you claim to backup mpd, which you do not. You simply copy the mpd binary, but that binary is linked to several libraries.
Copying back that binary at a later point will most definitely result in a non working setup.

Also I don't get why you mix 2 versions of mpd in the first place. Just compile, make, make install and you are done.
If the init script points to the version in /usr/bin fix the script instead.
Last but not least, if you want the init script, just copy it and uninstall the mpd package again, but don't overwrite files
from an existing package.

Also the link to dependencies gives a 404.

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

Rasi,

Thanks for your assist in IRC. I will update the walkthrough later today with the results of our discussion.

Best regards,

Ron

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

For reference this is the /etc/init.d/mpd script from my install.
#!/bin/sh

### BEGIN INIT INFO
# Provides: mpd
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: autofs $network $named alsa-utils pulseaudio avahi-daemon
# Should-Stop: autofs $network $named alsa-utils pulseaudio avahi-daemon
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Music Player Daemon
# Description: Start the Music Player Daemon (MPD) service
# for network access to the local audio queue.
### END INIT INFO

. /lib/lsb/init-functions

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=mpd
DESC="Music Player Daemon"
DAEMON=/usr/local/bin/mpd
MPDCONF=/etc/mpd.conf

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

if [ -n "$MPD_DEBUG" ]; then
set -x
MPD_OPTS=--verbose
fi

DBFILE=$(sed -n 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)
PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)

mpd_start () {
log_daemon_msg "Starting $DESC" "$NAME"

if [ -z "$PIDFILE" -o -z "$DBFILE" ]; then
log_failure_msg \
"$MPDCONF must have db_file and pid_file set; cannot start daemon."
exit 1
fi

PIDDIR=$(dirname "$PIDFILE")
if [ ! -d "$PIDDIR" ]; then
mkdir -m 0755 $PIDDIR
if dpkg-statoverride --list --quiet /run/mpd > /dev/null; then
# if dpkg-statoverride is used update it with permissions there
dpkg-statoverride --force --quiet --update --add $( dpkg-statoverride --list --quiet /run/mpd ) 2> /dev/null
else
# use defaults
chown mpd:audio $PIDDIR
fi
fi

start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
--exec "$DAEMON" -- $MPD_OPTS "$MPDCONF"
log_end_msg $?
}

mpd_stop () {
if [ -z "$PIDFILE" ]; then
log_failure_msg \
"$MPDCONF must have pid_file set; cannot stop daemon."
exit 1
fi

log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --oknodo --retry 5 --pidfile "$PIDFILE" \
--exec $DAEMON
log_end_msg $?
}

# note to self: don't call the non-standard args for this in
# {post,pre}{inst,rm} scripts since users are not forced to upgrade
# /etc/init.d/mpd when mpd is updated
case "$1" in
start)
mpd_start
;;
stop)
mpd_stop
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME
;;
restart|force-reload)
mpd_stop
mpd_start
;;
force-start)
mpd_start
;;
force-restart)
mpd_stop
mpd_start
;;
force-reload)
mpd_stop
mpd_start
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}"
exit 2
;;
esac

rhoering
Posts: 68
Joined: August 11th, 2014, 2:12 pm

Re: Walkthrough: Install MPD from Source as a daemon on Ubun

Post by rhoering »

I added the /etc/init.d/mpd file from my test pc to the original post.

1) Download the file.
2) Un-GZip and rename to "mpd".
3) Read the contents of the file to make sure you 'know' what it will do.
4) Place in /etc/inet.d directory.

Remember YMMV.

Post Reply