| New file |
| | |
| | | /* |
| | | Calypso - Media Player Remote Control via HTTP for Raspberry Pi |
| | | Copyright (C) 2021-2023 Ulrich Hilger |
| | | |
| | | This program is free software: you can redistribute it and/or modify |
| | | it under the terms of the GNU Affero General Public License as |
| | | published by the Free Software Foundation, either version 3 of the |
| | | License, or (at your option) any later version. |
| | | |
| | | This program is distributed in the hope that it will be useful, |
| | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | | GNU Affero General Public License for more details. |
| | | |
| | | You should have received a copy of the GNU Affero General Public License |
| | | along with this program. If not, see <https://www.gnu.org/licenses/>. |
| | | */ |
| | | |
| | | package de.uhilger.calypso.actor; |
| | | |
| | | import com.sun.net.httpserver.HttpContext; |
| | | import java.io.IOException; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * Ein HTTP-Handler zum Stoppen der Anwendung |
| | | * |
| | | * @author Ulrich Hilger |
| | | */ |
| | | public class DownServerActor extends StopServerActor { |
| | | |
| | | public void run(HttpContext thisContext) { |
| | | Logger.getLogger(DownServerActor.class.getName()).info( |
| | | "Maschine wird in einer Minute ausgeschaltet."); |
| | | ProcessBuilder pb = new ProcessBuilder("sudo", "shutdown", "-h", "-P", "+1"); |
| | | try { |
| | | Process process = pb.start(); |
| | | } catch (IOException ex) { |
| | | Logger.getLogger(DownServerActor.class.getName()).log(Level.SEVERE, null, ex); |
| | | } |
| | | super.run(thisContext); |
| | | } |
| | | |
| | | /** |
| | | * Die Klasse AppStopper ermöglicht das asnychrone bzw. |
| | | * zeitgesteuerte Stoppen der Anwendung. |
| | | */ |
| | | class AppStopper extends TimerTask { |
| | | |
| | | @Override |
| | | public void run() { |
| | | Logger.getLogger(DownServerActor.class.getName()).info("Calypso beendet."); |
| | | System.exit(0); |
| | | } |
| | | } |
| | | |
| | | } |