Skip to content

Instantly share code, notes, and snippets.

@jetbalsa
Last active June 5, 2017 01:01
Show Gist options
  • Save jetbalsa/4b1cdbe0f55f00d92c10ff1e2355c5b7 to your computer and use it in GitHub Desktop.
Save jetbalsa/4b1cdbe0f55f00d92c10ff1e2355c5b7 to your computer and use it in GitHub Desktop.
<?php
require("vendor/autoload.php");
$api = new RestClient([
'base_url' => "https://cp-par1.scaleway.com",
'headers' => ['X-Auth-Token' => "#####################", "Content-Type" => "application/json"],
]);
$result = $api->get("servers");
$server = $result->decode_response();
$result = $api->get("volumes");
$volumes = $result->decode_response();
$result = $api->get("ips");
$ips = $result->decode_response();
foreach($server->servers as $row){
echo "Stopping Servers" . PHP_EOL;
echo $row->id;
$result = $api->post("servers/" . $row->id . "/action", json_encode(["action" => "poweroff"]));
echo " DONE" . PHP_EOL;
}
while(true){
echo "Sleeping 30s" . PHP_EOL;
$seconds = 30;
for ($i = $seconds; $i > 0; --$i) {
echo $i;
usleep(250000);
echo '.';
usleep(250000);
echo '.';
usleep(250000);
echo '.';
usleep(250000);
}
$check = $api->get("servers");
$check = $check->decode_response();
foreach($check->servers as $row){
if($row->state_detail == "stopping"){echo "Servers still stopping" . PHP_EOL; continue 2;}
}
break;
}
foreach($server->servers as $row){
echo "Delete Servers" . PHP_EOL;
echo $row->id;
$result = $api->delete("servers/" . $row->id);
echo " DONE" . PHP_EOL;
}
foreach($volumes->volumes as $row){
echo "Delete volumes" . PHP_EOL;
echo $row->id;
$result = $api->delete("volumes/" . $row->id);
echo " DONE" . PHP_EOL;
}
foreach($ips->ips as $row){
echo "Delete ips" . PHP_EOL;
echo $row->id;
$result = $api->delete("ips/" . $row->id);
echo " DONE" . PHP_EOL;
}
adduser --system --group --shell /bin/bash archiveteam
apt-get update && apt-get install -y git-core libgnutls-dev lua5.1 liblua5.1-0 liblua5.1-0-dev screen python-dev python-pip bzip2 zlib1g-dev flex autoconf
pip install --upgrade seesaw
su -c "cd /home/archiveteam; git clone https://github.com/ArchiveTeam/pixiv-grab.git; cd pixiv-grab; ./get-wget-lua.sh" archiveteam
screen -dm su -c "cd /home/archiveteam/pixiv-grab/; run-pipeline pipeline.py --concurrent 6 --address '127.0.0.1' JRWR" archiveteam
<?php
//requires php-restclient in composor
//get your org id using this guide: https://www.scaleway.com/docs/retrieve-my-organization-id-throught-the-api/
$org = '####################';
require("vendor/autoload.php");
$api = new RestClient([
'base_url' => "https://cp-par1.scaleway.com",
'headers' => ['X-Auth-Token' => "###########", "Content-Type" => "application/json"],
]); // Make sure to Update your Auth Token found on the web panel!
//create 7 arm64 servers with ubuntu
$rootimg = "e1a0daf2-a61f-40bf-ba3c-f86ec4baa3bf"; // Ubuntu Xenial (16.04 latest)
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior1", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior2", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior3", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior4", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior5", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior6", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
$make = $api->post("servers", json_encode(["organization" => $org, "name" => "jrwrwarrior7", "image" => $rootimg, "commercial_type" => "ARM64-2GB"]));
echo $make->response_status_lines[0] . PHP_EOL;
echo "=========" . PHP_EOL;
echo "Starting Servers" . PHP_EOL;
$result = $api->get("servers");
$server = $result->decode_response();
$result = $api->get("volumes");
$volumes = $result->decode_response();
$result = $api->get("ips");
$ips = $result->decode_response();
foreach($server->servers as $row){
echo "Starting Servers" . PHP_EOL;
echo $row->id;
$result = $api->post("servers/" . $row->id . "/action", json_encode(["action" => "poweron"]));
echo $result->response_status_lines[0] . PHP_EOL;
}
while(true){
$seconds = 15;
$result = $api->get("servers");
$server = $result->decode_response();
for ($i = $seconds; $i > 0; --$i) {
echo $i;
usleep(250000);
echo '.';
usleep(250000);
echo '.';
usleep(250000);
echo '.';
usleep(250000);
}
$check = $api->get("servers");
$check = $check->decode_response();
foreach($check->servers as $row){
if($row->state_detail != "booted"){echo PHP_EOL . "Servers still starting " . PHP_EOL; var_dump($row->state_detail); continue 2;}
}
break;
}
echo "Deploying!" . PHP_EOL;
foreach($check->servers as $row){
echo "IP: " . $row->public_ip->address . PHP_EOL;
$ip = $row->public_ip->address;
exec('ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@'.$ip.'" bash -s" -- < script.sh > '.$ip.'.log &');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment