Restarting Teamspeak via Browser

Elewyth

New Member
Hello guys :)

Here's my situation: I am operating a Linux Debian virtual root server, on which i have several applications running, including a TS3 Server and an Apache2 / PHP5 installation.

Lately I have experienced, that my TS3 Server crashed occasionally (like once a month - there is literally no information in the logs...). Anyway, since I am the only one with access to the VRS and my friends are using the TS3 Server, it would be cool, if they had an easy way to start up the server should it crash and I am not around.

So I thought it shouldn't be too hard to write a PHP script and a shell script, which would do exactly that - start the TS3 server.

My php file test.php, in the directory /var/www/ looks like this:
PHP:
<?php
    $output = shell_exec('/var/www/ts3.sh');
    echo "<pre>" . $output . "</pre>";
?>

Furthermore, my shell script ts3.sh (obviously in the directory /var/www/):
Code:
#!/bin/bash
echo "Test"
/usr/local/teamspeak/ts3server_startscript.sh status

When I execute the script from the command line using PuTTY (logged in as root, simply inputting /var/www/ts3.sh) I get
Code:
Test
Server is running

When I access the Webpage (test.php) all I get is "Test", but nothing on the TS3 server.

Both test.php and ts3.sh have the execute (X) permission set. I read somewhere, one has to create command aliases and stuff for the account "www-data", but I didn't really get it, as I have never touched Linux before (Although I do have fair experience with PHP). All the "basic" shell commands like "ls" work perfectly fine using the PHP script, it just seems I can't execute anything outside of the /var/www directory.

Any help would be greatly appreciated - if you need more details please ask :)

Greetings, Elewyth

PS: I don't seem to find any kind of errors when executing the php script through the browser, also with error_reporting(E_ALL) set - there is no error log file either.

Edit: For anyone reading this thread because he got similar problems, the solution is adding
Code:
www-data        ALL=NOPASSWD: /var/www/ts3.sh
(replace the directory with the needed one) to your sudoers file (execute visudo), beneath the line that grants all the permissions to root.
 
Last edited:
What happens if you execute the php script from the command line? I know you said running the shell script directly works. What happens if you do this?
PHP:
<?php 
    $output = shell_exec('/var/www/ts3.sh 2>&1'); 
    echo "<pre>" . $output . "</pre>"; 
?>

I only ask because I've had trouble using shell_exec, and I wonder if it is throwing out something to stderror. If I had to guess, you've probably got permission problems I don't think the apache user is allowed to touch much outside of it's directories.
 
Thanks for the quick reply.

Just tested it:
Code:
root@vserver:/var/www# php test.php
<pre>Test
Server is running
</pre>

Seems to be working fine like this.

EDIT: Oh wait, I think I misunderstood what you meant. I didn't notice the small change in the PHP script until now - edited it and called the script in Firefox:

Code:
Test
/var/www/ts3.sh: line 3: /usr/local/teamspeak/ts3server_startscript.sh: Permission denied

Soooo.... What to do? :D

2nd Edit: when adding sudo to the command I get the following now: "sudo: no tty present and no askpass program specified". This should provide me with further Google-material, maybe it helps anyone of you, too :)

3rd and final edit:

Finally figured it out - kinda thanks to your post, Cromewell :)
The trick did indeed lay in adding permission in the sudoers file - just had to do some more intensive googling combined with trial and error. Anyway, I simply had to add the following line beneath "root ALL=(ALL) ALL" in the sudoers file I accessed with the shell command "visudo":
Code:
www-data        ALL=NOPASSWD: /var/www/ts3.sh

Figured it out by Googling "sudo: no tty present and no askpass program specified" which lead me to a work-around, which finally lead me to the solution. Hope I could help anyone having similar problems and thanks again for the quick and definitely helpful response.

Cheers
 
Last edited:
Good stuff, I figured you were going to need sudo or to play around with user groups but without knowing that the error was permission denied. In any event, I'm sure other people will try to do this at some point so thanks for posting your solution :)
 
Back
Top