[fsync] create a dependency towards enable_lan_branch

This commit is contained in:
Bart Van Der Meerssche 2011-04-28 13:53:23 +02:00
parent d08901f34e
commit 9e396e66ad
1 changed files with 23 additions and 13 deletions

View File

@ -50,7 +50,8 @@ local flukso = uci:get_all('flukso')
local MAX_SENSORS = tonumber(flukso.main.max_sensors) local MAX_SENSORS = tonumber(flukso.main.max_sensors)
local MAX_ANALOG_SENSORS = tonumber(flukso.main.max_analog_sensors) local MAX_ANALOG_SENSORS = tonumber(flukso.main.max_analog_sensors)
local RESET_COUNTERS = (flukso.main.reset_counters == '1') local RESET_COUNTERS = (flukso.main.reset_counters == '1')
local SYNC_TO_SERVER = (flukso.daemon.enable_wan_branch == '1') local WAN_ENABLED = (flukso.daemon.enable_wan_branch == '1')
local LAN_ENABLED = (flukso.daemon.enable_lan_branch == '1')
local METERCONST_FACTOR = 0.449 local METERCONST_FACTOR = 0.449
@ -314,6 +315,13 @@ local function commit(ctrl)
send(ctrl, COMMIT) send(ctrl, COMMIT)
end end
--- Remove all /sensor/xyz endpoint mappings to the cgi script.
-- @return none
local function remove_symlinks()
for symlink in nixio.fs.dir(API_PATH) do
nixio.fs.unlink(API_PATH .. symlink)
end
end
--- Map /sensor/xyz endpoints to the cgi script. --- Map /sensor/xyz endpoints to the cgi script.
-- @return none -- @return none
@ -321,11 +329,6 @@ local function create_symlinks()
-- make sure /www/sensor exists -- make sure /www/sensor exists
nixio.fs.mkdirr(API_PATH) nixio.fs.mkdirr(API_PATH)
-- clean up old symlinks
for symlink in nixio.fs.dir(API_PATH) do
nixio.fs.unlink(API_PATH .. symlink)
end
-- generate new symlinks -- generate new symlinks
for i = 1, MAX_SENSORS do for i = 1, MAX_SENSORS do
if flukso[tostring(i)] ~= nil if flukso[tostring(i)] ~= nil
@ -344,6 +347,12 @@ local function create_symlinks()
end end
end end
--- Remove the avahi-daemon flukso.service xml file.
-- @return none
local function remove_avahi_config()
nixio.fs.unlink(AVAHI_PATH)
end
--- Generate a new flukso.service xml file for the avahi-daemon. --- Generate a new flukso.service xml file for the avahi-daemon.
-- @return none -- @return none
local function create_avahi_config() local function create_avahi_config()
@ -373,10 +382,7 @@ local function create_avahi_config()
avahi.tail[3] = ' </service>' avahi.tail[3] = ' </service>'
avahi.tail[4] = '</service-group>' avahi.tail[4] = '</service-group>'
-- remove the old flukso.service -- generate the new flukso service
nixio.fs.unlink(AVAHI_PATH)
-- generate the new one
fd = nixio.open(AVAHI_PATH, O_RDWR_CREAT) fd = nixio.open(AVAHI_PATH, O_RDWR_CREAT)
print(string.format('generating a new %s', AVAHI_PATH)) print(string.format('generating a new %s', AVAHI_PATH))
@ -501,12 +507,16 @@ ctrl_close(ctrl)
-- sync config locally -- sync config locally
create_symlinks() remove_symlinks()
create_avahi_config() remove_avahi_config()
if LAN_ENABLED then
create_symlinks()
create_avahi_config()
end
-- sync config with the server -- sync config with the server
if SYNC_TO_SERVER then if WAN_ENABLED then
phone_home() phone_home()
end end