From 7580c60d80239c3a880e124c550c2353f8153d82 Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Thu, 6 Dec 2018 09:41:54 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?utf8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81?= =?utf8?q?=D1=81=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bin/weathermon | 14 ++++++++++++++ init.d/weathermon | 2 -- lib/wm_util.lua | 30 ++++++++++++++++++++++++++---- openwrt-web/meteo/archive.js | 2 +- web/config_local.php~ | 13 ------------- 5 files changed, 41 insertions(+), 20 deletions(-) delete mode 100644 web/config_local.php~ diff --git a/bin/weathermon b/bin/weathermon index 2314e1a..8da4696 100755 --- a/bin/weathermon +++ b/bin/weathermon @@ -1,6 +1,7 @@ #!/usr/bin/lua local json = require("json") +local signal = require("posix.signal") require "wm_util" @@ -307,6 +308,19 @@ end getConfig(arg[1]) +signal.signal(signal.SIGTERM, function(signum) + + printLog("Terminating...") + local pids = get_children() + for k,v in pairs(pids) do + printLog("Terminating subprocess "..tostring(v).."...") + signal.kill(v,signal.SIGTERM) + end + printLog("Exiting...") + os.exit(0) + +end) + if backlogdb or logdb then local dbdriver = require "luasql.sqlite3" env = assert(dbdriver.sqlite3()) diff --git a/init.d/weathermon b/init.d/weathermon index bbf6f21..8553b6a 100755 --- a/init.d/weathermon +++ b/init.d/weathermon @@ -48,7 +48,5 @@ start_service() { } stop_service() { - killall weathermon - killall weathermon-iio /usr/bin/weather-backup } diff --git a/lib/wm_util.lua b/lib/wm_util.lua index 984f6ae..2c05bb0 100644 --- a/lib/wm_util.lua +++ b/lib/wm_util.lua @@ -1,6 +1,9 @@ #!/usr/bin/lua local socket = require "socket" +local lfs = require "lfs" +local uci = require "uci" +local posix = require "posix" function startswith(String,Start) if String then @@ -95,7 +98,6 @@ function split(s, delimiter) end function list_dir(name) - local lfs = require "lfs" local result = {} for name in lfs.dir(name) do if not startswith(name,".") then @@ -107,8 +109,6 @@ end function get_devid(config) - local uci = require "uci" - local web_devid = uci.get(config,"web","devid") if web_devid then @@ -126,4 +126,26 @@ function get_devid(config) local web_devid = io.read("*line") return web_devid:gsub(":",""):upper() -end \ No newline at end of file +end + +function get_children() + + local pid = posix.getpid() + local pidlist = list_dir('/proc') + local pids = {} + + for k,v in pairs(pidlist) do + + pcall( function () + local stats = get_file_content('/proc/'..v..'/stat') + local ppid = tonumber(split(stats,' ')[4]) + if pid == ppid then + pids[#pids+1] = tonumber(v) + end + end) + + end + + return pids + +end diff --git a/openwrt-web/meteo/archive.js b/openwrt-web/meteo/archive.js index 20aa7aa..a0850e4 100644 --- a/openwrt-web/meteo/archive.js +++ b/openwrt-web/meteo/archive.js @@ -146,7 +146,7 @@ function drawGraph(graphData) { yAxes: [{ scaleLabel: { display: true, - labelString: properties["names"][sensor+"."+param], + labelString: properties["names"][devid+"."+sensor+"."+param] + ", " + properties["units"][devid+"."+sensor+"."+param], fontColor: properties["fonts"]["axes"]["color"], fontSize: properties["fonts"]["axes"]["size"], fontStyle: properties["fonts"]["axes"]["style"], diff --git a/web/config_local.php~ b/web/config_local.php~ deleted file mode 100644 index 1ca0c18..0000000 --- a/web/config_local.php~ +++ /dev/null @@ -1,13 +0,0 @@ - -- 2.34.1