Run Ampache-Coherence-MPD on Dreamplug

From PlugWiki
Jump to: navigation, search

Contents

Introduction

The aim of this project is set up the dreamplug as music server with web streaming, dlna and jukebox directly connected to a sound system and controlled via a web interface.

The software to be used for this is the Ampache Web streaming server, Coherence DLNA server and Music Player Daemon (MPD/MPC). These are available through the Squeeze repositories. Ampache will be the frontend for our music services.

My set up set does not require the dreamplug's wireless or bluetooth functionality, so I will turn it off. Also DHCP is handled by my router. I hope to update the music files with rsync over ssh, so I will turn off samba. I am assuming that the network is 192.168.1.0/24. The server will have an address of 192.168.1.38.

The music files will all be on a USB stick in a folder called "/media/music".

Disclaimer

I provide this guide in good faith. I provide no guarantees that it will work, and no warrantee if your plug computer is broken as a result of following this.

It worked for me, so I hope it works for you!

Before you start

In this section I will briefly take you from a brand new dreamplug with Debian Lenny installed to one with a static IP, updated to Squeeze and wireless turned off. If you already have Squeeze or need wireless, take or leave the bits you need.

1) log into your new dream plug. I used this guide.

http://www.spinifex.com.au/plugs/dplugintro.html

2) Update the software, time zone, password as per the above website. Note: you should keep any config files the update process offers to replace, otherwise you may loose some important configuration for the wireless bridging.


 apt-get update
 apt-get dist-upgrade
 apt-get autoremove
 apt-get autoclean

3) remove lighttpd as it conflicts with apache.

 apt-get remove lighttpd

4) Set eth1 to a static ip. You should use eth1 (the plug closest to the end) as eth0 and the wifi are connected in some manner.

Edit interfaces:

nano -w /etc/network/interfaces

as below

auto eth1
iface eth1 inet static
       address 192.168.1.38
       netmask 255.255.255.0
       broadcast 192.168.1.255
       gateway 192.168.1.1

Reset the eth1 interface.

ifdown eth1
ifconfig eth1 down
ifup eth1

5) Plug in a network cable and try to ssh to your static ip address:

ssh root@192.168.1.38

6) I disable my wireless and bluetooth, but ther is no harm in toughening up the wireless security to WPA as per this site:

http://www.spinifex.com.au/plugs/dplugintro.html

I changed ip of the wireless so it no longer clashed with my router whilst I was in ~/init_setup.sh.

7) Turned off wireless by running wlan.sh

http://ortizaudio.blogspot.com/2011/07/setting-up-dreamplug.html

8) Disable wifi and bluetooth by commenting out /root/init-setup.sh in /etc/rc.local

nano -w /etc/rc.local

as follows

#disable wireless & bluetooth
#/root/init-setup.sh

Note: the modules will still the loaded but the wireless will be turned off

8) Updated Lenny to Squeez by editing /etc/apt/sources.list and changing "lenny" to "squeeze"

nano -w /etc/apt/sources.list

as follows

deb http://ftp.us.debian.org/debian/ squeeze main contrib non-free
deb http://http.us.debian.org/debian stable main contrib non-free
deb http://security.debian.org squeeze/updates main contrib non-free
deb http://www.backports.org/debian squeeze-backports main contrib non-free
#deb http://10.82.108.51/kedars/sheevaplug_wifi/builds/packages/ binary/

do the upgrade

 apt-get update
 apt-get dist-upgrade
 apt-get autoremove
 apt-get autoclean

It is probably a good idea to restart the dreamplug at this point. Rebooting takes over a minute.

Install music software

1) Insert your USB stick with the music files into the dream plug and find the name of the connected usb stick with music on it.

ls /dev/disk/by-id/

example:

/dev/disk/by-id/usb-Imation_ImationFlashDriv_07AA1E03C71417D4-0:0

/dev/disk/by-id/usb-Imation_ImationFlashDriv_07AA1E03C71417D4-0:0-part1


My music resides on the first partition of the drive:

"/dev/disk/by-id/usb-Imation_ImationFlashDriv_07AA1E03C71417D4-0:0-part1"

2) I want my music to always be available at /media/music. So I add an /etc/fstab entry to ensure the usb stick always has the same mount point

nano -w /etc/fstab

Add a line similar to this, with name of your USB partition:

/dev/disk/by-id/usb-Imation_ImationFlashDriv_07AA1E03C71417D4-0:0-part1 /media/music  auto rw,user,auto,noatime  0 0

Mount the usb stick to the new mount point

mount /media/music_1

