Manage Services

Use the Manage services API to start, stop and restart the services present on your server.

HTTP Request

https://hostname:4085/index.php?act=services

Paramters

NameMethodValueDescriptionRequired
actGETservicesThe action specified to perform the operation and return dataYes
sel_servPOSTarrayThe array of the names of the servicesYes
actionPOSTtextPass this to stop/start/restart the specified serviceNo
changeseridGETIntThe server ID whose services needs to be managed, default is zeroNo

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['sel_serv'] = array('xinetd');    //Pass a particular Service name
    $post['action'] = 'start';              //To stop or start or restart

    $output = $admin->services($post);

    print_r(json_encode($output));

?>

Output

{
    "title": "Services",
    "autostart": [
        "auditd",
        "blk-availability",
        "cgconfig",
        "crond",
        "dhcpd",
        "haldaemon",
        "ip6tables",
        "iptables",
        "iscsi",
        "iscsid",
        "ksm",
        "ksmtuned",
        "libvirt-guests",
        "libvirtd",
        "lvm2-monitor",
        "mdmonitor",
        "messagebus",
        "netcf-transaction",
        "netfs",
        "network",
        "nfslock",
        "portreserve",
        "rpcbind",
        "rpcgssd",
        "rsyslog",
        "sendmail",
        "sshd",
        "udev-post",
        "virtnetwork",
        "virtualizor",
        "zzvirtservice"
    ],
    "running": [
        "auditd",
        "cgconfig",
        "crond",
        "dhcpd",
        "ebtables",
        "haldaemon",
        "ip6tables",
        "iptables",
        "ksm",
        "ksmtuned",
        "libvirt-guests",
        "libvirtd",
        "messagebus",
        "netcf-transaction",
        "netconsole",
        "network",
        "nfslock",
        "rpcbind",
        "rsyslog",
        "sendmail",
        "sshd",
        "virtnetwork",
        "virtualizor"
    ],
    "services": {
        "0": "auditd",
        "1": "cgconfig",
        "2": "crond",
        "3": "dhcpd",
        "4": "ebtables",
        "5": "haldaemon",
        "6": "ip6tables",
        "7": "iptables",
        "8": "ksm",
        "9": "ksmtuned",
        "10": "libvirt-guests",
        "11": "libvirtd",
        "12": "messagebus",
        "13": "netcf-transaction",
        "14": "netconsole",
        "15": "network",
        "16": "nfslock",
        "17": "rpcbind",
        "18": "rsyslog",
        "19": "sendmail",
        "20": "sshd",
        "21": "virtnetwork",
        "22": "virtualizor",
        "24": "blk-availability",
        "31": "iscsi",
        "32": "iscsid",
        "37": "lvm2-monitor",
        "38": "mdmonitor",
        "41": "netfs",
        "44": "portreserve",
        "46": "rpcgssd",
        "50": "udev-post",
        "53": "zzvirtservice"
    },
    "timenow": 1536668727,
    "time_taken": "2.193"
}
Was this helpful to you?