Icecast Streaming Media Server Forum Index Icecast Streaming Media Server
Icecast is a Xiph Foundation Project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Icecast2 PHP startup script.

 
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Icecast Server
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Tue Jul 19, 2005 4:51 am    Post subject: Icecast2 PHP startup script. Reply with quote

This is my first script so be nice. Any suggestions to improve it would be appreciated.
http://www.galwayland.com
Code:
<?php
//http://us2.php.net/manual/en/function.popen.php
//www.galwayland.com
header("Cache-Control: no-store, no-cache");
error_reporting(E_ALL);

$date=date("l dS of F Y h:i:s A");
echo"$date<br>";
echo "_______________________________<br>";

$pid = exec("ps -A | grep icecast | cut -c 0-6");
if ($pid <=1) {
        $handle = popen('icecast -b -c /usr/local/etc/icecast.xml 2>&1', 'r');
        $read = fread($handle, 1024);
        echo "<pre>$read</pre><br>";
        pclose($handle);
        sleep(3);
}

$pid2 = exec("ps -A | grep icecast | cut -c 0-6");

if ($pid2 <=1) {
        echo "icecast2 failed to start..trying again..";
        $handle2 = popen('icecast -b -c /usr/local/etc/icecast.xml 2>&1', 'r');
        $read2 = fread($handle2, 2096);
        echo "<pre>$read2</pre><br>";
        pclose($handle2);
        sleep(3);
}

$pid3= exec("ps -A | grep icecast | cut -c 0-6");

if ($pid3 <=1) {
        echo "icecast2 failed to start..giving up";
}
else {
        echo "icecast2 running on pid $pid3<br>";
}
?>
~
Back to top
Anonymous
Guest





PostPosted: Sun Jul 24, 2005 5:41 pm    Post subject: Reply with quote

your way works fine, but another way to quickly get a process id (pid) without grepping and text manipulation:

ps -o "%p" --no-headers -C commandname

only PID number output, no headers, for "commandname"
Back to top
Anonymous
Guest





PostPosted: Tue Aug 09, 2005 1:47 am    Post subject: Reply with quote

jens wrote:
your way works fine, but another way to quickly get a process id (pid) without grepping and text manipulation:

ps -o "%p" --no-headers -C commandname

only PID number output, no headers, for "commandname"


Thanks Jens...I will use it....Would you like some credit for you input?

Here is my latest..
Code:
<?php
/********************************************************/
/* Version .03                                          */
/* William J. Galway                                    */
/* http://www.galwayland.com                            */
/*                                                      */
/* .03 Released 8-Aug-2005                              */
/*  Changed exec("ps -A | grep icecast | cut -c 0-6")   */
/*  to exec("ps -o \"%p\" --noheaders -C icecast")      */
/*  Thanks Jens..                                       */
/*                                                      */
/* .02 Released 21-Jul-2005                             */
/* ------------------------                             */
/* Cleaned up code.                                     */
/*                                                      */
/* .01 Initial Release 18-Jul-2005                      */
/* -------------------------------                      */
/*                                                      */
/********************************************************/

header("Cache-Control: no-store, no-cache");
error_reporting(E_ALL);

/*--------------*/
/* Header       */
/*--------------*/

echo "<a href=\"http://www.galwayland.com/admin.php?op=IcecastAdmin\">Return to Icecast Admin</a><br><br>";
$date = date("l dS of F Y h:i:s A");
echo "$date<br>";

/*----------------------*/
/* Starting Icecast     */
/*----------------------*/

echo "---------------------------------------------<br>";
$pid = exec("ps -o \"%p\" --no-headers -C icecast");
if ($pid <=1) {
        $handle = popen('icecast -b -c /usr/local/etc/icecast.xml 2>&1', 'r');
        $read = fread($handle, 1024);
        echo "<pre>$read</pre><br>";
        pclose($handle);
        sleep(3);
}
echo "<br>";
echo "---------------------------------------------<br>";

/*******************/
/* Checking Status */
/*******************/echo "<br><br>";
echo "--------------------<br>";
echo "---Icecast Status---<br>";
echo "--------------------<br>";

$pid2 = exec("ps -o \"%p\" --no-headers -C icecast");
if ($pid2 <=1) {
        echo "Icecast2 Failed To Start<br>";
        echo "Please Try Again<br>";
}

if ($pid <=1 && $pid2>=1) {
        echo "Icecast2 Started<br>";
}

if ($pid2 >=1) {
        echo "Icecast2 Running On PID $pid2<br>";
}

?>
Back to top
pauldy
Guest





PostPosted: Wed Aug 24, 2005 4:55 am    Post subject: Reply with quote

Another way to do the same is use pidof icecast. $pid=`pidof icecast`;
Back to top
Guest






PostPosted: Thu Aug 25, 2005 1:27 am    Post subject: Reply with quote

pauldy wrote:
Another way to do the same is use pidof icecast. $pid=`pidof icecast`;


Thanks Pauldy Smile

BG
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Icecast Server All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
subRebel style by ktauber