Merge pull request #2165 from CodeFetch/pr_syslog

packages: introduce syslog function in gluon.util
This commit is contained in:
Martin Weinelt 2021-01-02 02:13:32 +01:00 committed by GitHub
commit 7709de6753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -1,5 +1,6 @@
local bit = require 'bit' local bit = require 'bit'
local posix_glob = require 'posix.glob' local posix_glob = require 'posix.glob'
local posix_syslog = require 'posix.syslog'
local hash = require 'hash' local hash = require 'hash'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local site = require 'gluon.site' local site = require 'gluon.site'
@ -179,4 +180,12 @@ function M.get_uptime()
return tonumber(uptime_file:match('^[^ ]+')) return tonumber(uptime_file:match('^[^ ]+'))
end end
function M.log(message, verbose)
if verbose then
io.stdout:write(message .. '\n')
end
posix_syslog.syslog(posix_syslog.LOG_INFO, message)
end
return M return M

View File

@ -3,14 +3,8 @@ local math_polygon = require('math-polygon')
local json = require ('jsonc') local json = require ('jsonc')
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local site = require ('gluon.site') local site = require ('gluon.site')
local logger = require('posix.syslog')
local M = {} local M = {}
function M.log(msg)
io.stdout:write(msg..'\n')
logger.openlog(msg, logger.LOG_PID)
end
function M.get_domains() function M.get_domains()
local list = {} local list = {}
for _, domain_path in ipairs(util.glob('/lib/gluon/domains/*.json')) do for _, domain_path in ipairs(util.glob('/lib/gluon/domains/*.json')) do
@ -68,7 +62,7 @@ end
function M.set_domain_config(domain) function M.set_domain_config(domain)
if uci:get('gluon', 'core', 'domain') ~= domain.domain_code then if uci:get('gluon', 'core', 'domain') ~= domain.domain_code then
os.execute(string.format("exec gluon-switch-domain --no-reboot '%s'", domain.domain_code)) os.execute(string.format("exec gluon-switch-domain --no-reboot '%s'", domain.domain_code))
M.log('Set domain "'..domain.domain.domain_names[domain.domain_code]..'"') util.log('Set domain "' .. domain.domain.domain_names[domain.domain_code] .. '"', true)
return true return true
end end
return false return false

View File

@ -1,6 +1,7 @@
#!/usr/bin/lua #!/usr/bin/lua
local bit = require('bit') local bit = require('bit')
local util = require ('gluon.util')
local unistd = require('posix.unistd') local unistd = require('posix.unistd')
local fcntl = require('posix.fcntl') local fcntl = require('posix.fcntl')
local hoodutil = require('hoodselector.util') local hoodutil = require('hoodselector.util')
@ -10,7 +11,7 @@ local lockfile = '/var/lock/hoodselector.lock'
local lockfd, err = fcntl.open(lockfile, bit.bor(fcntl.O_WRONLY, fcntl.O_CREAT), 384) -- mode 0600 local lockfd, err = fcntl.open(lockfile, bit.bor(fcntl.O_WRONLY, fcntl.O_CREAT), 384) -- mode 0600
if not lockfd then if not lockfd then
hoodutil.log(err, '\n') util.log(err, true)
os.exit(1) os.exit(1)
end end
@ -40,7 +41,7 @@ if geo.lat ~= nil and geo.lon ~= nil then
local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo) local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo)
if geo_base_domain ~= nil then if geo_base_domain ~= nil then
if hoodutil.set_domain_config(geo_base_domain) then if hoodutil.set_domain_config(geo_base_domain) then
hoodutil.log('Domain set by geolocation mode.\n') util.log('Domain set by geolocation mode.', true)
end end
return return
end end