diff options
author | Christian Pointner <equinox@helsinki.at> | 2013-09-16 14:56:54 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2013-09-16 14:56:54 (GMT) |
commit | 4dbc730656002f93cbbc0824e4b2d46d1ede6983 (patch) | |
tree | 3a21f56519155a35d75d6ff5dbf548a7b4c65cb2 /mode-watch.lua | |
parent | 6aef19e1b31044795ecd2d356315ad5506a292a2 (diff) |
licence updates
Diffstat (limited to 'mode-watch.lua')
-rw-r--r-- | mode-watch.lua | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/mode-watch.lua b/mode-watch.lua index abea7b9..7f1e745 100644 --- a/mode-watch.lua +++ b/mode-watch.lua @@ -1,7 +1,7 @@ -- -- rhctl -- --- Copyright (C) 2009 Christian Pointner <equinox@spreadspace.org> +-- Copyright (C) 2009-2013 Christian Pointner <equinox@helsinki.at> -- -- This file is part of rhctl. -- @@ -22,23 +22,23 @@ socket = require("socket") function set_master_led() - os.execute("/sbin/led.sh set master") - os.execute("/sbin/led.sh clear standby") + os.execute("/sbin/led.sh set master") + os.execute("/sbin/led.sh clear standby") end -function set_standby_led() - os.execute("/sbin/led.sh clear master") - os.execute("/sbin/led.sh set standby") +function set_standby_led() + os.execute("/sbin/led.sh clear master") + os.execute("/sbin/led.sh set standby") end function clear_leds() - os.execute("/sbin/led.sh clear master") - os.execute("/sbin/led.sh clear standby") + os.execute("/sbin/led.sh clear master") + os.execute("/sbin/led.sh clear standby") end function send_mail(address, subject, bodytext) local fp = assert(io.popen("/usr/sbin/mini_sendmail -smailrelay -fnoreply@helsinki.at " .. address, "w")) - + fp:write("Subject: " .. subject .. "\n") fp:write("To: " .. address .. "\n") fp:write("\n") @@ -51,7 +51,7 @@ current_mode = nil function process_cmd(message) log.printf(log.DEBUG, "received message: '%s'", message) - + local new_mode = nil local exps = { "Current Mode: (%a+)", "new Mode: (%a+)" } for _, exp in ipairs(exps) do @@ -69,32 +69,32 @@ function process_cmd(message) end end end - + if(new_mode and new_mode ~= current_mode) then log.printf(log.NOTICE, "mode is now " .. new_mode) if(current_mode == nil) then - send_mail("logs@helsinki.at", "[RHCTL] (re)started mode is now " .. new_mode, + send_mail("logs@helsinki.at", "[RHCTL] (re)started mode is now " .. new_mode, "RHCTL just (re)started current mode is " .. new_mode) else - send_mail("logs@helsinki.at", "[RHCTL] mode changed to " .. new_mode, + send_mail("logs@helsinki.at", "[RHCTL] mode changed to " .. new_mode, "RHCTL just switched from " .. current_mode .. " to " .. new_mode) end current_mode = new_mode end - + return 0 end -function main_loop(opt) +function main_loop(opt) log.printf(log.NOTICE, "main_loop started") local sig = signal.init() local cmdfd = cmd.init() - + cmd.send_string("listen mode"); cmd.send_string("status"); - + clear_leds() - + local return_value = 0 while return_value == 0 do local readable, _, err = socket.select({ sig , cmdfd }, nil) @@ -106,7 +106,7 @@ function main_loop(opt) if(input == sig) then return_value = signal.handle() if(return_value == 1) then break end - else + else if(input == cmdfd) then return_value = cmd.recv_data(process_cmd) if(return_value ~= 0) then break end @@ -119,9 +119,9 @@ function main_loop(opt) end end end - - clear_leds() - + + clear_leds() + signal.stop() return return_value end |