diff --git a/src/web/pi_cmds.py b/src/web/pi_cmds.py index c314170f..7ffb82b2 100644 --- a/src/web/pi_cmds.py +++ b/src/web/pi_cmds.py @@ -22,22 +22,6 @@ def systemd_service(service, action): } -def reboot_pi(): - """ - Reboots the Pi system - """ - subprocess.Popen(["sudo", "reboot"]) - return True - - -def shutdown_pi(): - """ - Shuts down the Pi system - """ - subprocess.Popen(["sudo", "shutdown", "-h", "now"]) - return True - - def running_env(): """ Returns (str) git and (str) env diff --git a/src/web/ractl_cmds.py b/src/web/ractl_cmds.py index 810c007e..26ce811d 100644 --- a/src/web/ractl_cmds.py +++ b/src/web/ractl_cmds.py @@ -3,6 +3,7 @@ Module for commands sent to the RaSCSI backend service. """ from settings import REMOVABLE_DEVICE_TYPES +from pi_cmds import systemd_service from socket_cmds import send_pb_command import rascsi_interface_pb2 as proto @@ -354,3 +355,26 @@ def set_log_level(log_level): result = proto.PbResult() result.ParseFromString(data) return {"status": result.status, "msg": result.msg} + + +def shutdown_pi(mode): + """ + Sends a SHUT_DOWN command to the server. + Takes (str) mode as an argument. + Returns (bool) status and (str) msg. + """ + # This section proactively stops the monitor_rascsi systemd service, if running + # Otherwise, the monitor_rascsi script's interrupt handler won't take effect + monitor_service = "monitor_rascsi.service" + monitor_status = systemd_service(monitor_service, "show") + if "ActiveState=active" in monitor_status["msg"]: + systemd_service(monitor_service, "stop") + + command = proto.PbCommand() + command.operation = proto.PbOperation.SHUT_DOWN + command.params["mode"] = str(mode) + + data = send_pb_command(command.SerializeToString()) + result = proto.PbResult() + result.ParseFromString(data) + return {"status": result.status, "msg": result.msg} diff --git a/src/web/templates/base.html b/src/web/templates/base.html index 8eea36a1..0a6c2765 100644 --- a/src/web/templates/base.html +++ b/src/web/templates/base.html @@ -29,6 +29,11 @@ document.getElementById("flash").innerHTML = "
" + Notification + " This process may take a while, and will continue in the background if you navigate away from this page.
"; window.scrollTo(0,0); } + + var shutdownNotify = function(Notification) { + document.getElementById("flash").innerHTML = "
" + Notification + " The Web Interface will become unresponsive momentarily. Reload this page after the Pi has started up again.
"; + window.scrollTo(0,0); + }