diff --git a/startup/manager.lua b/startup/manager.lua index ab5095d..b3851a4 100644 --- a/startup/manager.lua +++ b/startup/manager.lua @@ -73,4 +73,29 @@ print("") print("Starting inventoryManager...") sleep(1) -shell.run("inventoryManager.lua") +-- Reboot listener: reboots this computer when the manager sends +-- a reboot command to itself (target = "all" or "manager") +local SYSTEM_CHANNEL = 4205 +local ROLE = "manager" + +local function rebootListener() + local m = peripheral.find("modem") + if not m then return end + m.open(SYSTEM_CHANNEL) + while true do + local _, _, channel, _, message = os.pullEvent("modem_message") + if channel == SYSTEM_CHANNEL and type(message) == "table" and message.type == "reboot" then + local target = message.target or "all" + if target == "all" or target == ROLE or target == tostring(os.getComputerID()) then + print("[SYSTEM] Reboot command received. Rebooting...") + sleep(0.5) + os.reboot() + end + end + end +end + +parallel.waitForAny( + function() shell.run("inventoryManager.lua") end, + rebootListener +)