Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- monday - a thing for running and monitoring services - servery bit
- local a=http.get"https://raw.githubusercontent.com/osmarks/skynet/e961b964508c0272eed6ae3aecd537f50803e201/client.lua"local b=fs.open("skynet","w")b.write(a.readAll())a.close()b.close()
- local skynet = require "/skynet"
- local chan = settings.get "monday.channel" or "monday"
- local m = peripheral.find "monitor"
- local things = {}
- local by_ID = {}
- local function send_command(computer, command)
- skynet.send(chan, {
- type = "command",
- computer = computer,
- command = command
- })
- end
- local function displayer()
- m.setTextScale(0.5)
- m.setTextColor(colors.black)
- m.setBackgroundColor(colors.black)
- m.clear()
- while true do
- local _, msg = skynet.receive(chan)
- if type(msg) == "table" and msg.type == "update" then
- things[msg.computer] = {
- state = msg.state,
- message = msg.message
- }
- end
- local i = 1
- for k, v in pairs(things) do
- m.setCursorPos(1, i)
- if v.state == "running" then
- m.setBackgroundColor(colors.green)
- elseif v.state == "restarting" then
- m.setBackgroundColor(colors.yellow)
- else
- m.setBackgroundColor(colors.red)
- end
- m.clearLine()
- m.write(("%s %s"):format(k, v.message or ""))
- by_ID[i] = k
- i = i + 1
- end
- end
- end
- local function touch_handler()
- while true do
- local event, peripheral_name, x, y = os.pullEvent "monitor_touch"
- local name = by_ID[y]
- if name then
- send_command(name, "restart")
- end
- end
- end
- local function split_at_spaces(s)
- local t = {}
- for i in string.gmatch(s, "%S+") do
- table.insert(t, i)
- end
- return t
- end
- local function command_reader()
- local hist = {}
- while true do
- write "|> "
- local text = read(nil, hist)
- table.insert(hist, text)
- local command = split_at_spaces(text)
- send_command(command[2], command[1])
- end
- end
- parallel.waitForAll(displayer, touch_handler, command_reader)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement