. */ namespace GnuBoat; require_once(__DIR__ ."/../autoloader.php"); class ServiceShutdown extends Service { function __construct() { parent::__construct(); } public function process() { $debug = $this->debug(); $config = new Config(); $handle = @fopen($config->shutdownRequestFile(), "w"); if($handle === false){ $message = "Could not create file (". $config->shutdownRequestFile() .") to indicate shutdown to the daemon."; if($debug > 0) echo $message; error_log($message); $result["shutdownstart"] = -1; $result["errormessage"] = $message; } else{ $shutdownTime = new \DateTime('NOW'); $shutdownTime->modify("+15 seconds"); fwrite($handle, $shutdownTime->format(\DateTime::ATOM)); $result["shutdownstart"] = $shutdownTime->format(\DateTime::ATOM); } header('Content-Type: application/json'); if($debug > 0){ echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; } else{ echo json_encode($result) ."\n"; } } } ?>