summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-06-23 19:20:43 -0400
committerEudyptula <eitan@mosenkis.net>2009-06-23 19:20:43 -0400
commit6d04b1a4f2a37852f5e546e96e252c54c3d770e6 (patch)
tree83de4eb8a5c8356d15d6cf25cec8c65b29d919ff /backend
parentIntegrated basic ANSI handling into logviewer, needs to be merged with logvie... (diff)
downloadingenue-6d04b1a4f2a37852f5e546e96e252c54c3d770e6.tar.gz
ingenue-6d04b1a4f2a37852f5e546e96e252c54c3d770e6.tar.bz2
ingenue-6d04b1a4f2a37852f5e546e96e252c54c3d770e6.zip
Major improvements to logging in frontend and backend; moved log_command function to sql_task class; minor fixes here and there
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/backend.php5
-rw-r--r--backend/functions/build.php29
-rw-r--r--backend/functions/execution.php60
3 files changed, 24 insertions, 70 deletions
diff --git a/backend/backend.php b/backend/backend.php
index d6e4cb4..7f8d5f0 100755
--- a/backend/backend.php
+++ b/backend/backend.php
@@ -22,6 +22,7 @@ while (true) {
if ($r->rowCount()) {
$build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
$build->start=time();
+ $build->status='build/running';
$build->write();
echo 'Starting build id='.$build->id."\n";
$image=null;
@@ -29,13 +30,15 @@ while (true) {
$image=build($build);
} catch (Exception $e) {
echo 'Caught exception: '.$e->getMessage()."\n";
+ $build->status='finished/failed: '.$e->getMessage();
}
$build->finish=time();
- $build->write();
echo 'Finished with build id='.$build->id."\n";
if (isset($image)) {
echo "Completed image at $image\n";
+ $build->status='finished/success';
}
+ $build->write();
}
echo 'Sleeping...';
sleep(5);
diff --git a/backend/functions/build.php b/backend/functions/build.php
index df3fea5..8f1bda8 100644
--- a/backend/functions/build.php
+++ b/backend/functions/build.php
@@ -9,7 +9,6 @@ function build(&$build) {
$makeconf['pkgdir']=$conf['pkgdir_root'].'/'.$profile->pkgdir;
$makeconf['chost']=$headers['chost'];
$makeconf['accept_keywords']=$headers['accept_keywords'];
- $build->status='build/started';
$build->write();
$W=WORK.'/build-'.$build->id;
fatal(log_status('Creating work directory '.$W, mkdir($W, 0700)));
@@ -26,8 +25,8 @@ function build(&$build) {
$makeconf['portage_tmpdir']=$W.'/tmp';
$makeconf['emerge_default_opts']=$conf['emerge_default_opts'];
$contents='';
- foreach ($makeconf as $name => $val) { // TODO maybe shell_escape $val
- $contents.=strtoupper($name).'="'.$val.'"'."\n";
+ foreach ($makeconf as $name => $val) {
+ $contents.=strtoupper($name).'='.escapeshellarg($val)."\n";
}
unset($makeconf);
fatal(log_status('Writing '.$C.'/make.conf', file_put_contents($C.'/etc/make.conf', $contents)));
@@ -37,16 +36,28 @@ function build(&$build) {
'PORTAGE_CONFIGROOT' => $C,
'PATH' => $_ENV['PATH']
);
- fatal(log_command($build, 'emerge --info', null, $env) ==0 );
- fatal(log_command($build, 'emerge -p system', null, $env) ==0 );
- fatal(log_command($build, 'emerge system', null, $env) ==0 );
+ sql_task::execute_task('emerge --info', $build, true, null, $env);
+// fatal(log_command($build, 'emerge --info', null, $env) == 0);
+ sql_task::execute_task('emerge -p system', $build, true, null, $env);
+// fatal(log_command($build, 'emerge -p system', null, $env) == 0);
+ sql_task::execute_task('emerge system', $build, true, null, $env);
+// fatal(log_command($build, 'emerge system', null, $env) == 0);
if (isset($opts['install_packages'])) {
- fatal(log_command($build, 'emerge -p '.$opts['install_packages'], null, $env) == 0);
+ $pkgs=array();
foreach (explode(' ', $opts['install_packages']) as $atom) {
- fatal(log_command($build, 'emerge '.$atom, null, $env) == 0);
+ $pkgs[]=escapeshellarg($atom);
+ }
+ sql_task::execute_task('emerge -p '.implode(' ', $pkgs), $build, true, null, $env);
+// fatal(log_command($build, 'emerge -p '.implode(' ', $pkgs), null, $env) == 0);
+ foreach ($pkgs as $atom) {
+ sql_task::execute_task('emerge '.$atom, $build, true, null, $env);
+// fatal(log_command($build, 'emerge '.$atom, null, $env) == 0);
}
}
- fatal(log_command($build, "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$W/image' .") == 0);
+ sql_task::execute_task("tar -p --same-owner -czvf '$W/image.tar.gz' -C '$W/image' .", $build, true, null, $env);
+// fatal(log_command($build, "tar -p --same-owner -czvf '$W/image.tar.gz' -C '$W/image' .") == 0);
+ chmod($W, 0755);
+ chmod("$W/image.tar.gz", 0644);
return "$W/image.tar.gz";
}
?>
diff --git a/backend/functions/execution.php b/backend/functions/execution.php
deleted file mode 100644
index 73cef31..0000000
--- a/backend/functions/execution.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-// TODO this should be part of the task class
-function log_command(&$build, $command, $path=null, $env=null) {
- log_msg("Executing $command... ", false);
- $descriptorspec=array(
- 0 => array('pipe', 'r'), // STDIN
- 1 => array('pipe', 'w'), // STDOUT
- 2 => array('pipe', 'w') // STDERR
- );
- $task=new sql_task(null, $build->id, $command, null);
- $task->start=time();
- $task->write();
- $p=proc_open($command, $descriptorspec, $pipes, $path, $env);
- foreach ($pipes as $pipe) {
- stream_set_blocking($pipe, 0);
- }
- $msg=0;
- while (true) {
- $status=proc_get_status($p);
- // We have to set these all to variables because stream_select requires pass by reference
- $null=null;
- $outs=array($pipes[1], $pipes[2]);
- $s=stream_select($outs, $null, $null, 1);
- if ($s) {
- $c=stream_get_contents($pipes[2]);
- if ($c) {
- // STDERR
- $entry=new sql_buildlog_entry($task->id, $msg++, time(), 'stderr', $c);
- $entry->write();
- }
- $c=stream_get_contents($pipes[1]);
- if ($c) {
- // STDOUT
- $entry=new sql_buildlog_entry($task->id, $msg++, time(), 'stdout', $c);
- $entry->write();
- }
- }
- if ($status['running'] === false) {
- $exit_status=$status['exitcode'];
- break;
- }
- }
- $task->finish=time();
- foreach ($pipes as $pipe) {
- fclose($pipe);
- }
- if (!isset($exit_status)) {
- $exit_status=proc_close($p);
- }
- $task->exit=$exit_status;
- $task->write();
- if ($exit_status == 0) {
- log_msg(color('[success]', 'green'));
- } else {
- log_msg(color('[exit code '.$exit_status.']', 'red'));
- }
- // Handle end status
- return $exit_status;
-}
-?>