Install Ampache

1) Install mysql server

apt-get install mysql-server

Now set the mysql root password.

mysqladmin -u root password <NEWPASSWORD>

For some reason this failed for me, so I was forced to set my password as per the instructions found here:

http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html#resetting-permissions-unix

restart the mysql service

service mysql restart

2) Install ampache. This will be our web front end.

apt-get install ampache

Browse to http://192.168.1.38/ampache and follow the on screen instructions. You will need your MySQL root password.

When you save the config file, move it to /etc/ampache/ampache.cfg.php of the dreamplug. I just used cut and paste. First I opened created the cfg file on the dreamplug

nano -w etc/ampache/ampache.cfg.php

Then I opened the version I download in the Ampache config process, copied the contents ans pasted it into the terminal window. This may give you issues if your ssh client machine is windows?

After I configured ampache I could not successfully log into Ampache due to a permission error. I needed to

chmod go+w /var/lib/php5/

This would be a good time to set up your music catalogue from the Admin menu in ampache. This may take quite an long tome! Try streaming a song to your pc.

Install Coherence DLNA server

1) Install the coherence DLNA server. Note: this is only worth doing if you have DLNA devices on your network.

apt-get install python-coherence

Follow most of the instruction at http://coherence.beebits.net/wiki/Ampache. These instructions are a bit dated, so adjust them as below.

In summary:

a) Set up acls as per the web site

b) In ampache create a user for coherence. User level is fine

c) Edit the ampache config file.

nano -w /etc/ampache/ampache.cfg.php

Ensure these settings are set:

 access_control  = "true"
 xml_rpc         = "true"

d) create the coherence config

mkdir /etc/coherence
nano -w /etc/coherence/coherence.conf

Contents should be as follows:

<config>
  <plugin active="yes">
    <name>ampache</name>
    <url>http://192.186.1.38/ampache/server/xml.server.php</url>
    <user><user created above></user>
    <key><user's password created above></key>
    <backend>AmpacheStore</backend>
  </plugin>
</config>

e) You can test the server as follows. Then see if your DLNA device can detect your server.

/usr/bin/coherence -c /etc/coherence/coherence.conf

f) Set coherence to start automatically on boot up. I wrote an init script based on the one from the coherence site (http://coherence-project.org/browser/trunk/Coherence/misc/coherence-initscript.sh) and the debian skeleton init script. For some reason I have to call it from rc.local as just adding a link to the rc2.d direcory did not work. Perhaps more clever people can make it work?

nano -w /etc/init.d/coherence.sh 

This is the init script.

 
#! /bin/sh
 #       /etc/rc.d/init.d/coherence,sh
 #
 # Starts the coherence server
 #
 # chkconfig: 345 90 56
 # description: An UPnP/DLNA MediaServer
 # processname: coherence
 # securlevel: 80
 #
 ### BEGIN INIT INFO
 # Provides: coherence
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6 
 # Required-Start: $network messagebus
 # Required-Stop: $network messagebus
 # Short-Description: Starts the coherence server
 # Description: An UPnP/DLNA MediaServer
 ### END INIT INFO
 # Author: kongwak and based on the debian skeleton script and this web site:
 #http://coherence-project.org/browser/trunk/Coherence/misc/coherence-initscript.sh
 #
 #
 # PATH should only include /usr/* if it runs after the mountnfs.sh script
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="Coherence DLNA server"
 NAME=coherence
 DAEMON=/usr/bin/$NAME
 DAEMON_ARGS="-d -c /etc/coherence/coherence.conf -l /var/log/coherence"
 PIDFILE=/var/run/coherence.pid
 SCRIPTNAME=/etc/init.d/$NAME.sh
 CONFIGFILE=/etc/coherence/coherence.conf
 LOGFILE=/var/log/coherence
   #
 # 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
   #
 # Load the VERBOSE setting and other rcS variables
 . /lib/init/vars.sh
   #
 # Define LSB log_* functions.
 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 . /lib/lsb/init-functions
   #
   #
 # Function that starts the daemon/service
   #
 do_start()
 {
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet  --exec $DAEMON --test > /dev/null \
		|| return 1
	start-stop-daemon --start --quiet --exec $DAEMON -- \
		$DAEMON_ARGS \
		|| return 2
	# Add code here, if necessary, that waits for the process to be ready
	# to handle requests from services started subsequently which depend
	# on this one.  As a last resort, sleep for some time.
 }
   #
 # Function that stops the daemon/service
   #
 do_stop()
 {
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME
	RETVAL="$?"
	[ "$RETVAL" = 2 ] && return 2
	# Wait for children to finish too if this is a daemon that forks
	# and if the daemon is only ever run from this initscript.
	# If the above conditions are not satisfied then add some other code
	# that waits for the process to drop all resources that could be
	# needed by services started subsequently.  A last resort is to
	# sleep for some time.
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
	[ "$?" = 2 ] && return 2
	# Many daemons don't delete their pidfiles when they exit.
	rm -f $PIDFILE
	return "$RETVAL"
 }
   #
 # Function that sends a SIGHUP to the daemon/service
   #
 do_reload() {
	#
	# If the daemon can reload its configuration without
	# restarting (for example, when it is sent a SIGHUP),
	# then implement that here.
	#
	start-stop-daemon --stop --signal 1 --quiet --name $NAME
	return 0
 }
   #
 case "$1" in
   start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
   stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
   status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
   #reload|force-reload)
	#
	# If do_reload() is not implemented then leave this commented out
	# and leave 'force-reload' as an alias for 'restart'.
	#
	#log_daemon_msg "Reloading $DESC" "$NAME"
	#do_reload
	#log_end_msg $?
	#;;
   restart|force-reload)
	#
	# If the "reload" option is implemented then remove the
	# 'force-reload' alias
	#
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
	  	# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
   *)
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
	exit 3
	;;
 esac
 :
 

