SA-MP Forums Archive
Restart SA:MP hosted server trough a php code - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Restart SA:MP hosted server trough a php code (/showthread.php?tid=346861)



Restart SA:MP hosted server trough a php code - CaTaLinU - 30.05.2012

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


Re: Restart SA:MP hosted server trough a php code - 3ventic - 30.05.2012

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.


Re: Restart SA:MP hosted server trough a php code - kikito - 30.05.2012

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?


Re: Restart SA:MP hosted server trough a php code - 3ventic - 30.05.2012

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.


Re: Restart SA:MP hosted server trough a php code - ColorHost-Kevin - 30.05.2012

The host must also allow ssh2 on there webhosting server.

If they dont, your code will not function.


Re: Restart SA:MP hosted server trough a php code - Private200 - 30.05.2012

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) .


Re: Restart SA:MP hosted server trough a php code - CaTaLinU - 30.05.2012

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

other method ?

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


Re: Restart SA:MP hosted server trough a php code - Mandrakke - 30.05.2012

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!"); 



Re: Restart SA:MP hosted server trough a php code - CaTaLinU - 31.05.2012

and if i have no ssh2 exists other code?


Re: Restart SA:MP hosted server trough a php code - 3ventic - 31.05.2012

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?