packages/mpd: use new service functions
[packages.git] / sound / mpd / files / mpd.init
index 017ad77..707564b 100644 (file)
@@ -1,32 +1,28 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2007 OpenWrt.org
+# Copyright (C) 2007-2011 OpenWrt.org
+
 START=93
 
 start() {
        #create mpd directories
-       md=`grep music_directory /etc/mpd.conf | cut -d "\"" -f 2 | sed "s/~/\/root/g"`
-       if [ ! -d $md ]; then
-               mkdir -p $md
-       fi
-       pld=`grep playlist_directory /etc/mpd.conf | cut -d "\"" -f 2 | sed "s/~/\/root/g"`
+       pld=`grep ^playlist_directory /etc/mpd.conf | cut -d "\"" -f 2 | sed "s/~/\/root/g"`
        if [ ! -d $pld ]; then
-               mkdir -p $pld
+               mkdir -m 0755 -p $pld
        fi
-       #create mpd db
-       /usr/bin/mpd --stdout --create-db
 
-       #optional export for mpc
-       #export MPD_HOST=127.0.0.1
+       # Set the initial volume to something manageable
+       [ -x /usr/bin/amixer ] && /usr/bin/amixer set PCM 40
 
-       #start mpd
-       /usr/bin/mpd
+       if [ -x /bin/nice ]; then
+               # This has real-time constraints, so let's at least tell the OS
+               # that this should have higher priority to avoid skipping
+               # when doing other things in the background.
+               nice -n -10
+       fi
 
-       #generate playlist and start to play
-       /usr/bin/mpc listall | /usr/bin/mpc add -
-       /usr/bin/mpc play
-       /usr/bin/mpc repeat
+       service_start /usr/bin/mpd
 }
 
 stop() {
-        killall mpd
+       service_stop /usr/bin/mpd
 }