mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Allowing controller to restart itself.
This commit is contained in:
parent
5c8f164c1a
commit
0d155c9311
4 changed files with 41 additions and 2 deletions
|
|
@ -226,6 +226,26 @@ def restart_service(name: str) -> dict:
|
|||
return {"success": False, "error": f"Unknown service: {name}"}
|
||||
|
||||
systemd_name = service_config.get("systemd_name", name)
|
||||
|
||||
# Special handling for self-restart: use Popen to avoid blocking
|
||||
# (the process will be killed before subprocess.run can return)
|
||||
if systemd_name == "wrolpi-controller":
|
||||
try:
|
||||
subprocess.Popen(["systemctl", "restart", systemd_name])
|
||||
return {
|
||||
"success": True,
|
||||
"service": name,
|
||||
"action": "restart",
|
||||
"pending": True,
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"service": name,
|
||||
"action": "restart",
|
||||
"error": str(e),
|
||||
}
|
||||
|
||||
result = _run_systemctl("restart", systemd_name)
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -730,7 +730,7 @@
|
|||
|
||||
<!-- Logs Modal -->
|
||||
<div id="logs-modal" class="modal" onclick="if(event.target===this)closeLogsModal()">
|
||||
<div class="modal-content" style="width: 80%; max-width: none;">
|
||||
<div class="modal-content" style="width: 90%; max-width: none;">
|
||||
<div class="modal-header">
|
||||
<h3 id="logs-title">Service Logs</h3>
|
||||
<button class="modal-close" onclick="closeLogsModal()">×</button>
|
||||
|
|
|
|||
|
|
@ -219,6 +219,26 @@ class TestServiceActions:
|
|||
assert result["action"] == expected_action
|
||||
|
||||
|
||||
class TestControllerSelfRestart:
|
||||
"""Tests for controller self-restart behavior."""
|
||||
|
||||
def test_controller_restart_uses_popen(self):
|
||||
"""Controller restart should use Popen to avoid blocking on self-termination."""
|
||||
with mock.patch("subprocess.Popen") as mock_popen:
|
||||
result = restart_service("wrolpi-controller")
|
||||
mock_popen.assert_called_once_with(["systemctl", "restart", "wrolpi-controller"])
|
||||
assert result["success"] is True
|
||||
assert result["pending"] is True
|
||||
assert result["action"] == "restart"
|
||||
|
||||
def test_controller_restart_handles_exception(self):
|
||||
"""Controller restart should handle exceptions gracefully."""
|
||||
with mock.patch("subprocess.Popen", side_effect=Exception("popen failed")):
|
||||
result = restart_service("wrolpi-controller")
|
||||
assert result["success"] is False
|
||||
assert "popen failed" in result["error"]
|
||||
|
||||
|
||||
class TestGetServiceLogs:
|
||||
"""Tests for get_service_logs function."""
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ services:
|
|||
build:
|
||||
context: .
|
||||
dockerfile: docker/controller/Dockerfile
|
||||
container_name: wrolpi-controller
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8087:8087"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue