mirror of
https://github.com/gSpotx2f/luci-app-internet-detector.git
synced 2025-12-08 12:36:49 +03:00
Fixed syslog
This commit is contained in:
18
README.md
18
README.md
@@ -17,22 +17,22 @@ Internet-detector is an application for checking the availability of the Interne
|
|||||||
|
|
||||||
**OpenWrt >= 21.02:**
|
**OpenWrt >= 21.02:**
|
||||||
|
|
||||||
wget --no-check-certificate -O /tmp/internet-detector_0.4-2_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_0.4-2_all.ipk
|
wget --no-check-certificate -O /tmp/internet-detector_0.4-3_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_0.4-3_all.ipk
|
||||||
opkg install /tmp/internet-detector_0.4-2_all.ipk
|
opkg install /tmp/internet-detector_0.4-3_all.ipk
|
||||||
rm /tmp/internet-detector_0.4-2_all.ipk
|
rm /tmp/internet-detector_0.4-3_all.ipk
|
||||||
/etc/init.d/internet-detector start
|
/etc/init.d/internet-detector start
|
||||||
/etc/init.d/internet-detector enable
|
/etc/init.d/internet-detector enable
|
||||||
|
|
||||||
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.4-2_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_0.4-2_all.ipk
|
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.4-3_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_0.4-3_all.ipk
|
||||||
opkg install /tmp/luci-app-internet-detector_0.4-2_all.ipk
|
opkg install /tmp/luci-app-internet-detector_0.4-3_all.ipk
|
||||||
rm /tmp/luci-app-internet-detector_0.4-2_all.ipk
|
rm /tmp/luci-app-internet-detector_0.4-3_all.ipk
|
||||||
/etc/init.d/rpcd restart
|
/etc/init.d/rpcd restart
|
||||||
|
|
||||||
i18n-ru:
|
i18n-ru:
|
||||||
|
|
||||||
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.4-2_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_0.4-2_all.ipk
|
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.4-3_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_0.4-3_all.ipk
|
||||||
opkg install /tmp/luci-i18n-internet-detector-ru_0.4-2_all.ipk
|
opkg install /tmp/luci-i18n-internet-detector-ru_0.4-3_all.ipk
|
||||||
rm /tmp/luci-i18n-internet-detector-ru_0.4-2_all.ipk
|
rm /tmp/luci-i18n-internet-detector-ru_0.4-3_all.ipk
|
||||||
|
|
||||||
**OpenWrt 19.07:**
|
**OpenWrt 19.07:**
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=internet-detector
|
PKG_NAME:=internet-detector
|
||||||
PKG_VERSION:=0.4
|
PKG_VERSION:=0.4
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|||||||
@@ -117,6 +117,12 @@ local function readValueFromFile(filePath)
|
|||||||
return retValue
|
return retValue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function writeLogMessage(level, msg)
|
||||||
|
if Config.enableLogger then
|
||||||
|
nixio.syslog(level, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function loadModules()
|
local function loadModules()
|
||||||
package.path = string.format("%s;%s/?.lua", package.path, Config.modulesDir)
|
package.path = string.format("%s;%s/?.lua", package.path, Config.modulesDir)
|
||||||
Config.modules = {}
|
Config.modules = {}
|
||||||
@@ -128,7 +134,7 @@ local function loadModules()
|
|||||||
if mod_name and s.enabled == "1" then
|
if mod_name and s.enabled == "1" then
|
||||||
local m = prequire(mod_name)
|
local m = prequire(mod_name)
|
||||||
if m then
|
if m then
|
||||||
m.syslog = nixio.syslog
|
m.syslog = writeLogMessage
|
||||||
m.writeValue = writeValueToFile
|
m.writeValue = writeValueToFile
|
||||||
m.readValue = readValueFromFile
|
m.readValue = readValueFromFile
|
||||||
m:init(s)
|
m:init(s)
|
||||||
@@ -221,7 +227,7 @@ local function main()
|
|||||||
interval = Config.intervalUp
|
interval = Config.intervalUp
|
||||||
if lastStatus ~= nil and currentStatus ~= lastStatus then
|
if lastStatus ~= nil and currentStatus ~= lastStatus then
|
||||||
writeValueToFile(Config.statusFile, currentStatus)
|
writeValueToFile(Config.statusFile, currentStatus)
|
||||||
nixio.syslog("notice", "internet connected")
|
writeLogMessage("notice", "internet connected")
|
||||||
if Config.enableUpScript then
|
if Config.enableUpScript then
|
||||||
runExternalScript(Config.upScript)
|
runExternalScript(Config.upScript)
|
||||||
end
|
end
|
||||||
@@ -230,7 +236,7 @@ local function main()
|
|||||||
interval = Config.intervalDown
|
interval = Config.intervalDown
|
||||||
if lastStatus ~= nil and currentStatus ~= lastStatus then
|
if lastStatus ~= nil and currentStatus ~= lastStatus then
|
||||||
writeValueToFile(Config.statusFile, currentStatus)
|
writeValueToFile(Config.statusFile, currentStatus)
|
||||||
nixio.syslog("notice", "internet disconnected")
|
writeLogMessage("notice", "internet disconnected")
|
||||||
if Config.enableDownScript then
|
if Config.enableDownScript then
|
||||||
runExternalScript(Config.downScript)
|
runExternalScript(Config.downScript)
|
||||||
end
|
end
|
||||||
@@ -298,7 +304,9 @@ end
|
|||||||
|
|
||||||
local function stop()
|
local function stop()
|
||||||
local pidValue
|
local pidValue
|
||||||
nixio.openlog(Config.appName)
|
if Config.enableLogger then
|
||||||
|
nixio.openlog(Config.appName)
|
||||||
|
end
|
||||||
if nixio.fs.access(Config.pidFile, "r") then
|
if nixio.fs.access(Config.pidFile, "r") then
|
||||||
pidValue = readValueFromFile(Config.pidFile)
|
pidValue = readValueFromFile(Config.pidFile)
|
||||||
if pidValue then
|
if pidValue then
|
||||||
@@ -312,7 +320,7 @@ local function stop()
|
|||||||
if not success then
|
if not success then
|
||||||
io.stderr:write(string.format('No such process: "%s"\n', pidValue))
|
io.stderr:write(string.format('No such process: "%s"\n', pidValue))
|
||||||
end
|
end
|
||||||
nixio.syslog("info", string.format("[%s] stoped", pidValue))
|
writeLogMessage("info", string.format("[%s] stoped", pidValue))
|
||||||
removeProcessFiles()
|
removeProcessFiles()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -321,11 +329,13 @@ local function stop()
|
|||||||
string.format('PID file "%s" does not exist. %s not running?\n',
|
string.format('PID file "%s" does not exist. %s not running?\n',
|
||||||
Config.pidFile, Config.appName))
|
Config.pidFile, Config.appName))
|
||||||
end
|
end
|
||||||
nixio.closelog()
|
if Config.enableLogger then
|
||||||
|
nixio.closelog()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function preRun()
|
local function preRun()
|
||||||
-- Exit if internet detector mode != 2(Service)
|
-- Exit if internet-detector mode != 2(Service)
|
||||||
if Config.mode ~= 2 then
|
if Config.mode ~= 2 then
|
||||||
io.stderr:write(string.format('Start failed, mode != 2\n', Config.appName))
|
io.stderr:write(string.format('Start failed, mode != 2\n', Config.appName))
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
@@ -342,8 +352,10 @@ end
|
|||||||
local function run()
|
local function run()
|
||||||
local pidValue = nixio.getpid()
|
local pidValue = nixio.getpid()
|
||||||
writeValueToFile(Config.pidFile, pidValue)
|
writeValueToFile(Config.pidFile, pidValue)
|
||||||
nixio.openlog(Config.appName, "pid")
|
if Config.enableLogger then
|
||||||
nixio.syslog("info", "started")
|
nixio.openlog(Config.appName, "pid")
|
||||||
|
end
|
||||||
|
writeLogMessage("info", "started")
|
||||||
loadModules()
|
loadModules()
|
||||||
|
|
||||||
-- Loaded modules
|
-- Loaded modules
|
||||||
@@ -352,13 +364,15 @@ local function run()
|
|||||||
modules[#modules + 1] = string.format("%s", v.name)
|
modules[#modules + 1] = string.format("%s", v.name)
|
||||||
end
|
end
|
||||||
if #modules > 0 then
|
if #modules > 0 then
|
||||||
nixio.syslog(
|
writeLogMessage(
|
||||||
"info", string.format("Loaded modules: %s", table.concat(modules, ", "))
|
"info", string.format("Loaded modules: %s", table.concat(modules, ", "))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
main()
|
main()
|
||||||
nixio.closelog()
|
if Config.enableLogger then
|
||||||
|
nixio.closelog()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function noDaemon()
|
local function noDaemon()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_VERSION:=0.4-2
|
PKG_VERSION:=0.4-3
|
||||||
LUCI_TITLE:=LuCI support for internet-detector
|
LUCI_TITLE:=LuCI support for internet-detector
|
||||||
LUCI_DEPENDS:=+internet-detector
|
LUCI_DEPENDS:=+internet-detector
|
||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
|
|||||||
@@ -239,13 +239,13 @@ return view.extend({
|
|||||||
};
|
};
|
||||||
if(!this.ctx.initStatus) {
|
if(!this.ctx.initStatus) {
|
||||||
this.ctx.initButton.textContent = _('Enabled');
|
this.ctx.initButton.textContent = _('Enabled');
|
||||||
this.ctx.initButton.className = btnStyleEnabled;
|
this.ctx.initButton.className = btnStyleEnabled;
|
||||||
this.ctx.initStatus = true;
|
this.ctx.initStatus = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.ctx.initButton.textContent = _('Disabled');
|
this.ctx.initButton.textContent = _('Disabled');
|
||||||
this.ctx.initButton.className = btnStyleDisabled;
|
this.ctx.initButton.className = btnStyleDisabled;
|
||||||
this.ctx.initStatus = false;
|
this.ctx.initStatus = false;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user