Cloud-init is a service that allows you fetch custom user data scripts when provisioning new servers via Client Portal or API.
When ordering a new server through Cherry Servers API you can automate various server configuration tasks by fetching user data directives upon server deployment. Your provided tasks will be executed when your server boots for the first time. There are two ways of doing that - shell scripts and cloud-init directives.
Shell scripts
This is the simplest way to send instructions to a newly deployable server that are going to be executed when the server boots for the first time. Your Shell script has to start with "#!/bin/bash" line, otherwise user data directives will be rejected. Your script is then executed non-interactively with root access rights by default.
A simple example:
#!/bin/bash
yum install -y httpd
apt install -y nginx
Cloud-Init directives
Cloud-Init directives are also executed when your server boots for the first time, but the syntax is slightly different. Your scenario must start with "#cloud-config" line, otherwise user data directives will be rejected. For further reference we recommend checking cloud-init official documentation: https://cloudinit.readthedocs.io/en/latest/index.html
A simple example:
#cloud-config
packages:
- httpd
- mariadb-server
runcmd:
- systemctl start httpd
- sudo systemctl enable httpd
- [ sh, -c, "chmod 755 /var/tmp" ]
In order to pass these scenarios to Cherry Servers API, they have to be converted into base64 format. On a Linux system you would do the following for your test.sh or test.yaml file:
:# base64 test.sh
IyEvYmluL2Jhc2gKeXVtIGluc3RhbGwgLXkgaHR0cGQKYXB0IGluc3RhbGwgLXkgbmdpbngK
:# base64 test.yaml
I2Nsb3VkLWNvbmZpZwpwYWNrYWdlczogCiAtIGh0dHBkIAogLSBtYXJpYWRiLXNlcnZlcgpydW5j
bWQ6CiAtIHN5c3RlbWN0bCBzdGFydCBodHRwZAogLSBzdWRvIHN5c3RlbWN0bCBlbmFibGUgaHR0
cGQKIC0gWyBzaCwgLWMsICJjaG1vZCA3NTUgL3Zhci90bXAiIF0K
This output text then has to be fetched via Cherry Servers API user_data parameter when ordering a new server.
Please bear in mind when using user data functionality:
- Server provisioning will take longer than 3 minutes. Linux servers with user_data parameter fetched will take up to 10 minutes, plus any required time for user_data script to complete;
- Additional scripts should be used with responsibly, since misused scripts can disrupt the system;
- In case the script you used did not run as you expected, please check cloud-init logs, that can be found here:
o /var/log/cloud-init.log
o /var/log/cloud-init-output.log
- User-Data is currently available for Linux systems only.
Integrations
User-Data is currently supported by our cherrygo GO LANG library Terraform module and cherryctl.
Terraform module for your OS can be downloaded here: http://downloads.cherryservers.com/other/terraform/
Cherryctl program can be downloaded from here:
https://github.com/cherryservers/cherryctl
More detailed instructions are available on our cherryservers GITHUB account: https://github.com/cherryservers