Home MiscellaneousRunCloud API: How to Automate Server Management

RunCloud API: How to Automate Server Management

by SupportPRO Admin

RunCloud provides a powerful API that allows you to automate various server management tasks, such as deploying web applications, managing databases, and configuring security settings. Here’s how you can leverage the RunCloud API for automation.

1. Getting Started with the RunCloud API.

Step 1: Get Your API Key

   In order to get the API Token go to Workspace > Settings > API Management.

Step 2: Base API URL

   The RunCloud API base URL: https://manage.runcloud.io/api/v3

Step 3: Authentication

RunCloud uses Bearer Token authentication. You can test it by sending a GET request to the ping endpoint.

curl -X GET “https://manage.runcloud.io/api/v3/ping” \

    -H “Authorization: Bearer YOUR_API_TOKEN” \

    -H “Content-Type: application/json” \

    -H “Accept: application/json”

You will get pong message as the output, If the request is successful, 

{

    “message”: “pong”

}

2. Automating Server Management.

a. List All Servers

curl -H “Authorization: Bearer YOUR_API_KEY” \

“https://manage.runcloud.io/api/v3/servers”

This returns a list of all your connected servers.

b. Get Server Details

curl -H “Authorization: Bearer YOUR_API_KEY” \

“https://manage.runcloud.io/api/v3/servers/{server_id}”

Replace {server_id} with the actual ID of your server.

c. Restart a Server

curl -X POST -H “Authorization: Bearer YOUR_API_KEY” \

“https://manage.runcloud.io/api/v3/servers/{server_id}/restart”

3. Automating Website Management.

a. Create a New Web App

curl -X POST “https://manage.runcloud.io/api/v3/servers/{server_id}/webapps” \

-H “Authorization: Bearer YOUR_API_KEY” \

-H “Content-Type: application/json” \

-d ‘{

  “domainName”: “example.com”,

  “stack”: “native-nginx”,

  “php_version”: “8.1”

}’

This creates a web app with Nginx + PHP 8.1.

b. Deploy a Web App from Git

curl -X POST “https://manage.runcloud.io/api/v3/servers/{server_id}/webapps/{webapp_id}/git/deploy” \

-H “Authorization: Bearer YOUR_API_KEY”

c. Delete a Web App

curl -X DELETE “https://manage.runcloud.io/api/v3/servers/{server_id}/webapps/{webapp_id}” \

-H “Authorization: Bearer YOUR_API_KEY”

4. Automating Database Management.

a. Create a Database

curl -X POST “https://manage.runcloud.io/api/v3/servers/{server_id}/databases” \

-H “Authorization: Bearer YOUR_API_KEY” \

-H “Content-Type: application/json” \

-d ‘{

  “databaseName”: “mydatabase”,

  “databaseUser”: “myuser”,

  “databasePassword”: “mypassword”

}’

b. Delete a Database

curl -X DELETE “https://manage.runcloud.io/api/v3/servers/{server_id}/databases/{database_id}” \

-H “Authorization: Bearer YOUR_API_KEY”

5. Automating User Management.

a. Add a New System User

curl -X POST “https://manage.runcloud.io/api/v3/servers/{server_id}/system-users” \

-H “Authorization: Bearer YOUR_API_KEY” \

-H “Content-Type: application/json” \

-d ‘{

  “username”: “newuser”

}’

b. Delete a System User

curl -X DELETE “https://manage.runcloud.io/api/v3/servers/{server_id}/system-users/{user_id}” \

-H “Authorization: Bearer YOUR_API_KEY”

6. Scheduling Tasks via API.

RunCloud allows you to automate cron jobs using the API.

curl -X POST “https://manage.runcloud.io/api/v3/servers/{server_id}/cronjobs” \

-H “Authorization: Bearer YOUR_API_KEY” \

-H “Content-Type: application/json” \

-d ‘{

  “command”: “php /home/runcloud/webapps/myapp/artisan schedule:run”,

  “schedule”: “* * * * *”,

  “user”: “runcloud”

}’

This schedules Laravel’s schedule:run to execute every minute.

7. Monitoring and Alerts.

a. Get Server Usage Stats

curl -H “Authorization: Bearer YOUR_API_KEY” \

“https://manage.runcloud.io/api/v3/servers/{server_id}/usage”

This returns CPU, memory, and disk usage.

b. Enable Web Application Firewall (WAF)

curl -X POST “https://manage.runcloud.io/api/v3/servers/{server_id}/webapps/{webapp_id}/waf/enable” \

-H “Authorization: Bearer YOUR_API_KEY”

We can set up automated server management using APIs from each server. The major advantage of this setup is that we can use APIs for multiple servers. This allows us to collect server resources and perform tasks to ensure the servers remain secure and optimized for hosted websites.

If you are facing difficulties in server management, we can assist you with a server management setup enabled with RunCloud. We also perform routine manual tasks to ensure your servers are secure and optimized for production workloads.

Let us take care of your server management while you focus on growing your business.

If you need any assistance with the RunCloud API, Our team is available 24/7 to assist you.

Facing issues?

Our technical support
engineers can solve it.

Contact Us today!
guy server checkup

You may also like

Leave a Comment