Use the Restart Services API to restart a specific service on your server. This API allows you to restart services such as "mysqld" and "webserver" service. The API response will contain "done" as "1" after successful restart of the service.
HTTP Request
https://hostname:4085/index.php?act=restartservices&service=SERVICE_NAME
Parameters
Name Method Value Description Required act GET restartservices The action specified to perform the operation and returns "done" as "1" after the service is restarted successfully Yes service POST text The name of the service that needs to be restarted, use the below table for valid values Yes changeserid GET Int The server ID whose services need to be restarted, default is zero No
Service Parameters
Service Description webserver This parameter will restart the web service network This parameter will restart the network of the server sendmail This parameter will restart the mail service of the server mysqld This parameter will restart mysql service of the server iptables This parameter will restart the iptables service of the server
Sample Code
<?php
require_once('/usr/local/virtualizor/sdk/admin.php');
$key = 'your_api_key';
$pass = 'your_api_pass';
$ip = 'your_server_ip';
$admin = new Virtualizor_Admin_API($ip, $key, $pass);
$post = array();
$post['service'] = 'mysqld';
$output = $admin->restartservices($post);
print_r(json_encode($output));
?>
Output
{
"title": "Restart Services",
"done": 1,
"getservices": "mysqld",
"do": "restart",
"timenow": 1536681179,
"time_taken": "5.304"
}