aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.php34
-rwxr-xr-xcreate_image.sh1
-rw-r--r--daemon.php158
-rw-r--r--status.php65
4 files changed, 141 insertions, 117 deletions
diff --git a/client.php b/client.php
index ec7e354..ce4bc1f 100644
--- a/client.php
+++ b/client.php
@@ -1,23 +1,27 @@
<?php
- // Gentoaster build daemon client
- // Licensed under GPL v3, see COPYING file
+ // Gentoaster build daemon client
+ // Licensed under GPL v3, see COPYING file
- if(!isset($argv[1])) die("No config file provided\n");
+ if(!isset($argv[1])) die("No config file provided\n");
- $client= new GearmanClient();
- $client->addServer();
+ $client= new GearmanClient();
+ $client->addServer();
- echo "Sending job\n";
+ echo "Sending job\n";
- $handle = $client->doBackground("invoke_image_build", file_get_contents($argv[1]));
- $handlehash = md5($handle);
+ $iniString = file_get_contents($argv[1]);
- echo "Job sent, handle was ".$handle." - hash ".$handlehash."\n";
+ $handle = $client->doBackground("invoke_image_build", $iniString);
+ $handlehash = md5($handle);
+
+ echo "Job sent, handle was ".$handle." - hash ".$handlehash."\n";
+
+ $db = mysql_connect("localhost", "gentoaster", "");
+ if(!$db) die("Could not connect to database ".mysql_error());
+ mysql_select_db("gentoaster");
+ $query = "INSERT INTO builds (id, handle)".
+ ." VALUES('".$handlehash."','".$handle."')";
+ mysql_query($query);
+ echo "Job handle mapping added to database\n";
- $db = mysql_connect("localhost","gentoaster","");
- if(!$db) die("Could not connect to database ".mysql_error());
- mysql_select_db("gentoaster");
- mysql_query("INSERT INTO builds (id, handle) VALUES('".$handlehash."','".$handle."')");
- echo "Job handle mapping added to database\n";
-?>
diff --git a/create_image.sh b/create_image.sh
index 94004a8..f87e507 100755
--- a/create_image.sh
+++ b/create_image.sh
@@ -192,6 +192,7 @@ echo "Step 13: Setting timezone to ${TIMEZONE}"
linux32 chroot . cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime &>> ${LOG_FILE}
echo "Step 14: Setting hostname to ${HOSTNAME}"
+linux32 chroot . /bin/bash -c "echo hostname='${HOSTNAME}' > /etc/conf.d/hostname" &>> ${LOG_FILE}
linux32 chroot . /bin/bash -c "echo 127.0.0.1 ${HOSTNAME}.local ${HOSTNAME} localhost > /etc/hosts" &>> ${LOG_FILE}
echo "Step 15: Copying new fstab"
diff --git a/daemon.php b/daemon.php
index af7143b..a8b36a5 100644
--- a/daemon.php
+++ b/daemon.php
@@ -1,76 +1,90 @@
<?php
- // Gentoaster build daemon worker
- // Licensed under GPL v3, see COPYING file
+ // Gentoaster build daemon worker
+ // Licensed under GPL v3, see COPYING file
+
+ $configurationsPath = "/var/www/gentoaster";
+ $gentoasterPath = "/usr/share/gentoaster";
+ $toolName = "create_image.sh";
+
+ // DO NOT EDIT BELOW THIS LINE
+
+ $progressMagic = 23;
+
+ $worker = new GearmanWorker();
+ $worker->addServer();
+ $worker->addFunction("invoke_image_build", "image_build");
+ while ($worker->work());
+
+ function update_result($handle, $returncode, $result)
+ {
+ $result = trim($result);
+ echo "A job finished with return code ".$returncode.": ".$result."\n";
+ $db = mysql_connect("localhost", "gentoaster", "");
+ if(!$db) die("Could not connect to database ".mysql_error());
+ mysql_select_db("gentoaster");
+ $result = mysql_real_escape_string($result);
+ $query = "UPDATE builds".
+ " SET result = '".$result."', returncode = '".$returncode
+ "' WHERE handle = '".mysql_real_escape_string($handle)."'";
+ mysql_query($query);
+ return serialize(array($returncode, $result));
+ }
+
+ function image_build($job)
+ {
+ global $configurationsPath, $gentoasterPath, $toolName, $progressMagic;
+
+ $handle = $job->handle();
+ $handlehash = md5($handle);
+
+ echo "Processing job handle hash ".$handlehash."\n";
+
+ $configurationString = $job->workload();
+ $configurationArray = parse_ini_string($configurationString);
+
+ if ($configurationArray !== FALSE) {
+ if (isset($configurationArray["BUILD_ID"])) {
+ $buildID = $configurationArray["BUILD_ID"];
+ $buildPath = $configurationsPath."/".$buildID;
+ @mkdir($buildPath, 0777, true);
+
+ if (is_writable($buildPath)) {
+ chdir($buildPath);
+ file_put_contents("config.ini", $configurationString);
+ $toolArgs = "--config config.ini --compress";
+ $cmd = $gentoasterPath."/".$toolName." ".$toolArgs;
+ $processHandle = popen($cmd." 2>&1", "r");
+
+ $nonstatusOutput = "";
+
+ while (!feof($processHandle)) {
+ $progressLine = fgets($processHandle);
+ preg_match("/Step (.+):/", $progressLine, $matches);
+ if (sizeof($matches) > 0) {
+ $job->sendStatus($matches[1], $progressMagic);
+ } else {
+ $nonstatusOutput .= $progressLine;
+ }
+ }
+
+ $returncode = pclose($processHandle);
+
+ unlink("config.ini");
+
+ return update_result($handle, $returncode, $nonstatusOutput);
+ } else {
+ $error = "Configured build path is not writable";
+ return update_result($handle, -2, $error);
+ }
+ } else {
+ $error = "Configuration file is incomplete";
+ return update_result($handle, -3, $error);
+ }
+ } else {
+ $error = "Configuration string is not valid";
+ return update_result($handle, -4, $error);
+ }
+ }
- $configurations_path = "/var/www/gentoaster";
- $gentoaster_path = "/usr/share/gentoaster";
- $tool_name = "create_image.sh";
- // DO NOT EDIT BELOW THIS LINE
-
- $progress_magic = 23;
-
- $worker = new GearmanWorker();
- $worker->addServer();
- $worker->addFunction("invoke_image_build", "image_build");
- while ($worker->work());
-
- function update_result($handle, $returncode, $result) {
- $result = trim($result);
- echo "A job finished with return code ".$returncode.": ".$result."\n";
- $db = mysql_connect("localhost","gentoaster","");
- if(!$db) die("Could not connect to database ".mysql_error());
- mysql_select_db("gentoaster");
- mysql_query("UPDATE builds SET result = '".mysql_real_escape_string($result)."', returncode = '".$returncode."' WHERE handle = '".mysql_real_escape_string($handle)."'");
- return serialize(array($returncode, $result));
- }
-
- function image_build($job) {
- global $configurations_path, $gentoaster_path, $tool_name, $progress_magic;
-
- $handle = $job->handle();
- $handlehash = md5($handle);
-
- echo "Processing job handle hash ".$handlehash."\n";
-
- $configuration_string = $job->workload();
- $configuration_array = parse_ini_string($configuration_string);
-
- if($configuration_array !== FALSE && isset($configuration_array["BUILD_ID"])) {
- $build_id = $configuration_array["BUILD_ID"];
- $build_path = $configurations_path."/".$build_id;
- @mkdir($build_path, 0777, true);
-
- if(is_writable($build_path)) {
- chdir($build_path);
- file_put_contents("config.ini", $configuration_string);
- $tool_args = "--config config.ini --compress";
- $process_handle = popen($gentoaster_path."/".$tool_name." ".$tool_args." 2>&1", "r");
-
- $nonstatus_output = "";
-
- while(!feof($process_handle)) {
- $progress_line = fgets($process_handle);
- preg_match("/Step (.+):/", $progress_line, $matches);
- if(sizeof($matches) > 0) {
- $job->sendStatus($matches[1], $progress_magic);
- } else {
- $nonstatus_output .= $progress_line;
- }
- }
-
- $returncode = pclose($process_handle);
-
- unlink("config.ini");
-
- return update_result($handle, $returncode, $nonstatus_output);
- } else {
- return update_result($handle, -2, "Configured build path is not writable");
- }
- } else {
- return update_result($handle, -3, "Configuration string is not valid");
- }
- }
-
-?>
diff --git a/status.php b/status.php
index e5624dd..a69bc35 100644
--- a/status.php
+++ b/status.php
@@ -1,33 +1,38 @@
<?php
- if(!isset($argv[1])) die("No handle hash given\n");
- $db = mysql_connect("localhost","gentoaster","");
- if(!$db) die("Could not connect to database ".mysql_error()."\n");
- mysql_select_db("gentoaster");
- $result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($argv[1])."'");
- if(mysql_num_rows($result) == 1) {
- $handles = mysql_fetch_array($result);
- $handle = $handles[0];
- $client = new GearmanClient();
- $client->addServer();
+ if (!isset($argv[1])) die("No handle hash given\n");
+ $db = mysql_connect("localhost", "gentoaster", "");
+ if (!$db) die("Could not connect to database ".mysql_error()."\n");
+ mysql_select_db("gentoaster");
+ $query = "SELECT handle FROM builds ".
+ "WHERE id = '".mysql_real_escape_string($argv[1])."'";
+ $result = mysql_query($query);
+ if (mysql_num_rows($result) == 1) {
+ $handles = mysql_fetch_array($result);
+ $handle = $handles[0];
+ $client = new GearmanClient();
+ $client->addServer();
- $status = $client->jobStatus($handle);
- if($status[0]) {
- if($status[3] != 0) {
- echo "Running: " . ($status[1] ? "true" : "false") . ", progress: " . ceil($status[2]/$status[3]*100) . "%, numerator: " . $status[2] . ", denomintor: " . $status[3] . "\n";
- } else {
- echo "Task has not yet been processed\n";
- }
- } else {
- $result = mysql_query("SELECT returncode, result FROM builds WHERE id = '".mysql_real_escape_string($argv[1])."'");
- $jobres = mysql_fetch_array($result);
- if($jobres[0] !== NULL) {
- echo "Job returned with code ".$jobres[0].": ".$jobres[1]."\n";
- } else {
- echo "Job failed\n";
- }
- }
- } else {
- echo "Invalid handle hash\n";
- }
+ $status = $client->jobStatus($handle);
+ if ($status[0]) {
+ if ($status[3] != 0) {
+ echo "Running: " . ($status[1] ? "true" : "false");
+ echo ", progress: ".ceil($status[2]/$status[3]*100) . "%, ";
+ echo $status[2] . "/" . $status[3] . "\n";
+ } else {
+ echo "Task has not yet been processed\n";
+ }
+ } else {
+ $query = "SELECT returncode, result FROM builds ".
+ "WHERE id = '".mysql_real_escape_string($argv[1])."'";
+ $result = mysql_query($query);
+ $jobres = mysql_fetch_array($result);
+ if ($jobres[0] !== NULL) {
+ echo "Job returned with code ".$jobres[0].": ".$jobres[1]."\n";
+ } else {
+ echo "Job failed\n";
+ }
+ }
+ } else {
+ echo "Invalid handle hash\n";
+ }
-?>