Restart Services

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

NameMethodValueDescriptionRequired
actGETrestartservicesThe action specified to perform the operation and returns “done” as “1” after the service is restarted successfullyYes
servicePOSTtextThe name of the service that needs to be restarted, use the below table for valid valuesYes
changeseridGETIntThe server ID whose services need to be restarted, default is zeroNo

Service Parameters

ServiceDescription
webserverThis parameter will restart the web service
networkThis parameter will restart the network of the server
sendmailThis parameter will restart the mail service of the server
mysqldThis parameter will restart mysql service of the server
iptablesThis 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"
}
Was this helpful to you?