|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
Starting shoutcast server from PHP under apache user - Problem
I am starting the shoutcast server from php using the following command:
$Command = "/path/to/sc_serv /path/to/sc_serv.conf"; $PID = shell_exec("nohup $Command > /dev/null & echo $!"); sc_serv is running as apache It starts up just fine. I connect from my home computer and start broadcasting. A few seconds... or minutes... after I start broadcasting the shoutcast server will close (the time is random but within 10 minutes). I assume its crashing but I have no idea why. There is nothing in the logs about it. Does anyone have an idea of what is going on? I can start sc_serv as root with the same command and it will not crash. What is it about running it as the apache user that is causing it to crash? Thanks for your help. |
![]() |
![]() |
![]() |
#2 |
Winamp's Womble
Join Date: May 2004
Location: Wimbledon Common
Posts: 1,100
|
the apache process will be cleaning up the child process, so depending on what it thinks about the process, this could be immediate, or take a bit longer.
You should not use apache to start it, as you will get unpredictable results. BW Without open minds the world will die. Open yours and correct the mistakes you are making right now. |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
Thanks I figured it was something like that.
So set the uid bit then (not owned by root of course ;-)). Thanks. |
![]() |
![]() |
![]() |
#4 |
Forum King
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
|
A better idea would be to keep the server running all the time and use the Apache/PHP CGI to send the running sc_serv process [root is ok] the signals you want.
The [exported?] environment that the PHP and the sc_serv get from Apache via CGI may not be sufficient to properly run the DNAS. One other thing you could try is to have the PHP launch a shell script [ksh? perhaps] instead of the sc_ executable directly -- this way you may gain more control over the environment that sc_serv runs under. /* v2 HTML5 / Player test pages DigitalMixNYC, DigitalMixNYCbx | DNAS Status: Now Playing js codes (scaststatus_X.php) | PortForward.com | Upload/Download Speed Test | No-IP.com: Free Dynamic DNS | In the YP | dnasDir */ |
![]() |
![]() |
![]() |
#5 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
I don't know what you mean by running apache all the time. It is running all the time.
It is running under a shell. The command I used is shell_exec. Perhaps I need to start a shell explicitly. |
![]() |
![]() |
![]() |
#6 |
Forum King
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
|
sc_serv -- DNAS running all the time -- if you don't have a source connected, it will not allow listeners, but it will allow station page [and /admin.cgi page] connects which will display "server is down."
I also think that kill -INT should cause a running sc_serv to shutdown, restart and re-read the config file (?) but I'm not too sure.... Anyways, just a suggestion.... /* v2 HTML5 / Player test pages DigitalMixNYC, DigitalMixNYCbx | DNAS Status: Now Playing js codes (scaststatus_X.php) | PortForward.com | Upload/Download Speed Test | No-IP.com: Free Dynamic DNS | In the YP | dnasDir */ |
![]() |
![]() |
![]() |
#7 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
I cannot leave it running all the time. There is going to be an arbitrary ammount of DNAS servers running. Not just one... not two... but x ammount. That solution won't work.
|
![]() |
![]() |
![]() |
#8 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
If I start under apache the DNAS server will run perfectly until I try to stream. It usually crashed immediatly after. I can browse its admin page as much as i want... no crash. Only when I start broadcasting does it crash.
I can even connect to it from winamp so as long as i dont play anything. As soon as I hit the play button it goes down. |
![]() |
![]() |
![]() |
#9 |
Forum King
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
|
Permissions maybe? When the server starts, it must have access to all of the files and paths it needs like the log, rip, and ban files, even if you don't have any.
Check the system logs for errors that may indicate what's going on. /* v2 HTML5 / Player test pages DigitalMixNYC, DigitalMixNYCbx | DNAS Status: Now Playing js codes (scaststatus_X.php) | PortForward.com | Upload/Download Speed Test | No-IP.com: Free Dynamic DNS | In the YP | dnasDir */ |
![]() |
![]() |
![]() |
#10 |
Winamp's Womble
Join Date: May 2004
Location: Wimbledon Common
Posts: 1,100
|
definately sounds like a permissions problem.
If you are insist on running it via apache, you *may* have to set the permissions to global read/write chmod 777 <logfile filename> I personally would avoid running it via Apache, as you will find ( as others have ) it wont be too stable as Apache has safeguards to prevent processes from taking too much time/memory/CPU so bogging down Apache. BW Without open minds the world will die. Open yours and correct the mistakes you are making right now. |
![]() |
![]() |
![]() |
#11 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
Starting it using
bash /path/to/script where "script" just starts sc_serv seems to work. At least it works so far. I will reply back if it really doesn't work. Thanks guys for your help. |
![]() |
![]() |
![]() |
#12 | |
Junior Member
Join Date: Jul 2005
Posts: 11
|
Quote:
---- damn sc_serv crashed... :-( The setuid bit seems to be the only thing working. |
|
![]() |
![]() |
![]() |
#13 | |
Junior Member
Join Date: Jul 2005
Posts: 11
|
Quote:
|
|
![]() |
![]() |
![]() |
#14 |
Forum King
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
|
It's important -- When apache spawns the PHP, it will wait at least until the PHP script ends, however, when your PHP then spawns a process (allocating resources) the Apache HTTPd still is responsible for cleaning up everything that was done by the PHP, so it may be "garbage collecting" resources that are being used by the sc_serv. I guess the "way" your PHP script spawns the process [shell_exec()?] may have something to do with it?
When Apache runs any CGI like PHP, the CGI has less rights than the Apache "user" by nature -- it may be important "how" you are running the PHP as well -- is the PHP in-line in an HTML doc? [server-parsed-html] or is it an external PHP script -- it may make a difference ? /* v2 HTML5 / Player test pages DigitalMixNYC, DigitalMixNYCbx | DNAS Status: Now Playing js codes (scaststatus_X.php) | PortForward.com | Upload/Download Speed Test | No-IP.com: Free Dynamic DNS | In the YP | dnasDir */ |
![]() |
![]() |
![]() |
#15 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
PHP is running as an apache module. So its like apache starting the process. I set UID on DNAS to another user... not root... and it works. So when apache runs the script it is running as a different user. Are there any problems with this.. security implications?
|
![]() |
![]() |
![]() |
#16 |
Forum King
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
|
The "Apache user" has only enough priveledge to run the HTTPd and access the files the server needs to run -- changing the user for sc_serv is the thing to do, since the Apache HTTPd does not need to know anything about how to run the DNAS...
You should know the security implications -- the user that sc_serv runs as should have only enough priveledge to run the DNAS in a perfect world -- believe it or not, you would be fine if you ran the DNAS server as root -- but if you need to be a bit paranoid... ![]() You'll be ok. /* v2 HTML5 / Player test pages DigitalMixNYC, DigitalMixNYCbx | DNAS Status: Now Playing js codes (scaststatus_X.php) | PortForward.com | Upload/Download Speed Test | No-IP.com: Free Dynamic DNS | In the YP | dnasDir */ |
![]() |
![]() |
![]() |
#17 |
Junior Member
Join Date: Jul 2005
Posts: 11
|
Yeah... I don't like to run anything as root that doesn't need to. I actually think the security would be better running as a different user than apache as apache would have permissions on the entire web directory. I can restrict the other username to only having permissions on DNAS. Works for me :-)
Thanks for your help guys. |
![]() |
![]() |
![]() |
#18 |
Junior Member
Join Date: Mar 2005
Posts: 31
|
You can try to use suphp and start sc_serv from a screen also. No uid needed then, because suphp makes apache start process from an user, who is owner of the file, not apache/apache.
afaik while using suphp your last number in the chmod must be zero. |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|