{"id":33,"date":"2013-03-24T17:26:00","date_gmt":"2013-03-24T17:26:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=33"},"modified":"2013-03-24T17:26:00","modified_gmt":"2013-03-24T17:26:00","slug":"how-to-make-the-mpdas-run-as-a-daemon","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=33","title":{"rendered":"How to make the mpdas run as a daemon"},"content":{"rendered":"<p>The other day I installed the <a href=\"https:\/\/github.com\/affekt\/mpdas\">mpdas<\/a>, which is the <a href=\"http:\/\/www.last.fm\/about\">audio scrobbler<\/a> for the <a href=\"http:\/\/mpd.wikia.com\/wiki\/Music_Player_Daemon_Wiki\">music player daemon<\/a>. Since there&#8217;s no debian package for the Raspberry Pi, I compiled mpdas from scratch and installed it. Now I don&#8217;t want to run it manually each time the Raspberry Pi boots up. So I found a <a href=\"http:\/\/werxltd.com\/wp\/2012\/01\/05\/simple-init-d-script-template\/\">nice template<\/a> for writing your own debian-style init-script. I changed it a little and also installed the <a href=\"http:\/\/packages.debian.org\/wheezy\/daemon\">daemon<\/a> tool, to turn the interactive mpdas program into a daemon. Just run <tt>apt-get install daemon<\/tt> to install it. Then put the following file under <tt>\/etc\/init.d\/mpdas<\/tt> and run <tt>update-rc.d mpdas defaults<\/tt>. Then mpdas will be run automatically upon boot. Oh, one more thing: put your mpdas configuration under <tt>\/usr\/local\/etc\/mpdasrc<\/tt> or adjust the <tt>DAEMONOPTS<\/tt> in the init script accordingly. <\/p>\n<pre><br \/>#!\/bin\/bash<br \/>### BEGIN INIT INFO<br \/># Provides:          mpdas<br \/># Required-Start:    $remote_fs $syslog $mpd<br \/># Required-Stop:     $remote_fs $syslog<br \/># Default-Start:     2 3 4 5<br \/># Default-Stop:      0 1 6<br \/># X-Interactive:     true<br \/># Short-Description: Audio Scrobbler for mpd<br \/># Description:       Starts the Audio Scrobbler for the mpd music player daemon.<br \/>### END INIT INFO<br \/><br \/>DAEMON_PATH=\"\/usr\/bin\/\"<br \/><br \/>DAEMON=daemon<br \/>DAEMONOPTS=\"-u pi -r -X \/usr\/local\/bin\/mpdas\"<br \/><br \/>NAME=mpdas<br \/>DESC=\"The mpdas audio scrobbler for mpd\"<br \/>PIDFILE=\/var\/run\/$NAME.pid<br \/>SCRIPTNAME=\/etc\/init.d\/$NAME<br \/><br \/>case \"$1\" in<br \/>start)<br \/>printf \"%-50s\" \"Starting $NAME...\"<br \/>cd $DAEMON_PATH<br \/>PID=`$DAEMON $DAEMONOPTS > \/dev\/null 2>&1 & echo $!`<br \/>#echo \"Saving PID\" $PID \" to \" $PIDFILE<br \/> if [ -z $PID ]; then<br \/>     printf \"%sn\" \"Fail\"<br \/> else<br \/>     echo $PID > $PIDFILE<br \/>     printf \"%sn\" \"Ok\"<br \/> fi<br \/>;;<br \/>status)<br \/> printf \"%-50s\" \"Checking $NAME...\"<br \/> if [ -f $PIDFILE ]; then<br \/>     PID=`cat $PIDFILE`<br \/>     if [ -z \"`ps axf | grep ${PID} | grep -v grep`\" ]; then<br \/>  printf \"%sn\" \"Process dead but pidfile exists\"<br \/>     else<br \/>  echo \"Running\"<br \/>     fi<br \/> else<br \/>     printf \"%sn\" \"Service not running\"<br \/> fi<br \/>;;<br \/>stop)<br \/> printf \"%-50s\" \"Stopping $NAME\"<br \/>     PID=`cat $PIDFILE`<br \/>     cd $DAEMON_PATH<br \/> if [ -f $PIDFILE ]; then<br \/>     kill -HUP $PID<br \/>     printf \"%sn\" \"Ok\"<br \/>     rm -f $PIDFILE<br \/> else<br \/>     printf \"%sn\" \"pidfile not found\"<br \/> fi<br \/>;;<br \/><br \/>restart)<br \/>$0 stop<br \/>$0 start<br \/>;;<br \/><br \/>*)<br \/> echo \"Usage: $0 {status|start|stop|restart}\"<br \/> exit 1<br \/>esac<br \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The other day I installed the mpdas, which is the audio scrobbler for the music player daemon. Since there&#8217;s no debian package for the Raspberry Pi, I compiled mpdas from scratch and installed it. Now I don&#8217;t want to run it manually each time the Raspberry Pi boots up. So I found a nice template &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=33\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to make the mpdas run as a daemon&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,11,2,3,10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}