From e44a0d464580decf710d5453a3af693e40648043 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 2 May 2012 16:33:26 +0200 Subject: [PATCH] Some fixes --- frontend/classes/class.container.php | 22 ++++++++++------------ frontend/cphp/class.databaserecord.php | 2 ++ frontend/cron.15.php | 24 ++++++++++++++++++++++++ frontend/test.php | 4 ++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index dd1268a..2658375 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -134,10 +134,10 @@ class Container extends CPHPDatabaseRecordClass --ostemplate {$this->sTemplate->sTemplateName} "); - //$result = $this->sNode->ssh->RunCommand($command, false); + $result = $this->sNode->ssh->RunCommand($command, false); $result->returncode = 0; - if($result->returncode == 0) + if($result->returncode == 0 && strpos($result->stderr, "ERROR") === false) { // TODO: set sensible defaults depending on container resource configuration // http://wiki.openvz.org/UBC_consistency_check @@ -148,18 +148,18 @@ class Container extends CPHPDatabaseRecordClass $this->uStatus = CVM_STATUS_CREATED; $this->InsertIntoDatabase(); - $sKMemSize = (isset($conf['sKMemSize'])) ? $conf['sKMemSize'] : $this->sGuaranteedRam * 250; + $sKMemSize = (isset($conf['sKMemSize'])) ? $conf['sKMemSize'] : $this->sGuaranteedRam * 65000; $sKMemSizeLimit = (isset($conf['sKMemSizeLimit'])) ? $conf['sKMemSizeLimit'] : (int)($sKMemSize * 1.1); $sLockedPages = (isset($conf['sLockedPages'])) ? $conf['sLockedPages'] : (int)($this->sGuaranteedRam * 1.5); $sShmPages = (isset($conf['sShmPages'])) ? $conf['sShmPages'] : $sLockedPages * 64; - $sOomGuarPages = (isset($conf['sOomGuarPages'])) ? $conf['sOomGuarPages'] : $this->sGuaranteedRam * 400; + $sOomGuarPages = (isset($conf['sOomGuarPages'])) ? $conf['sOomGuarPages'] : $this->sGuaranteedRam * 140; $sTcpSock = (isset($conf['sTcpSock'])) ? $conf['sTcpSock'] : $this->sGuaranteedRam * 3; $sOtherSock = (isset($conf['sOtherSock'])) ? $conf['sOtherSock'] : $this->sGuaranteedRam * 3; $sFLock = (isset($conf['sFLock'])) ? $conf['sFLock'] : (int)($this->sGuaranteedRam * 0.6); $sFLockLimit = (isset($conf['sFLockLimit'])) ? $conf['sFLockLimit'] : (int)($sFLock * 1.1); - $sTcpSndBuf = (isset($conf['sTcpSndBuf'])) ? $conf['sTcpSndBuf'] : (int)($this->sGuaranteedRam * 20000); - $sTcpRcvBuf = (isset($conf['sTcpRcvBuf'])) ? $conf['sTcpRcvBuf'] : (int)($this->sGuaranteedRam * 20000); - $sOtherBuf = (isset($conf['sOtherBuf'])) ? $conf['sOtherBuf'] : (int)($this->sGuaranteedRam * 20000); + $sTcpSndBuf = (isset($conf['sTcpSndBuf'])) ? $conf['sTcpSndBuf'] : (int)($this->sGuaranteedRam * 10000); + $sTcpRcvBuf = (isset($conf['sTcpRcvBuf'])) ? $conf['sTcpRcvBuf'] : (int)($this->sGuaranteedRam * 10000); + $sOtherBuf = (isset($conf['sOtherBuf'])) ? $conf['sOtherBuf'] : (int)($this->sGuaranteedRam * 10000); $sOtherBufLimit = (isset($conf['sOtherBufLimit'])) ? $conf['sOtherBufLimit'] : (int)($sTcpSndBuf * 2); $sTcpSndBufLimit = (isset($conf['sTcpSndBufLimit'])) ? $conf['sTcpSndBufLimit'] : (int)($sTcpSndBuf * 2); $sTcpRcvBufLimit = (isset($conf['sTcpRcvBufLimit'])) ? $conf['sTcpRcvBufLimit'] : (int)($sTcpRcvBuf * 2); @@ -167,7 +167,7 @@ class Container extends CPHPDatabaseRecordClass $sNumFile = (isset($conf['sNumFile'])) ? $conf['sNumFile'] : $this->sGuaranteedRam * 32; $sDCache = (isset($conf['sDCache'])) ? $conf['sDCache'] : $this->sGuaranteedRam * 16000; $sDCacheLimit = (isset($conf['sDCacheLimit'])) ? $conf['sDCacheLimit'] : (int)($sDCache * 1.1); - $sAvgProc = (isset($conf['sAvgProc'])) ? $conf['sAvgProc'] : (int)($this->sGuaranteedRam * 1.5); + $sAvgProc = (isset($conf['sAvgProc'])) ? $conf['sAvgProc'] : (int)($this->sGuaranteedRam); $command = shrink_command("vzctl set {$this->sInternalId} --onboot yes @@ -235,9 +235,7 @@ class Container extends CPHPDatabaseRecordClass --save ");*/ - pretty_dump($command); - - //$result = $this->sNode->ssh->RunCommand($command, false); + $result = $this->sNode->ssh->RunCommand($command, false); if($result->returncode == 0) { @@ -339,7 +337,7 @@ class Container extends CPHPDatabaseRecordClass if($result->returncode == 0) { $lines = split_lines($result->stdout); - $values = split_whitespace($lines[0]); + $values = split_whitespace(str_replace(":", " ", $lines[0])); $uIncoming = $values[1]; $uOutgoing = $values[9]; diff --git a/frontend/cphp/class.databaserecord.php b/frontend/cphp/class.databaserecord.php index fdbacef..0ee2680 100644 --- a/frontend/cphp/class.databaserecord.php +++ b/frontend/cphp/class.databaserecord.php @@ -345,6 +345,8 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass $this->sId = mysql_insert_id(); } + $this->PurgeCache(); + return $result; } else diff --git a/frontend/cron.15.php b/frontend/cron.15.php index 195025c..f1c5949 100644 --- a/frontend/cron.15.php +++ b/frontend/cron.15.php @@ -11,4 +11,28 @@ * licensing text. */ +$_CVM = true; +require("includes/include.base.php"); + +if($result = mysql_query_cached("SELECT * FROM containers")) +{ + foreach($result->data as $row) + { + $sContainer = new Container($row); + + //try + //{ + $sContainer->UpdateTraffic(); + //} + //catch (ContainerTrafficRetrieveException $e) + /*{ + if($sContainer->sCurrentStatus == CVM_STATUS_STARTED) + { + // This is not supposed to fail, as the container is running. + // Something shady going on. + // TODO: Log exception + } + }*/ + } +} ?> diff --git a/frontend/test.php b/frontend/test.php index 9a72610..8de9a5b 100644 --- a/frontend/test.php +++ b/frontend/test.php @@ -8,13 +8,13 @@ $settings['salt'] = "kAU0qM"; if($_GET['action'] == "deploy") { - $sContainer = new Container(2); + $sContainer = new Container(3); $sContainer->Deploy(); } else { - $sContainer = new Container(1); + $sContainer = new Container(3); if($_GET['action'] == "start") {