openwrt: use Flukso UCI file as param input for heartbeat

This commit is contained in:
Bart Van Der Meerssche 2010-10-01 16:19:06 +02:00
parent 6889fa3594
commit 3d4c7dc5b2
1 changed files with 9 additions and 11 deletions

View File

@ -29,15 +29,11 @@ else
require 'xmlrpc.http' require 'xmlrpc.http'
require 'luci.sys' require 'luci.sys'
auth = require 'flukso.auth' local auth = require 'flukso.auth'
dbg = require 'flukso.dbg' local dbg = require 'flukso.dbg'
-- config parameters
local param = {server = 'logger.flukso.net',
xmlrpcaddress = 'http://logger.flukso.net/xmlrpc',
xmlrpcversion = '1',
xmlrpcmethod = 'logger.heartbeat'}
local uci = require 'luci.model.uci'.cursor()
local param = uci:get_all('flukso', 'main')
local monitor = {reset = tonumber(arg[1])} local monitor = {reset = tonumber(arg[1])}
-- open the connection to the syslog deamon, specifying our identity -- open the connection to the syslog deamon, specifying our identity
@ -58,9 +54,11 @@ else
dbg.vardump(monitor) dbg.vardump(monitor)
-- send a heartbeat method call -- send a heartbeat method call
local url = 'http://' .. param.home .. '/xmlrpc/' .. param.homeVersion
local pcall_ok, return_or_err, pong = pcall(xmlrpc.http.call, local pcall_ok, return_or_err, pong = pcall(xmlrpc.http.call,
param.xmlrpcaddress..'/'..param.xmlrpcversion, url,
param.xmlrpcmethod, 'logger.heartbeat',
auth, auth,
monitor) monitor)
@ -76,7 +74,7 @@ else
if tonumber(pong.upgrade) == monitor.version then --reset device if tonumber(pong.upgrade) == monitor.version then --reset device
os.execute('reboot') os.execute('reboot')
elseif tonumber(pong.upgrade) > monitor.version then -- upgrade device to specified version elseif tonumber(pong.upgrade) > monitor.version then -- upgrade device to specified version
os.execute('wget -P /tmp http://'..param.server..'/files/upgrade/upgrade.'..pong.upgrade) os.execute('wget -P /tmp http://'.. param.home ..'/files/upgrade/upgrade.'..pong.upgrade)
os.execute('chmod a+x /tmp/upgrade.'..pong.upgrade) os.execute('chmod a+x /tmp/upgrade.'..pong.upgrade)
os.execute('/tmp/upgrade.'..pong.upgrade) os.execute('/tmp/upgrade.'..pong.upgrade)
os.execute('rm /tmp/upgrade.'..pong.upgrade) os.execute('rm /tmp/upgrade.'..pong.upgrade)