From 11f05e43345185ebb60c1cd8a8b23078b5c352e6 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 29 Apr 2012 13:35:02 +0200 Subject: [PATCH] Container.Stop function --- frontend/classes/class.container.php | 17 +++++++++++++++++ frontend/test.php | 13 ++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index 30f0894..4988ec9 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -137,6 +137,23 @@ class Container extends CPHPDatabaseRecordClass } } + public function Stop() + { + $command = "vzctl stop {$this->sInternalId}"; + $result = $this->sNode->ssh->RunCommand($command, false); + + if($result->returncode == 0 && strpos($result->stderr, "Unable to stop") === false) + { + $this->uStatus = CVM_STATUS_STOPPED; + $this->InsertIntoDatabase(); + return true; + } + else + { + throw new ContainerStopException($result->stderr, $result->returncode, $this->sInternalId); + } + } + public function EnableTunTap() { // TODO: Finish EnableTunTap function, check whether tun module is available on host diff --git a/frontend/test.php b/frontend/test.php index 8f0491e..b61de56 100644 --- a/frontend/test.php +++ b/frontend/test.php @@ -7,7 +7,18 @@ $settings['master_pubkey'] = "/etc/cvm/key.pub"; $sContainer = new Container(1); -$sContainer->Start(); +if($_GET['action'] == "start") +{ + $sContainer->Start(); +} +elseif($_GET['action'] == "stop") +{ + $sContainer->Stop(); +} echo("Done!"); ?> +

+Start
+Stop
+