Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created April 22, 2010 21:49
Show Gist options
  • Save softlayer/375867 to your computer and use it in GitHub Desktop.
Save softlayer/375867 to your computer and use it in GitHub Desktop.
<?php
/**
* Reboot a SoftLayer server
*
* Given a server id call the rebootDefault() method in the
* SoftLayer_Hardware_Server service to attempt to reboot the server via IPMI
* or its power strip if remote management is unavailable.
*
* This assumes the SoftLayer API PHP client
* <http://github.com/softlayer/softlayer-api-php-client> is installed in the
* directory '/SoftLayer' in this script's path and that you wish to use the
* SOAP client instead of our XML-RPC client.
*
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/rebootDefault
* @license <http://sldn.softlayer.com/article/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
// Include XmlrpcClient.class.php if you'd like to use our XML-RPC client
// instead.
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');
// Generate an API key in the SoftLayer customer portal.
$username = 'set me!';
$key = 'set me too!';
// If you don't know your server id you can call getHardware() in the
// SoftLayer_Account API service to get a list of hardware or call
// findByIpAddress() in the SoftLayer_Hardware_Server service if you already
// know your server's primary IP address.
$serverId = 1234;
// Call SoftLayer_XmlrpcClient::getClient() if you're using our XML-RPC
// library.
$client = SoftLayer_SoapClient::getClient('SoftLayer_Hardware_Server', $serverId, $username, $key);
// There are three other reboot methods you can call instead of rebootDefault().
// rebootSoft() attempts a soft IPMI server reboot, akin to the ctrl-alt-del
// sequence. rebootHard() performs a hard IPMI server boot, similar to hitting
// the server's reset button. powerCycle() physically flips power to the server
// via its power strip, and should only be used as a last resort.
// rebootDefault() is a great compromise amongst the server reboot options.
try {
$client->rebootDefault();
echo 'Server rebooted!';
} catch (Exception $e) {
echo 'Unable to reboot server: ' . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment