Automatic agent installation - Vultr

If you wish to monitor your Vultr VPS you can have the agent installed and the device added your to Server Density account automatically upon VPS creation. 

This works by creating a boot 'Startup Script' and selecting it to be run when your provision new VPS. 

API

Create Startup Script

curl -v -X POST https://api.vultr.com/v1/startupscript/create?api_key=$VULTR_API_TOKEN \
--data 'name=SD_Install&script=#!/bin/bash
sysctl kernel.hostname=$HOSTNAME
curl http://archive.serverdensity.com/agent-install.sh | bash -s -- -a $SD_ACCOUNT -t $SD_API_TOKEN' 

The above will create a startup script that will change the hostname (on sysctl enabled systems only) and install the sd-agent. Before executing the command ensure that you change the $VULTR_API_TOKEN, $HOSTNAME, $SD_ACCOUNT & $SD_API_TOKEN variables.

This will output similarly the following:

{"SCRIPTID":16000}

Create Instance

You can also use the Vultr API to create instances and it's possible to pass a startup script ID with the instance creation request.

curl -v -X POST https://api.vultr.com/v1/server/create?api_key=$VULTR_API_TOKEN \
--data 'DCID=1&VPSPLANID=29&OSID=167&SCRIPTID=$SCRIPT_ID&label=$HOSTNAME' 

The above will create a VPS on your account, these settings will create a CentOS 7 server on the lowest plan which is located in New Jersey. Feel free to change to settings as required (Refer to Vultr's API guide for more information regarding these). But ensure that you have also changed the $VULTR_API_TOKEN, $HOSTNAME & $SCRIPT_ID variables before executing.

$SCRIPT_ID should be replaced with the script id given in the output of the previous command.

User Interface

When you create a VPS using the Vultr User Interface you can create and use 'Startup Scripts'. 

Simply create a boot startup script containing the following, replacing the $HOSTNAME, $SD_ACCOUNT & $SD_API_TOKEN variables as required. 

#!/bin/bash
sysctl kernel.hostname=$HOSTNAME
curl http://archive.serverdensity.com/agent-install.sh | bash -s -- -a $SD_ACCOUNT -t $SD_API_TOKEN

Once created select the startup script when creating your VPS

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Monday  —  Friday.

10am  —  6pm UK.

Dedicated Support.