Start, stop, reboot
start boots a stopped server, shutdown turns the system off cleanly and destroy cuts the power. reboot restarts the system cleanly, reset works like the reset button. A stopped server is still billed for its plan.
Parameters
| Name | In | Description |
|---|---|---|
| vm_uuid | path, stringrequired | Server id, from Create a VM or List VMs |
Request body
| Field | Type | Description |
|---|---|---|
| action | stringrequired | start, shutdown (clean), destroy (power off), reboot (clean) or reset (hard) |
Example request
curl -X POST "https://platform.serverscamp.com/api/v1/vms/$VM_UUID/power" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"action": "reboot"
}'import os, requests
token = os.environ["API_TOKEN"]
vm_uuid = "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34"
r = requests.post(
f"https://platform.serverscamp.com/api/v1/vms/{vm_uuid}/power",
headers={"Authorization": f"Bearer {token}"},
json={
"action": "reboot"
},
)
r.raise_for_status()
print(r.json())const vmUuid = '6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34';
const r = await fetch(`https://platform.serverscamp.com/api/v1/vms/${vmUuid}/power`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"action": "reboot"
}),
});
console.log(r.status, await r.json());curl -X POST "https://platform.serverscamp.com/api/v1/vms/$VM_UUID/power" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"action": "start"
}'import os, requests
token = os.environ["API_TOKEN"]
vm_uuid = "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34"
r = requests.post(
f"https://platform.serverscamp.com/api/v1/vms/{vm_uuid}/power",
headers={"Authorization": f"Bearer {token}"},
json={
"action": "start"
},
)
r.raise_for_status()
print(r.json())const vmUuid = '6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34';
const r = await fetch(`https://platform.serverscamp.com/api/v1/vms/${vmUuid}/power`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"action": "start"
}),
});
console.log(r.status, await r.json());curl -X POST "https://platform.serverscamp.com/api/v1/vms/$VM_UUID/power" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"action": "shutdown"
}'import os, requests
token = os.environ["API_TOKEN"]
vm_uuid = "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34"
r = requests.post(
f"https://platform.serverscamp.com/api/v1/vms/{vm_uuid}/power",
headers={"Authorization": f"Bearer {token}"},
json={
"action": "shutdown"
},
)
r.raise_for_status()
print(r.json())const vmUuid = '6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34';
const r = await fetch(`https://platform.serverscamp.com/api/v1/vms/${vmUuid}/power`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"action": "shutdown"
}),
});
console.log(r.status, await r.json());curl -X POST "https://platform.serverscamp.com/api/v1/vms/$VM_UUID/power" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"action": "destroy"
}'import os, requests
token = os.environ["API_TOKEN"]
vm_uuid = "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34"
r = requests.post(
f"https://platform.serverscamp.com/api/v1/vms/{vm_uuid}/power",
headers={"Authorization": f"Bearer {token}"},
json={
"action": "destroy"
},
)
r.raise_for_status()
print(r.json())const vmUuid = '6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34';
const r = await fetch(`https://platform.serverscamp.com/api/v1/vms/${vmUuid}/power`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"action": "destroy"
}),
});
console.log(r.status, await r.json());curl -X POST "https://platform.serverscamp.com/api/v1/vms/$VM_UUID/power" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"action": "reset"
}'import os, requests
token = os.environ["API_TOKEN"]
vm_uuid = "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34"
r = requests.post(
f"https://platform.serverscamp.com/api/v1/vms/{vm_uuid}/power",
headers={"Authorization": f"Bearer {token}"},
json={
"action": "reset"
},
)
r.raise_for_status()
print(r.json())const vmUuid = '6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34';
const r = await fetch(`https://platform.serverscamp.com/api/v1/vms/${vmUuid}/power`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"action": "reset"
}),
});
console.log(r.status, await r.json());Answer
Status 200 with this body.
| Field | Type | Description |
|---|---|---|
| vm_uuid | stringrequired | |
| action | stringrequired | The action sent to the server |
| status | stringrequired | power_control_queued: watch state in Get a VM |
{
"vm_uuid": "6f1c2a9e-4b3d-4e8a-9c71-2d5e8f0a1b34",
"action": "reboot",
"status": "power_control_queued"
}Wait until it is ready
The answer comes at once and the action runs in the background. Get a VM shows the power state in state, and pending_op while the action still runs.
Check the status
Ask Get a VM with the server's id; the field to watch is state:
curl "https://platform.serverscamp.com/api/v1/vms/$VM_UUID" \
-H "Authorization: Bearer $API_TOKEN"| state | What it means |
|---|---|
running | Up, after start, reboot or reset |
stopped | Off, after shutdown or destroy |
Wait in a loop
Ask every few seconds until it gets there, and stop on an error.
# VM_UUID: vm_uuid of the server, from the answer above
WANT=running # stopped after shutdown or destroy
while true; do
VM=$(curl -s "https://platform.serverscamp.com/api/v1/vms/$VM_UUID" -H "Authorization: Bearer $API_TOKEN")
STATE=$(echo "$VM" | jq -r .state)
echo "$STATE"
[ "$STATE" = "$WANT" ] && [ "$(echo "$VM" | jq .pending_op)" = null ] && break
sleep 5
done# vm_uuid: vm_uuid of the server, from the answer above
import os, time, requests
headers = {"Authorization": f"Bearer {os.environ['API_TOKEN']}"}
want = "running" # "stopped" after shutdown or destroy
while True:
vm = requests.get(f"https://platform.serverscamp.com/api/v1/vms/{vm_uuid}", headers=headers).json()
print(vm["state"])
if vm["state"] == want and not vm["pending_op"]:
break
time.sleep(5)// vmUuid: vm_uuid of the server, from the answer above
const headers = { Authorization: `Bearer ${process.env.API_TOKEN}` };
const want = 'running'; // 'stopped' after shutdown or destroy
for (;;) {
const vm = await (await fetch(`https://platform.serverscamp.com/api/v1/vms/${vmUuid}`, { headers })).json();
console.log(vm.state);
if (vm.state === want && !vm.pending_op) break;
await new Promise((ok) => setTimeout(ok, 5000));
}The bash version needs jq.
A reboot and a reset end where they started, running, so the loop ends at once for them. Check your own service, an SSH login or a port, to know the system is back.
Errors
| Status | When |
|---|---|
400 | Not one of the five actions |
401 | No token, or a token that is not valid |
402 | Starting needs a positive balance |
409 | The server is busy with another operation |
422 | The body or a parameter is not what the operation takes |
Every operation can also answer 401 without a valid token. All errors