Old 21st July 2005, 02:45   #1
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 11:36   #2
bored_womble
Winamp's Womble
 
bored_womble's Avatar
 
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.
bored_womble is offline   Reply With Quote
Old 21st July 2005, 16:14   #3
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 16:18   #4
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
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.
djSpinnerCee is offline   Reply With Quote
Old 21st July 2005, 16:23   #5
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 16:29   #6
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
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....
djSpinnerCee is offline   Reply With Quote
Old 21st July 2005, 16:46   #7
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 16:49   #8
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 16:54   #9
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
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.
djSpinnerCee is offline   Reply With Quote
Old 21st July 2005, 16:57   #10
bored_womble
Winamp's Womble
 
bored_womble's Avatar
 
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.
bored_womble is offline   Reply With Quote
Old 21st July 2005, 17:01   #11
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 17:06   #12
jclawson
Junior Member
 
Join Date: Jul 2005
Posts: 11
Quote:
Originally posted by bored_womble
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 [/B]
This doesn't make sense to me at all though. It is not running under apache... just as the apache user. Unless apache searches for all programs running as apache and kills them I don't think this should be a problem. (who knows it could) Or if apache monitors everything it starts...

---- damn

sc_serv crashed... :-(

The setuid bit seems to be the only thing working.
jclawson is offline   Reply With Quote
Old 21st July 2005, 17:10   #13
jclawson
Junior Member
 
Join Date: Jul 2005
Posts: 11
Quote:
Originally posted by djSpinnerCee
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.
no permission problems... Like I said sometimes it runs just fine for 5 minutes and then crashes. all log files, and everything else are 777
jclawson is offline   Reply With Quote
Old 21st July 2005, 17:17   #14
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
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 ?
djSpinnerCee is offline   Reply With Quote
Old 21st July 2005, 17:32   #15
jclawson
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?
jclawson is offline   Reply With Quote
Old 21st July 2005, 18:22   #16
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
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.
djSpinnerCee is offline   Reply With Quote
Old 21st July 2005, 18:29   #17
jclawson
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.
jclawson is offline   Reply With Quote
Old 21st July 2005, 22:12   #18
reef1
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.
reef1 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump