Controlling a VPS through the API: start, stop, restart, root password, reinstall and backups

VPS & Servers·· 35 views· 4 min read

The short answer: through the API you see the state of your VPS servers and start, stop and restart them, make backups, change reverse DNS and the time zone, generate a new root password, reinstall and restore. You read with vps:read and act with vps:write; password, reinstall and restore have their own permissions, off by default.

Which servers show up

Only the account's active or suspended servers managed from My MozOut. A server not yet created, terminated or cancelled answers 404. A server's id is the same as its service in GET /v1/services. With the service suspended, data can be read, but actions answer 409 with service_not_active.

Operation What it shows
GET /v1/servers, GET /v1/servers/{id} IP, system, resources and power_state.
GET .../traffic This month's traffic.
GET .../backups The backups.
GET .../reverse-dns, GET .../timezone Reverse DNS and the time zone.
GET .../operating-systems The systems available for a reinstall.

The state comes from a recent copy: state_checked_at says when it was read. The detail uses a copy up to 60 seconds old; the list only refreshes 2 servers at a time. If it cannot be read right now, state_stale comes back true with the last known state.

Start, stop and restart

curl https://api.mozout.com/v1/servers/123/restart -X POST -H "Authorization: Bearer $RLX_API_KEY"

POST .../start, .../stop and .../restart are queued and answer 202 with an action_id. Starting usually takes about 2 minutes and stopping about 6. Follow it with GET /v1/actions/{id}, as explained in long-running operations.

One at a time, and the limits

Rule Value
Simultaneous actions on one server One. With another running: 409 action_in_progress.
Between actions on the same server 15 seconds
Actions across the account 10 per minute
New passwords 5 per hour, across the account
Reinstalls or restores 3 per hour, across the account

Going over answers 429 with Retry-After. sandbox_ keys have these limits separately.

Root password, reinstall and restore

Operation Permission Take care
POST .../password vps:password Needs the server name in confirm. The server restarts to apply the password, which works after 1 to 2 minutes. The password appears only in that answer.
POST .../reinstall vps:reinstall Wipes everything and installs the system in operating_system. With backup_first set to true, the reinstall starts by itself once the backup appears, which can take up to an hour. The new root password appears only in that answer.
POST .../restore vps:restore Returns to the state of the backup given in backup. Everything changed after it is lost.

Reinstall and restore also need the Idempotency-Key header and the server name in confirm.

Save the root password the moment you get it. Repeating the request with the same Idempotency-Key does not generate another and returns password as null. In Sandbox, the password is not real. Better still, sign in with an SSH key, as explained in how to create an SSH key.

Backups, reverse DNS and time zone

POST .../backups makes a backup, which can take up to 50 minutes to appear. Each server has at most 4 backups, automatic ones included; with 4, the answer is 409 with backup_limit_reached. Downloading and deleting backups is done in My MozOut. PUT .../reverse-dns changes the name of each server IP and PUT .../timezone changes the time zone, picked from the list.

What stays in My MozOut: buying an extra IP or disk, the console and the virtual CD. The plans are on the VPS servers page.

Want to control your VPS from scripts? See the API page and test with a Sandbox key, which never touches the server.

See the API page

SEE ALSO

Long-running API operations: the 202 answer, the action_id and following the result

Sensitive API permissions and the spending limit: paying, buying, reinstalling, cPanel access

Idempotency-Key in our API: repeating a purchase, payment or ticket without doing it twice

API request limits: per key, per account and per task, the headers and what to do after a 429

API Sandbox or Production: what each key really does, and moving your program to production

How to create an SSH key and log in to your VPS without a password

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from KSh1,092.00/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.