diff options
Diffstat (limited to 'backend/backend.php')
-rwxr-xr-x | backend/backend.php | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/backend/backend.php b/backend/backend.php index 4e2209a..cde76f0 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -1,8 +1,5 @@ #!/usr/bin/php <?php -require_once(dirname(__FILE__).'/../shared/include/includes.php'); // USE __DIR__ once 5.3.0 is out (and 2 lines down) -require_once(BACKEND.'/include/signals.php'); -declare(ticks=1); $pidfile='/var/run/ingenue.pid'; // Doesn't work when not run as root $opts=getopt('fk'); if (isset($opts['f'])) { @@ -21,19 +18,19 @@ if (isset($opts['k'])) { if (is_file($pidfile)) { $pid=trim(file_get_contents($pidfile)); if (posix_kill($pid, 0)) { - debug("Sending SIGTERM to $pid"); + fputs(STDERR, "Sending SIGTERM to $pid"); if (!posix_kill($pid, SIGTERM)) { - debug("Failed to send SIGTERM to $pid"); + fputs(STDERR, "Failed to send SIGTERM to $pid"); die(1); } else { // TODO wait for $pid to exit } } else { - debug("Couldn't send signal 0 to $pid"); + fputs(STDERR, "Couldn't send signal 0 to $pid"); die(0); } } else { - debug('No PID file found'); + fputs(STDERR, 'No PID file found'); } die(); } @@ -43,9 +40,12 @@ if (is_file($pidfile)) { die("Found already running backend PID=$pid.\n"); } if (posix_geteuid() !== 0) - debug("Not running as root... this is not going to accomplish much."); + fputs(STDERR, "Not running as root... this is not going to accomplish much."); if (file_put_contents($pidfile, posix_getpid())) $unlinkpidfile=true; +require_once(dirname(__FILE__).'/../shared/include/includes.php'); // USE __DIR__ once 5.3.0 is out (and 2 lines down) +require_once(BACKEND.'/include/signals.php'); +declare(ticks=1); require_once(SHARED.'/include/dbinit.php'); while (true) { // TODO check first for builds that need to be resumed (and figure out how to resume things) @@ -58,7 +58,19 @@ while (true) { log_msg('Starting build id='.$build->id); $success=null; try { - $success=build($build); + $opts=$build->get_buildopts(); + $module=$opts['backend_module']; + $build_proc=$module.'_build'; + foreach (glob(BACKEND."/modules/$module/*.php") as $inc) { + require_once($inc); + } + // TODO check that build_proc exists + $workdir=WORK.'/build-'.$build->id; + fatal(log_status('Creating work directory '.$workdir, mkdir($workdir, 0700))); + $success=$build_proc($build, $opts, $workdir); + if (!$conf['debug']) { + execute_command('Delete work directory', 'rm -rf "'.$workdir.'"'); + } } catch (Exception $e) { log_msg('Caught exception: '.$e->getMessage()); $build->status='finished/failed: '.$e->getMessage(); @@ -75,8 +87,8 @@ while (true) { $build->write(); unset($build); } - log_msg('Sleeping...', false); +// log_msg('Sleeping...', false); sleep(5); - log_msg("done"); +// log_msg("done"); } ?> |