kiltjim
Posts: 9
Joined: Mon Jan 28, 2013 1:53 am

pianobar, php, permissions

Mon Jan 28, 2013 2:14 am

First, let me apologize if this in the wrong forum. Mods, please move or redirect if I am!

I am a complete beginner with Linux, and the Pi is driving my education in both Linux and several of the web based programming languages (HTML, PHP, etc.)

I have successfully installed http://6xq.net/projects/pianobar/ via the Debian repo's, and have it running without issue when launching via the command line as the user 'pi'. I have also used a fellow Pi user's web interface for control https://github.com/jacroe/pidora.

Now, I want to be able to launch pianobar without the CLI, simply by opening the website served through lighttpd and PHP (also properly functioning). In a PHP script, I have the following:

Code: Select all

<?php
$cmd = "/usr/bin/pianobar";
exec($cmd . " > /dev/null &");
?>
Originally, I had just the exec("/usr/bin/pianobar"); , but added the rest as it caused the script to hang waiting for it to complete. Again, I am a beginner, so if this is wrong, I wouldn't know it.

The above does launch pianobar, as "ps aux" shows it running under the user 'www-data' with the STAT = "S", but I have no sound output.

Can someone point me in the direction I should even be looking next?

Thanks, Jim.

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: pianobar, php, permissions

Thu Jan 31, 2013 7:14 am

you should use a service for this:
service pianobar start
service example:

Code: Select all

#!/bin/bash

#
#/etc/init.d/pianobar
#

NAME=pianobar
OPTIONS=""
PID=$(pidof $NAME);

function start {
        if [ "$PID" = "" ] ; then
                echo "Starting $NAME...";
                #screen -S $NAME -d -m $NAME $OPTIONS
                #nohup $NAME $OPTIONS >/dev/null 2>&1 
                tmux new -d -s $NAME $NAME $OPTIONS
                echo "  Done.";
        else
                echo "$NAME is already running as $PID.";
        fi
}

function stop {
        if [ "$PID" != "" ] ; then
                echo "Stoping $NAME...";
                kill $PID;
                TIMEOUT=30;
                START=$( date +%s);
                while [ $(( $( date +%s) - ${START} )) -lt ${TIMEOUT} ]; do
			PID=$(pidof $NAME);
                        if [ "$PID" == "" ]; then break
                        else sleep 2
                        fi
                done
                if [ "$PID" != "" ] ; then
                        echo "Error: $NAME would not stop";
                else
                        echo "  Done.";
                fi
        else
                echo "$NAME is was not running.";
        fi
}

function status {
        if [ "$PID" = "" ]; then
                echo "$NAME is not running";
        else
                echo "$NAME is running with pid $PID";
        fi
}

if [ "$1" = "start" ]; then
        start
elif [ "$1" = "stop" ]; then
        stop
elif [ "$1" = "restart" ]; then
        stop
        start
elif [ "$1" = "status" ]; then
        status
else
        echo " * Usage: /etc/init.d/$NAME [start|status|stop|restart]";
fi
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

kiltjim
Posts: 9
Joined: Mon Jan 28, 2013 1:53 am

Re: pianobar, php, permissions

Sat Feb 02, 2013 6:38 pm

I think I see what you are suggesting, but the whole point is to be able to launch it from a web page. This would let me control pianobar from my phone, tablet or other web enabled device. I was guessing that PHP would be a good method at getting control of the server side.

I tried your code, and it looks like it starts (I substituted out tmux for screen since I had it installed already). But is doesn't seem like pianobar started correctly. Or at least I don't have any sound.

Could this be that pianobar simply doesn't want to run in the background? I wouldn't even know where to start to change that if it was the case.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianobar, php, permissions

Sun Mar 17, 2013 10:46 pm

I just posted some info on setting up pianod, which is like pianobar but designed more as a background service. It has a nice web interface that works with any HTML5 compatible browser including Chrome, Firefox, and Safari on desktop as well as Android/iOS.

Return to “Media centres”