diff options
author | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-07-08 03:44:09 +0100 |
---|---|---|
committer | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-07-08 03:44:09 +0100 |
commit | 9d971158f5fb4888f8ac33540c85801a6064bcda (patch) | |
tree | 6d3832c0160cb4bee165de0c3918c19176072883 /daemon.php | |
parent | Fix minimal config and incorrect cachedkernel logic (diff) | |
download | gentoaster-9d971158f5fb4888f8ac33540c85801a6064bcda.tar.gz gentoaster-9d971158f5fb4888f8ac33540c85801a6064bcda.tar.bz2 gentoaster-9d971158f5fb4888f8ac33540c85801a6064bcda.zip |
Added basic Gearman worker/client
Client is only for testing purposes, real client will be part of WebUI
Worker needs better error handling, does work in current form though
Added progress reporting hack in create_image.sh, going to replace this with a better system soon
Diffstat (limited to 'daemon.php')
-rw-r--r-- | daemon.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/daemon.php b/daemon.php new file mode 100644 index 0000000..deeb0d6 --- /dev/null +++ b/daemon.php @@ -0,0 +1,61 @@ +<?php + + // Gentoaster build daemon worker + // Licensed under GPL v3, see COPYING file + + $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 image_build($job) { + global $configurations_path, $gentoaster_path, $tool_name, $progress_magic; + + echo "Got job ID ".$job->handle(). "(".md5($job->handle()).")\n"; + + $configuration_string = $job->workload(); + $configuration_array = parse_ini_string($configuration_string); + + if($configuration_array !== FALSE) { + $build_id = $configuration_array["BUILD_ID"]; + $build_path = $configurations_path."/".$build_id; + mkdir($build_path); + + if(is_writable($build_path)) { + chdir($build_path); + file_put_contents("config.ini", $configuration_string); + $tool_args = "--config config.ini --cachedkernel"; + $process_handle = popen($gentoaster_path."/".$tool_name." ".$tool_args, "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; + } + } + + pclose($process_handle); + + return $nonstatus_output; + } else { + echo "Configured build path is not writable"; + } + } else { + echo "Configuration string is not valid"; + } + } + +?> |