How to remotely stop/start a server with php?

Discussion in 'Bukkit Discussion' started by ReRRemi, Feb 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    ReRRemi

    I need a php script and linux shell to start and stop my server remotely.
    I can not find a plugin that does it :(...
     
  2. Offline

    Snaipe

    You would have to code a plugin to stop the server when it recieves the command, then work around with shell_exec($command) to start it again.

    Or, you could use a server wrapper, or make one.
     
  3. Offline

    Monopol

    This should do it:

    Code:
    shell_exec("echo 'password_goes_here' | sudo -u user_goes_here -S /path/to/bukkit/startscript.sh start");
     
  4. Offline

    ReRRemi

    Exactly Snaipe, I want to use shell_exec but with www-data user's right, it does not work. So thank you Monopol, it's excellent, I'll try it :)
     
  5. Offline

    Dreaux

  6. Offline

    JohnTheRipper

    RemoteToolkit is a good solution. Not web based though.
     
  7. Offline

    Postbote

    www-data cannot exec sudo in the default config.
    Another possibility is to connect over ssh on the server.
    You only need the libssh2 package (http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/)

    Then you could use a Serverstart/stopscript. I used the Teamspeak 3 Serverscript and modify'd it for the Minecraftserver. Any another Script should work too.

    You can executed commands with libssh2 like this:
    PHP:
    <?
    $user "minecraft";
    $password "OLOLOL";
    if(
    $ssh ssh2_connect('127.0.0.1'22)) {
        if(
    ssh2_auth_password($ssh$user$password)) {
            
    $stream ssh2_exec($ssh'./server.sh start');  //The Command to do
            
    stream_set_blocking($streamtrue);
            
    $data '';
            while(
    $buffer fread($stream4096)) {
                
    $data .= $buffer;
            }
            
    fclose($stream);
          echo 
    "<pre>";
            echo 
    $data//Prints the output
            
    echo "</pre>";
        }
    }
    ?>
     
  8. Offline

    ReRRemi

    Ok thank you guys. The methods work perfectly, and I made a third :p.
    I put chmod 777 -R on the folder minecraft (the startservers.sh is into the minecraft folder). I hope it is not dangerous for the security :p. Because having the password in a php file, I'm a little afraid (if apache bug and displays the php source). But thank you very much all, the Postbote technique is very interesting!
     
  9. Offline

    PhonicUK

    If your server runs McMyAdmin, you can use the McMyAdmin API to stop and start the server via any means you like.
     
  10. Offline

    Sich

  11. Using the php-ssh extension, you could just send command via SSH.
     
  12. Offline

    Dreaux

Thread Status:
Not open for further replies.

Share This Page