Prototype for icingacli web serve
This commit is contained in:
parent
29f007e537
commit
76c322901c
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Clicommands;
|
||||
|
||||
use Icinga\Cli\Command;
|
||||
use Exception;
|
||||
|
||||
class WebCommand extends Command
|
||||
{
|
||||
public function serveAction()
|
||||
{
|
||||
$fork = $this->params->get('daemonize');
|
||||
$basedir = $this->params->shift();
|
||||
$socket = $this->params->shift();
|
||||
|
||||
// TODO: Sanity check!!
|
||||
if ($socket === null) {
|
||||
$socket = '0.0.0.0:80';
|
||||
// throw new Exception('Socket is required');
|
||||
}
|
||||
if ($basedir === null) {
|
||||
throw new Exception('Basedir is required');
|
||||
}
|
||||
|
||||
if ($fork) {
|
||||
$this->forkAndExit();
|
||||
}
|
||||
$cmd = sprintf(
|
||||
'%s -S %s -t %s %s',
|
||||
readlink('/proc/self/exe'),
|
||||
$socket,
|
||||
$basedir,
|
||||
ICINGA_LIBDIR . '/Icinga/Application/webrouter.php'
|
||||
);
|
||||
// TODO: Store webserver log, switch uid, log index.php includes, pid file
|
||||
if ($fork) {
|
||||
exec($cmd);
|
||||
} else {
|
||||
passthru($cmd);
|
||||
}
|
||||
}
|
||||
|
||||
public function stopAction()
|
||||
{
|
||||
// TODO: No, that's NOT what we want
|
||||
$prog = readlink('/proc/self/exe');
|
||||
`killall $prog`;
|
||||
}
|
||||
|
||||
protected function forkAndExit()
|
||||
{
|
||||
$pid = pcntl_fork();
|
||||
if ($pid == -1) {
|
||||
throw new Exception('Could not fork');
|
||||
} else if ($pid) {
|
||||
echo $this->screen->colorize('[OK]')
|
||||
. " Icinga Web server forked successfully\n";
|
||||
fclose(STDIN);
|
||||
fclose(STDOUT);
|
||||
fclose(STDERR);
|
||||
exit;
|
||||
// pcntl_wait($status);
|
||||
} else {
|
||||
// child
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
|
||||
if ($_SERVER['REQUEST_URI'] === '/css/icinga.css') {
|
||||
include $baseDir . '/css.php';
|
||||
} elseif ($_SERVER['REQUEST_URI'] === '/js/icinga.min.js') {
|
||||
include $baseDir . '/js.php';
|
||||
} elseif (file_exists($baseDir . $_SERVER['REQUEST_URI'])) {
|
||||
return false;
|
||||
} else {
|
||||
include $baseDir . '/index.php';
|
||||
}
|
||||
|
Loading…
Reference in New Issue