示例#1
0
 public static function archiver(array $path) : array
 {
     Site::requirePrivilege(Config::getCfg('permissions')['owner']);
     if (count($path) !== 5) {
         throw new Exception("Wrong number of parameters");
     }
     $board = Model::get()->getBoard(strtolower(alphanum($path[3])));
     switch (strtolower($path[4])) {
         case "start":
             self::ensurePOST();
             Archivers::run($board->getName());
             sleep(1);
             return ['result' => "Started"];
         case "stop":
             self::ensurePOST();
             Archivers::stop($board->getName());
             return ['result' => "Stopping"];
         case "output":
             self::ensureGET();
             return ['output' => Archivers::getOutput($board->getName())];
         case "error":
             self::ensureGET();
             return ['output' => Archivers::getError($board->getName())];
         case "clearerror":
             self::ensurePOST();
             Archivers::clearError($board->getName());
             return ['result' => 'success'];
         default:
             throw new Exception("Invalid command");
     }
 }
示例#2
0
require_once '../inc/config.php';
use Site\Archivers;
use Model\Model;
$boards = Model::get()->getBoards(true);
$log = function ($msg) {
    echo $msg . PHP_EOL;
    file_put_contents("check.log", $msg . PHP_EOL, FILE_APPEND);
};
$log("Checking at " . date('c'));
foreach ($boards as $board) {
    if (!$board->isArchive()) {
        continue;
    }
    $status = Archivers::getStatus($board->getName());
    switch ($status) {
        case Archivers::STOPPED_UNCLEAN:
            Archivers::run($board->getName());
            $log("Restarted uncleanly stopped archiver for " . $board->getName() . ".");
            break;
        case Archivers::RUNNING:
            $log("Archiver for {$board->getName()} is running normally.");
            break;
        case Archivers::STOPPING:
            $log("Archiver for {$board->getName()} is stopping normally.");
            break;
        case Archivers::STOPPED:
            $log("Archiver for {$board->getName()} is stopped normally.");
            break;
    }
}