Thought it was time for a tutorial on the feature called script_url
which seems to be relatively unknown. Although it's a great feature in terms of saving time while working with large clusters of servers.
So here's the thing, say that I have this bash script below:
apt-get update && apt-get upgrade
apt-get install htop nmap nload apache2 php-common mysql
...
And I want it to run once during deployment. What I do is that I place it anywhere it can be reached by a server, i.e on Github, on a object storage or even on another server. Then during deployment via API, I do my call to /v1/server/create
as usual:
{
"hostname": "web-server-2",
"label": "Second Web server",
"region": 201,
"image": 2102,
"plan": 2101,
"auto_backups": false,
"ipv6_networking": true,
"ddos_protection": false,
"private_networking": true,
"ssh_key": "5cb46fd8-1b2d-11e9-ab14-d663bd873d93",
"script_url": "",
}
Now, observe the script_url
parameter at the bottom of the list, just change it to the url pointing to your install script and it will run during the creation of the server. So what makes this feature useful compared to cloud-init for instance?
Well, if you're developing your app and want to give people an easy way to install your app, you usually have to provide documentation and plenty of instructions. But with this all you need to provide is a button "Deploy on 99Stack" and let it do this API call with script_url
set to your installation script.