Now start the service on boot.

nano -w /etc/rc.local

By adding these lines:

#start coherence DLNA server
service coherence.sh start

Install Music Player Daemon

1) I am connecting the head phone socket on the dreamplug to my stereo for local sound, so I need to ensure the internal USB sound card mounts as the default sound device.

Ref: http://www.newit.co.uk/forum/index.php?topic=2090.0

  1. nano -w /etc/modprobe.d/alsa-base.conf

Comment out the last line which prevents a usb device from becoming the default audio as follows:

#options snd-usb-audio index=-2

You may need to reboot for this to take effect.

2) Run alsamixer to see if it is all running and set the starting volume.

alsamixer

3) Install Music Player Deamon for local play via ampache.

apt-get install mpd mpc

MPD is configured as a system service and started by the install process.

4) MPD needs to be independently configured before it will work with ampache.

https://wiki.archlinux.org/index.php/Music_Player_Daemon

http://mpd.wikia.com/wiki/Configuration

Edit the MPD config file.

nano -w /etc/mpd.conf

Change the music directory to your music path. Everything else as the default.

music_directory       "/media/music_1/music"

Restart the MPD service

service mpd restart

5) create/update the MPD database. This data base will need to be updated whenever new files are added to the music directory.

mpc update

Using local play in Ampache

1) In order to use ampache for local play, login to ampache as an administrator

http://ampache.org/wiki/localplay:mpd

a) click the "local play" tab in the left hand menu

b) select "localplay" from the drop down below the search box

c) "add instance" from the localplay menu and use the following settings:

instance name: usb 1
hostname: localhost
port: 6600
password: <leave blank>

d) select "usb 1" in the active instance list (you may need to refresh the page)

e) go to the "home" tab and queue some songs, so they appear in the play list on the right side.

f) click the little icon on the "playlist" menu on the right side that looks like an orange semi circle to make your playlist available to mpd

g) click the play button on the "playlist" menu

Other system stuff

These are some other thing you can consider doing to save a little memory.

1) turn off unneeded services

apt-get install rcconf
rcconf

I turned off:

  1. bluetooth
  2. dnsmasq
  3. lighttpd
  4. pppd-dns
  5. udhcpd
  6. X11-common
  7. Exim4 (replaced by nullmailer below)
  8. samba

I am not sure about removing fam (used by samba?) and kbd

2) set security update notification

apt-get install cron-apt

Edit the config file:

nano -w /etc/cron-apt/config

Add these lines to the /etc/cron-apt/config

MAILTO="your prefered email address"
MAILON="output"

3) Install a light mail relay instead of exim4.

apt-get install nullmailer

Null mailer will remove EXIM and prompt you for your isp's smtp server during installation.

nano -w /etc/nullmailer/adminaddr

This file will just have your email address as the only entry

4) Maintaining the music databases. These would be good candidates for a cron job. These should be done occasionally:

Ampache will need its catalogue updated via the catalog menu when new files are added. This can also be done via the commandline:

http://ampache.org/wiki/config:commandline

mpd will need its database updated at the same time via the command line:

mpc update

5) To update your music with rsync, it need to ne installed on your desktop pc and the dreamplug

apt-get install rsync
Personal tools