Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Any PHP script to check current status and boot a virtualizor VPS if needed?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Any PHP script to check current status and boot a virtualizor VPS if needed?

TinkuTinku Member

I have a simple PHP script that check the status of SolusVM vpses using API and cron every minute so if it's down the script automatically boot the VPS.

I wanted to ask is there any similar script for virtualizor API? I need one thanks

Comments

  • akbakb Member

    Try this:

    <?php
    
    $vpsip   = 'YOUR VPS IP';
    $apiurl  = 'VIRTUALIZER URL'; // Something like: https://domain:4083/
    $apikey  = 'YOUR API KEY';
    $apipass = 'YOUR API PASS';
    
    @exec("ping -c 4 $vpsip", $output, $r);
    if($r===0) {exit;} // VPS is UP. No need to restart.
    
    $vmlist=@json_decode(@file_get_contents("$apiurl?act=listvs&api=json&apikey=$apikey&apipass=$apipass"));
    if (!$vmlist || !isset($vmlist->vs) || @!count($vmlist->vs)) {die("error in getting vm list");}
    
    foreach($vmlist->vs as $i)
    {
    if (in_array($vpsip, (array)$i->ips))
    {
    $reboot=@json_decode(@file_get_contents("$apiurl?act=restart&do=1&svs=".$i->vpsid."&api=json&apikey=$apikey&apipass=$apipass"));
    if ($reboot && isset($reboot->done->msg)) {die($reboot->done->msg);}
    else {die("Could not restart VM ID: ".$i->vpsid);}
    }
    }
    
    die("No VPS found with IP: $vpsip");
    ?>
    
  • I understand why you may need this.

    But I'm sure providers will not like this as such. Mass booting VMs after a node reboot on oversold systems can cause more problems.

  • Not to mention that maybe the user wanted their VPS powered down :)

  • autoboot(tm)

  • BopieBopie Member

    the strange thing is that some users actually do want ther machines powered down, I have a few clients that only boot the VPS when needed

  • @Bopie said:
    the strange thing is that some users actually do want ther machines powered down, I have a few clients that only boot the VPS when needed

    I personally don't. However I would never want to forcefully boot my VPS. Especially sending a boot request every minute.

    I've had it with LE providers specifically LES where the nodes are overloaded on boot due to 400 VPSes trying to boot on 8 cores. Zero of my VPSes are used alone in full production. I see no reason why a user would require their low end VPS to be forcefully booted every minute. What if the node had gone down? Sending boot requests to a solus master if the slave is down usually causes more issues. Especially if the VPS is online but has networking issues. You are just causing more issues. I'd highly recommend investing in High Availablity or a fail over setup. Maybe use the server you are running these scripts on as the backup server?

  • RizRiz Member

    You guys are over thinking the initial post completely.

Sign In or Register to comment.