Looking at the API docs https://developers.digitalocean.com/documentation/v2/
You should be able to see the status of the Droplet (see the droplets section).
Using your logic you could:
- Create droplet and store the id in a variable
- Sleep 1 Minute
- Call the droplet with the id /v2/droplets/$DROPLET_ID.
- Test the response status (A status string indicating the state of the Droplet instance. This may be "new", "active", "off", or "archive".).
- If status == new do something
UPDATE
Another method would be to modify the droplet as it is created. With Digital ocean you can pass User Data
, previously I have used this to configure servers automatically, here is an example.
$user_data = <<<EOD
#!/bin/bash
apt-get update
apt-get -y install apache2
apt-get -y install php5
apt-get -y install php5-mysql
apt-get -y install unzip
service apache2 restart
cd /var/www/html
mkdir pack
cd pack
wget --user {$wgetUser} --password {$wgetPass} http://x.x.x.x/pack.tar.gz
tar -xvf pack.tar.gz
php update.php
EOD;
//Start of the droplet creation
$data = array(
"name"=>"AutoRes".$humanProv.strtoupper($lang),
"region"=>randomRegion(),
"size"=>"512mb",
"image"=>"ubuntu-14-04-x64",
"ssh_keys"=>$sshKey,
"backups"=>false,
"ipv6"=>false,
"user_data"=>$user_data,
"private_networking"=>null,
);
$chDroplet = curl_init('https://api.digitalocean.com/v2/droplets');
curl_setopt($chDroplet, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($chDroplet, CURLOPT_POSTFIELDS, json_encode($data) );
curl_setopt($chDroplet, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$apiKey,
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($data)),
));
Basically once the droplet is active it will run these commands and then download a tar.gz file from my server and execute it, you could potentially create update.php to call your server and therefore update it that the droplet is online.