mirror of
https://github.com/akuker/RASCSI.git
synced 2024-08-20 13:29:27 +00:00
Better Pi shutdown handling in Web Interface (#522)
* Add shutdown method * Use shutdown method * Use proto shutdown commands; remove old shell commands * Add explicit monitor_rascsi shutdown * Better method name * Add code comment * Fix bug
This commit is contained in:
parent
0eb9e50d18
commit
39c65beb99
@ -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
|
||||
|
@ -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}
|
||||
|
@ -29,6 +29,11 @@
|
||||
document.getElementById("flash").innerHTML = "<div class='message'>" + Notification + " This process may take a while, and will continue in the background if you navigate away from this page.</div>";
|
||||
window.scrollTo(0,0);
|
||||
}
|
||||
|
||||
var shutdownNotify = function(Notification) {
|
||||
document.getElementById("flash").innerHTML = "<div class='message'>" + Notification + " The Web Interface will become unresponsive momentarily. Reload this page after the Pi has started up again.</div>";
|
||||
window.scrollTo(0,0);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js">
|
||||
|
@ -618,19 +618,19 @@
|
||||
Raspberry Pi Operations
|
||||
</summary>
|
||||
<ul>
|
||||
<li>Issue reboot or shutdown commands to the Raspberr Pi.</li>
|
||||
<li>Issue reboot or shutdown commands to the Raspberry Pi.</li>
|
||||
<li>You can also restart the RaSCSI backend service here.</li>
|
||||
</ul>
|
||||
</details>
|
||||
<table style="border: none">
|
||||
<tr style="border: none">
|
||||
<td style="border: none; vertical-align:top;">
|
||||
<form action="/pi/reboot" method="post" onsubmit="return confirm('Reboot Pi?')">
|
||||
<form action="/pi/reboot" method="post" onclick="if (confirm('Reboot the Raspberry Pi?')) shutdownNotify('Rebooting the Raspberry Pi...'); else event.preventDefault();">
|
||||
<input type="submit" value="Reboot Raspberry Pi">
|
||||
</form>
|
||||
</td>
|
||||
<td style="border: none; vertical-align:top;">
|
||||
<form action="/pi/shutdown" method="post" onsubmit="return confirm('Shutdown Pi?')">
|
||||
<form action="/pi/shutdown" method="post" onclick="if (confirm('Shut down the Raspberry Pi?')) shutdownNotify('Shutting down the Raspberry Pi...'); else event.preventDefault();">
|
||||
<input type="submit" value="Shut Down Raspberry Pi">
|
||||
</form>
|
||||
</td>
|
||||
|
@ -37,8 +37,6 @@ from file_cmds import (
|
||||
read_drive_properties,
|
||||
)
|
||||
from pi_cmds import (
|
||||
shutdown_pi,
|
||||
reboot_pi,
|
||||
running_env,
|
||||
systemd_service,
|
||||
running_proc,
|
||||
@ -60,6 +58,7 @@ from ractl_cmds import (
|
||||
get_device_types,
|
||||
reserve_scsi_ids,
|
||||
set_log_level,
|
||||
shutdown_pi,
|
||||
)
|
||||
from device_utils import (
|
||||
sort_and_format_devices,
|
||||
@ -662,16 +661,6 @@ def unreserve_id():
|
||||
flash(process["msg"], "error")
|
||||
return redirect(url_for("index"))
|
||||
|
||||
@APP.route("/pi/reboot", methods=["POST"])
|
||||
@login_required
|
||||
def restart():
|
||||
"""
|
||||
Restarts the Pi
|
||||
"""
|
||||
reboot_pi()
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
||||
@APP.route("/rascsi/restart", methods=["POST"])
|
||||
@login_required
|
||||
def rascsi_restart():
|
||||
@ -705,13 +694,23 @@ def rascsi_restart():
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
||||
@APP.route("/pi/reboot", methods=["POST"])
|
||||
@login_required
|
||||
def restart():
|
||||
"""
|
||||
Restarts the Pi
|
||||
"""
|
||||
shutdown_pi("reboot")
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
||||
@APP.route("/pi/shutdown", methods=["POST"])
|
||||
@login_required
|
||||
def shutdown():
|
||||
"""
|
||||
Shuts down the Pi
|
||||
"""
|
||||
shutdown_pi()
|
||||
shutdown_pi("system")
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user