in tools/gsnapshot/Instances.cs [135:192]
public bool CheckInstanceRunning(string projectId, ComputeData.Instance instance,
bool forceStopServer, string operation) {
if (instance.Status != "RUNNING" && instance.Status != "TERMINATED") {
_logger.LogCritical(
$"Instance state is not in a good state ({instance.Status}), waiting for 10 seconds...");
bool statusOk = false;
for (int i = 0; i < 10 && !statusOk; i++) {
System.Threading.Thread.Sleep(1000);
instance = GetInstance(projectId, instance);
if (instance.Status != "RUNNING" || instance.Status != "TERMINATED") {
statusOk = true;
}
}
if (!statusOk) {
_logger.LogCritical(
$"Instance state is not in a good state ({instance.Status}), timed out after 10 seconds.");
System.Environment.Exit(5);
}
}
if (instance.Status == "RUNNING") {
bool stopServer = forceStopServer;
if (!forceStopServer) {
if (operation == "snapshot") {
_logger.LogWarning($"Instance is running, do you want to stop it first?");
_logger.LogInformation(
$"(Stopping an instance guarantees a consistent snapshot from a clean shutdown, but is not required)");
}
if (operation == "rollback") {
_logger.LogWarning($"Instance is running, do you want proceed stopping it?");
_logger.LogInformation(
$"(Instance needs to be stopped to reattach disks from snapshots)");
}
stopServer = _utils.GetYesNo("Stop server (Y/n)?", true);
}
if (stopServer) {
_logger.LogWarning($"Stopping instance {instance.Name} now...");
bool serverStopped = StopInstance(projectId, instance).GetAwaiter().GetResult();
do {
var stoppingInstance = GetInstance(projectId, instance);
if (stoppingInstance.Status == "TERMINATED") {
_logger.LogInformation("Instance has been stopped successfully.");
break;
}
if (stoppingInstance.Status != "RUNNING" && stoppingInstance.Status != "STOPPING") {
_logger.LogCritical(
$"Unknown status encountered during instance stop ({stoppingInstance.Status}), but continuing.");
break;
}
System.Threading.Thread.Sleep(750);
} while (true);
}
if (!stopServer && operation == "rollback") {
_logger.LogCritical("Instance needs to be stopped to reattach rolled back disks!");
System.Environment.Exit(6);
}
}
return instance.Status == "RUNNING";
}