Starting, restarting and reinstalling a server through the API

API & DocumentationWhat You Can Automate·· 9 views· 5 min read

In short: when a client asks you to start, restart or reinstall their server, your own system can do it through the API, without opening Meu Interweb. Each action goes into a queue and comes back with a number you follow to the end. Anything that deletes data, such as a reinstall, needs a permission of its own and the server name in the request. This covers VPS and Cloud; dedicated servers are handled with our team. See the server reseller page.

One key for everyday tasks, another for anything that wipes

Task Permission
See the servers and the state of each one vps:read
Start, stop and restart vps:write
Reinstall the system vps:reinstall (sensitive)
Restore a backup vps:restore (sensitive)
Create a new root password vps:password (sensitive)

The three sensitive ones are off on every key. If your system gives the client a "restart" button, that key has no business reinstalling anything. Keep the sensitive permissions on a separate key, used only when a request calls for it. More in sensitive API permissions.

Start, stop and restart

1 Check the state with GET /v1/servers/{id}. power_state says running, stopped, restarting or another state. The id is the same as the service's.
2 Ask for the action with POST /v1/servers/{id}/start, stop or restart. The answer is 202 with an action_id.
3 Follow it with GET /v1/actions/{id}: running while it runs, then done or failed. Starting usually takes about 2 minutes and stopping about 6. Only the key that asked for the action can look it up.

ACTION=$(curl -s -X POST https://api.interweb.ao/v1/servers/700/start \
-H "Authorization: Bearer $INTERWEB_API_KEY" -H "X-API-Mode: production" | jq -r '.data.action_id')
curl -s https://api.interweb.ao/v1/actions/$ACTION \
-H "Authorization: Bearer $INTERWEB_API_KEY" | jq -r '.data.status'

The X-API-Mode: production header makes sure the request never runs with the wrong key: if the key is a Sandbox one, the API refuses it. If the action ends failed with timed_out, check the server state before trying again. More on the action_id in long-running API operations.

Reinstalling, with a backup first

1 Pick the system from GET /v1/servers/{id}/operating-systems and keep its id.
2 Ask for the reinstall with POST /v1/servers/{id}/reinstall: confirm with the server name (the name from GET /v1/servers/{id}), operating_system and backup_first, plus the Idempotency-Key header.
3 Save the root password straight away. It appears only in that response and works once the reinstall has finished. Retrying with the same Idempotency-Key does not create another.
4 Follow it with the action_id. With backup_first set to true, the reinstall starts on its own once the backup appears, which can take up to an hour.

curl https://api.interweb.ao/v1/servers/700/reinstall -X POST \
-H "Authorization: Bearer $INTERWEB_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: request-318-reinstall" \
-d '{"confirm": "web1.asuaempresa.ao", "operating_system": "ubuntu-24.04", "backup_first": true}'

A reinstall deletes everything on the server. Confirm with your client before you ask for it. If the server already has 4 backups, a request with a backup first answers 409 backup_limit_reached and deletes nothing. There is a limit of 3 reinstalls or restores per hour across the account. Afterwards your client can log in with an SSH key, as we explain in how to create an SSH key.

Your client lost the root password

POST /v1/servers/{id}/password creates a new one, with vps:password and the server name in confirm. The server restarts to apply it, and the password works after 1 to 2 minutes. As with a reinstall, it appears only in the response: pass it to your client over a safe channel and keep it out of your system's logs.

The answers your system should expect

Answer When What to do
409 already_running / already_stopped The server is already the way you asked. Nothing. Tell your client it already was.
409 server_stopped You asked to restart a server that is off. Use start.
409 action_in_progress The server is busy with another action. Its action_id is in details. Follow that one instead of asking again.
409 service_not_active The service is suspended: data can be read, actions cannot run. Check the unpaid invoices in Meu Interweb.
429 rate_limited 15 seconds between actions on the same server, 10 actions per minute per account, 5 new passwords per hour. Wait the seconds in Retry-After.
What stays in Meu Interweb: the console and the virtual CD. sandbox_ keys have separate limits and touch no server, so test your system there first. The full list of actions is in controlling a VPS through the API, and a sample script in scripts for your servers.

Want to handle your clients' requests from your own system? See the server reseller page.

See server reselling

SEE ALSO

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

Scripts for your servers: restart or reinstall a VPS and keep nameservers and DNS up to date

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

Reinstalling or changing your VPS operating system

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

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon)

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