| [c455d7b] | 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2016 - 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | namespace GnuBoat;
|
|---|
| 20 |
|
|---|
| 21 | require_once(__DIR__ ."/../autoloader.php");
|
|---|
| 22 |
|
|---|
| 23 | class ServiceShutdown extends Service
|
|---|
| 24 | {
|
|---|
| 25 | function __construct()
|
|---|
| 26 | {
|
|---|
| 27 | parent::__construct();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | public function process()
|
|---|
| 31 | {
|
|---|
| 32 | $debug = $this->debug();
|
|---|
| 33 | $config = new Config();
|
|---|
| 34 |
|
|---|
| 35 | $handle = @fopen($config->shutdownRequestFile(), "w");
|
|---|
| 36 | if($handle === false){
|
|---|
| 37 | $message = "Could not create file (". $config->shutdownRequestFile() .") to indicate shutdown to the daemon.";
|
|---|
| 38 | if($debug > 0)
|
|---|
| 39 | echo $message;
|
|---|
| 40 | error_log($message);
|
|---|
| 41 | $result["shutdownstart"] = -1;
|
|---|
| 42 | $result["errormessage"] = $message;
|
|---|
| 43 | }
|
|---|
| 44 | else{
|
|---|
| 45 | $shutdownTime = new \DateTime('NOW');
|
|---|
| 46 | $shutdownTime->modify("+15 seconds");
|
|---|
| 47 | fwrite($handle, $shutdownTime->format(\DateTime::ATOM));
|
|---|
| 48 | $result["shutdownstart"] = $shutdownTime->format(\DateTime::ATOM);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | header('Content-Type: application/json');
|
|---|
| 52 | if($debug > 0){
|
|---|
| 53 | echo json_encode($result, JSON_PRETTY_PRINT) ."\n";
|
|---|
| 54 | }
|
|---|
| 55 | else{
|
|---|
| 56 | echo json_encode($result) ."\n";
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | ?>
|
|---|