Restart SA:MP hosted server trough a php code
#1

I have a domain an a webhost on it

Exists a code that would restar my server trough a connection with the user & password from the GameCP ?

i have tried something like this, the code i have founde on the internet ..


PHP код:
$connection ssh2_connect($host22); 
                     
ssh2_auth_password($connection$user$password); 
                     
ssh2_exec($connection"cd service8/samp03 && ./samp03svr"); 
but nothing

please help me ..
My server is hosted on a Dedicated Server with gamecp
Reply
#2

I think you should use "cd /absolute/path/to/samp/folder;./samp03svr"

The problem is that it might be running under a screen or under different user if it's hosted.
Reply
#3

Quote:
Originally Posted by CaTaLinU
Посмотреть сообщение
I have a domain an a webhost on it

Exists a code that would restar my server trough a connection with the user & password from the GameCP ?

i have tried something like this, the code i have founde on the internet ..


PHP код:
$connection ssh2_connect($host22); 
                     
ssh2_auth_password($connection$user$password); 
                     
ssh2_exec($connection"cd service8/samp03 && ./samp03svr"); 
but nothing

please help me ..
My server is hosted on a Dedicated Server with gamecp
Do you have , at least, root access to the dedicated server?
Reply
#4

Quote:
Originally Posted by kikito
Посмотреть сообщение
Do you have , at least, root access to the dedicated server?
Only need the access to the user the process is run with, and the user must have rights to the required actions.
Reply
#5

The host must also allow ssh2 on there webhosting server.

If they dont, your code will not function.
Reply
#6

I think you should /rcon login [rcon password] and then /restart . This is what i used and it restarted server in 15 secs ( rarely) and 2 min ( really often) .
Reply
#7

I think that the Dedicated server has no ssh2 ....

other method ?

Yes i have an user on the GameCP with one samp server
Reply
#8

to restart the server you need to kill the process then start it again;

I took this snippet from my own server administration script, it is not a finished script, it is just to look and see how it works, then modify it to work with your server;

PHP код:
$cmd ssh2_exec($connection"top -b -n 1 | grep samp");
stream_set_blocking($cmdtrue);
$resp stream_get_contents($cmd);
preg_match_all("/[ ]+(.*?) (.*?) [ ]+(.*?) [ ]+(.*?)[ ]+(.*?)[ ]+(.*?)[ ]+(.*?) (.*?) [ ]+(.*?) [ ]+(.*?) [ ]+(\d+\:\d+\.\d+) (.*?) .*?\n/i"$resp$resp);
$erros = array();
for(
$i 0$i count($resp[1]); ++$i) {
    
$cmd ssh2_exec($connection"kill {$resp[1][$i]}");
    
stream_set_blocking($cmdtrue);
    
    
$erro stream_get_contents(ssh2_fetch_stream($cmdSSH2_STREAM_STDERR));
    if(
stristr($erro"No such process")) {
        
$erros[] = "Could not kill the process '{$resp[12][$i]}' (pid: {$resp[1][$i]})";
    }
}
if(
count($erros) > 0) {
    die(
json_encode(array("resp"=>utf8_encode("There was a error while restarting the server\\n\\n".implode("\\n"$erros)))));
} else {
    die(
json_encode(array("resp"=>utf8_encode("Server restarted successfully."))));

In my case, my server have an auto-restarter, so I just have to kill the process and the auto-restarted will put it back online again automatically.


Also you need to have sure if SSH2 library is installed, just make a test;

PHP код:
if(function_exists("ssh2_connect")) die("SSH2 library installed!");
else die(
"SSH2 library not installed!"); 
Reply
#9

and if i have no ssh2 exists other code?
Reply
#10

Is your server running on a host (from volt or serverffs for instance) or is it on a dedicated server/VPS, which you can control completely?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)