Commit 264197f6 authored by 周尚's avatar 周尚

using syslog-ng instead

parent c5379d91
This diff is collapsed.
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
worker_processes auto; worker_processes auto;
#error_log logs/error.log; #error_log logs/error.log;
#error_log logs/error.log notice; error_log logs/error.log notice;
#error_log logs/error.log info; #error_log logs/error.log info;
#pid logs/nginx.pid; #pid logs/nginx.pid;
events { events {
worker_connections 1024; worker_connections 10000;
} }
# worker_rlimit_nofile 30000; # worker_rlimit_nofile 30000;
...@@ -61,42 +61,21 @@ http { ...@@ -61,42 +61,21 @@ http {
#charset koi8-r; #charset koi8-r;
#access_log logs/host.access.log main; # access_log logs/host.access.log main;
# location / {
# root /Users/zhoush/Documents/Private/Notes;
# index README.html;
# }
location / { location / {
root /Users/zhoush/Documents/Private/Notes/; root /Users/zhoush/Documents/Private/Notes;
index README.html; index README.html;
lua_code_cache on;
log_by_lua_block {
local logger = require("socket")
if not logger.initted() then
local ok, err = logger.init {
host = '127.0.0.1',
port = 1234,
flush_limit = 4096
}
if not ok then
ngx.log(ngx.ERR, "failed to initialize the logger: ", err)
return
end
end
-- construct the custom access log message in
-- the Lua variable "msg"
local bytes, err = logger.log(msg)
if err then
ngx.log(ngx.ERR, "failed to log message: ", err)
return
end
}
} }
# location / {
# root /Users/zhoush/Documents/Private/Notes/;
# index README.html;
# lua_code_cache on;
# content_by_lua_file lua/luabiz/log.lua;
# # log_by_lua_file lua/luabiz/log.lua;
# }
location /get_addr { location /get_addr {
content_by_lua_block { content_by_lua_block {
local zx_base = loadmod("zx_base") local zx_base = loadmod("zx_base")
...@@ -105,6 +84,10 @@ http { ...@@ -105,6 +84,10 @@ http {
} }
} }
location /pos {
content_by_lua_file "lua/luabiz/pos.lua";
}
location /settle { location /settle {
content_by_lua_block { content_by_lua_block {
local settle = loadmod("settle") local settle = loadmod("settle")
...@@ -119,6 +102,9 @@ http { ...@@ -119,6 +102,9 @@ http {
} }
} }
location /log {
}
location /echo { location /echo {
content_by_lua_block { content_by_lua_block {
......
local _M = {}
local logger = require "resty.logger.socket"
function _M.__FILE__ () return string.match(debug.getinfo(2,'S').source, ".+/([^/]*%.%w+)$") end
function _M.__LINE__ () return debug.getinfo(2,'l').currentline end
function _M.log(self, ...)
if not logger.initted() then
local ok, err = logger.init{
host = '0.0.0.0',
port = 1234,
flush_limit = 2048, --日志长度大于flush_limit的时候会将msg信息推送一次
drop_limit = 99999,
}
if not ok then
ngx.log(ngx.ERR, "failed to initialize the logger: ",err)
return
end
end
local str = ""
for i = 1, select("#", ...) do
local tmp = tostring(select(i, ...))
str = string.format("%s %s", str, tmp)
end
local bytes, err = logger.log(str .. "\n")
if err then
ngx.log(ngx.ERR, "failed to log message: ", err)
ngx.log(ngx.NOTICE, str)
return
end
end
function _M.BEGIN(self, modname)
local str = string.format("\n\n\nNOTICE: " .. "-----------------------> <%s> BEGIN\n", string.upper(modname))
logger.log(str)
logger.flush()
end
function _M.END(self, modname)
local str = string.format("NOTICE: " .. "-----------------------> <%s> END\n\n\n", string.upper(modname))
logger.log(str)
logger.flush()
end
return _M
...@@ -5,121 +5,79 @@ local NODE_CARD = {} ...@@ -5,121 +5,79 @@ local NODE_CARD = {}
local mysql = loadmod("resty.mysql") local mysql = loadmod("resty.mysql")
local zx_base = loadmod("zx_base") local zx_base = loadmod("zx_base")
local log_lua = loadmod("log")
local M = string.format("%-16s", "<NODE_CARD>") local M = string.format("%-16s", "<NODE_CARD>")
-- local json = loadmod('cjson') -- local json = loadmod('cjson')
-- local db_conf = "tk7_dbs.json" -- local db_conf = "tk7_dbs.json"
local tasks = {} local db_biz
local function card_sql(db_st, total_time) local function BEGIN(tk_biz)
ngx.log(ngx.NOTICE, "-----------------------> START") log_lua:BEGIN("node_card")
local db, err = mysql:new() local err
if not db then db_biz, err = mysql:new()
ngx.log(ngx.ERR, "failed to instantiate mysql: ", err) if not db_biz then
log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: ", "failed to instantiate mysql: ", err)
return false return false
end end
db:set_timeout(1000) -- 1 sec db_biz:set_timeout(1000) -- 1 sec
local ok, err, errcode, sqlstate = db:connect{ local ok, err, errcode, sqlstate = db_biz:connect{
host = zx_base:_get_addr(db_st['host']), host = zx_base:_get_addr(tk_biz['host']),
port = db_st['port'], port = tk_biz['port'],
database = db_st['database'], database = tk_biz['database'],
user = db_st['user'], user = tk_biz['user'],
password = db_st['password'], password = tk_biz['password'],
timeout = db_st['timeout'], timeout = tk_biz['timeout'],
charset = 'utf8' charset = 'utf8'
} }
if not ok then if not ok then
ngx.log(ngx.ERR, err, ": ", errcode, " ", sqlstate) log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: ", err, ": ", errcode, " ", sqlstate)
return return false
end end
return true
end
local function END()
zx_base:close_db(db_biz)
log_lua:END("node_card")
end
local function card_sql()
-- DELETE invalid rows -- DELETE invalid rows
-- local sql_delete = [[DELETE FROM node_card WHERE (card_status != 0 AND card_status !=1) or now() > card_exp]] -- local sql_delete = [[DELETE FROM node_card WHERE (card_status != 0 AND card_status !=1) or now() > card_exp]]
local sql_update = string.format([[UPDATE node_card SET card_status = 8 WHERE %d > card_exp]], os.date("%Y%m%d")) local sql_update = string.format([[UPDATE node_card SET card_status = 8 WHERE %d > card_exp]], os.date("%Y%m%d"))
local res, err, errcode, sqlstate = db:query(sql_update) local res, err, errcode, sqlstate = db_biz:query(sql_update)
ngx.log(ngx.NOTICE, sql_update) log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql_update)
if not res then if not res then
ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".") log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: ", "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
return return
end end
-- SET yesterday's balance -- SET yesterday's balance
local sql_update = [[UPDATE node_card SET card_lbal_amt = card_cbal_amt, card_lbal_count = card_cbal_count]] sql_update = [[UPDATE node_card SET card_lbal_amt = card_cbal_amt, card_lbal_count = card_cbal_count]]
local res, err, errcode, sqlstate = db:query(sql_update) local res, err, errcode, sqlstate = db_biz:query(sql_update)
ngx.log(ngx.NOTICE, sql_update) log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql_update)
if not res then if not res then
ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".") log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: ", "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
return return
end end
-- -- INSERT INTO history table
-- local sql_insert = string.format([[INSERT INTO node_card_his SELECT * FROM node_card ]]..
-- -- [[WHERE DATE(`create_time`) < DATE('%s')]],
-- -- [[WHERE EXTRACT(YEAR_MONTH FROM `create_time`) = EXTRACT(YEAR_MONTH FROM DATE_SUB('%s', INTERVAL 3 MONTH))]],
-- os.date("%Y%m%d%H%M%S", total_time))
-- ngx.log(ngx.NOTICE, sql_insert)
-- local res, err, errcode, sqlstate = db:query(sql_insert)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
-- -- DELETE current tables record
-- local sql_delete = string.format([[DELETE FROM node_card WHERE DATE(`create_time`) < DATE('%s')]],
-- os.date("%Y%m%d%H%M%S", total_time - 24 * 60 * 60 ))
-- ngx.log(ngx.NOTICE, sql_delete)
-- local res, err, errcode, sqlstate = db:query(sql_delete)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
ngx.log(ngx.NOTICE, "-----------------------> END")
zx_base:close_db(db)
end end
function NODE_CARD.run(self)
local function async(i, total_time)
local co = coroutine.wrap(
function()
card_sql(i, total_time)
end
)
table.insert(tasks, co)
end
local function dispatch()
local i = 1
while true do
if tasks[i] == nil then
if tasks[1] == nil then
break
end
i = 1
end
local res = tasks[i]()
if not res then
table.remove(tasks, i)
else
i = i + 1
end
end
end
function NODE_CARD.run(self, total_time)
-- -- local dbs_st = zx_base:db_read(db_conf)
for i = 1, #dbs_st.tk_biz do for i = 1, #dbs_st.tk_biz do
-- async(dbs_st.tk_biz[i]) if BEGIN(dbs_st.tk_biz[i]) then
card_sql(dbs_st.tk_biz[i], total_time) card_sql()
end
END()
end end
dispatch()
end end
return NODE_CARD return NODE_CARD
...@@ -2,112 +2,68 @@ local NODE_TICKET = {} ...@@ -2,112 +2,68 @@ local NODE_TICKET = {}
local mysql = loadmod("resty.mysql") local mysql = loadmod("resty.mysql")
local zx_base = loadmod('zx_base') local zx_base = loadmod('zx_base')
local logger = loadmod("log")
local db_conf = "tk7_dbs.json" local db_conf = "tk7_dbs.json"
local M = string.format("%-16s", "<NODE_TICKET>") local M = string.format("%-16s", "<NODE_TICKET>")
local tasks = {}
local db_biz
local function BEGIN(tk_biz)
logger:BEGIN("node_ticket")
local err
local function ticket_sql(db_st, total_time) db_biz, err = mysql:new()
ngx.log(ngx.NOTICE, "-----------------------> START") if not db_biz then
logger:log(logger:__FILE__() .. ":" .. logger:__LINE__(), "ERR: ", "failed to instantiate mysql: ", err)
local db, err = mysql:new()
if not db then
ngx.log(ngx.ERR, "failed to instantiate mysql: ", err)
return false return false
end end
db:set_timeout(1000) -- 1 sec db_biz:set_timeout(1000) -- 1 sec
local ok, err, errcode, sqlstate = db:connect{ local ok, err, errcode, sqlstate = db_biz:connect{
host = zx_base:_get_addr(db_st['host']), host = zx_base:_get_addr(tk_biz['host']),
port = db_st['port'], port = tk_biz['port'],
database = db_st['database'], database = tk_biz['database'],
user = db_st['user'], user = tk_biz['user'],
password = db_st['password'], password = tk_biz['password'],
timeout = db_st['timeout'], timeout = tk_biz['timeout'],
charset = 'utf8' charset = 'utf8'
} }
if not ok then if not ok then
ngx.log(ngx.ERR, err, ": ", errcode, " ", sqlstate) logger:log(logger:__FILE__() .. ":" .. logger:__LINE__(), "ERR: ", err, ": ", errcode, " ", sqlstate)
return return false
end
-- DELETE invalid rows
-- local sql_delete = [[DELETE FROM node_ticket WHERE (ticket_status != 0 AND ticket_status !=1) or now() > ticket_exp]]
local sql_update = string.format([[UPDATE node_ticket SET ticket_status = 8 WHERE %d > ticket_exp]], os.date("%Y%m%d"))
ngx.log(ngx.NOTICE, sql_update)
local res, err, errcode, sqlstate = db:query(sql_update)
if not res then
ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
return
end end
-- -- INSERT INTO history table return true
-- local sql_insert = string.format([[INSERT INTO node_ticket_his SELECT * FROM node_ticket WHERE ]]..
-- [[DATE(`create_time`) < DATE('%s')]],
-- os.date("%Y%m%d%H%M%S", total_time - 24 * 60 * 60))
-- ngx.log(ngx.NOTICE, sql_insert)
-- local res, err, errcode, sqlstate = db:query(sql_insert)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
-- -- DELETE current tables record
-- local sql_delete = string.format([[DELETE FROM node_ticket WHERE DATE(`create_time`) < DATE('%s')]],
-- os.date("%Y%m%d%H%M%S", total_time - 24 * 60 * 60))
-- ngx.log(ngx.NOTICE, sql_delete)
-- local res, err, errcode, sqlstate = db:query(sql_delete)
-- if not res then
-- ngx.log(ngx.ERR, "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
-- return
-- end
-- ngx.log(ngx.NOTICE, "-----------------------> END")
zx_base:close_db(db)
end end
local function END()
zx_base:close_db(db_biz)
local function async(i, total_time) logger:END("node_ticket")
local co = coroutine.wrap(
function()
ticket_sql(i, total_time)
end
)
table.insert(tasks, co)
end end
local function dispatch() local function ticket_sql()
local i = 1 logger:BEGIN("node_ticket")
while true do
if tasks[i] == nil then
if tasks[1] == nil then
break
end
i = 1
end
local res = tasks[i]() -- UPDATE tickets' status
if not res then local sql_update = string.format([[UPDATE node_ticket SET ticket_status = 8 WHERE %d > ticket_exp]], os.date("%Y%m%d"))
table.remove(tasks, i) logger:log(logger:__FILE__() .. ":" .. logger:__LINE__(), "NOTICE: ", sql_update)
else local res, err, errcode, sqlstate = db_biz:query(sql_update)
i = i + 1 if not res then
end logger:log(logger:__FILE__() .. ":" .. logger:__LINE__(), "ERR: ", "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
return
end end
end end
function NODE_TICKET.run(self, total_time) function NODE_TICKET.run(self)
-- local json = loadmod('cjson')
-- -- local dbs_st = zx_base:db_read(db_conf)
for i = 1, #dbs_st.tk_biz do for i = 1, #dbs_st.tk_biz do
-- async(dbs_st.tk_biz[i]) if BEGIN(dbs_st.tk_biz[i]) then
ticket_sql(dbs_st.tk_biz[i], total_time) ticket_sql()
end
END()
end end
dispatch()
end end
return NODE_TICKET return NODE_TICKET
...@@ -119,8 +119,8 @@ function SETTLE.run() ...@@ -119,8 +119,8 @@ function SETTLE.run()
-- node_vipacct: run() -- node_vipacct: run()
tk_sync: run() tk_sync: run()
node_card: run(t) node_card: run()
node_ticket: run(t) node_ticket: run()
tk_sdt: run(t) tk_sdt: run(t)
end end
......
This diff is collapsed.
...@@ -7,33 +7,31 @@ local mysql = loadmod("resty.mysql") ...@@ -7,33 +7,31 @@ local mysql = loadmod("resty.mysql")
local zx_base = loadmod("zx_base") local zx_base = loadmod("zx_base")
local json = loadmod('cjson') local json = loadmod('cjson')
local db_conf = "tk7_dbs.json" local db_conf = "tk7_dbs.json"
local log_lua = loadmod('log')
-- 协程组 local db_biz
local tasks = {} local db_control
-- 初始化数据库连接
local function EOF()
end
-- 表信息
-- @param table tk_biz 节点机数据库对象 -- @param table tk_biz 节点机数据库对象
-- table tk_control 总控机数据库对象 -- table tk_control 总控机数据库对象
-- table tk_table 数据同步表名 -- @return true/false
-- @return nil local function BEGIN(tk_biz, tk_control)
local function sync_sql(tk_biz, tk_control, tk_table) log_lua:BEGIN("tk_sync")
ngx.log(ngx.NOTICE, "-----------------------> START") local err
-- 新建mysql连接 -- 新建mysql连接
local db, err = mysql:new() db_biz, err = mysql:new()
if not db then if not db_biz then
ngx.log(ngx.ERR, "failed to instantiate mysql: ", err) log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: " .. "failed to instantiate mysql: ", err)
return false return false
end end
db:set_timeout(1000) -- 1 sec
-- 连接节点机MySQL -- 超时设置
local ok, err, errcode, sqlstate = db:connect{ db_biz:set_timeout(1000)
-- 连接tk_biz
local ok, err, errcode, sqlstate = db_biz:connect{
host = zx_base:_get_addr(tk_biz['host']), host = zx_base:_get_addr(tk_biz['host']),
port = tk_biz['port'], port = tk_biz['port'],
database = tk_biz['database'], database = tk_biz['database'],
...@@ -43,39 +41,22 @@ local function sync_sql(tk_biz, tk_control, tk_table) ...@@ -43,39 +41,22 @@ local function sync_sql(tk_biz, tk_control, tk_table)
charset = 'utf8' charset = 'utf8'
} }
if not ok then if not ok then
ngx.log(ngx.ERR, json.encode(tk_biz), ":", err, errcode, sqlstate) log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: " .. json.encode(tk_biz), ":", err, errcode, sqlstate)
return return false
end end
-- 新建mysql连接
-- 查询节点机 db_control, err = mysql:new()
local sql = string.format([[SELECT * FROM %s where update_time > %s]], if not db_control then
tk_table, log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: " .. "failed to instantiate mysql: ", err)
os.date("%Y%m%d000000", os.time()-24*60*60) return false
)
ngx.log(ngx.NOTICE, sql)
local syncs
syncs, err, errcode, sqlstate = db:query(sql)
if not syncs then
ngx.log(ngx.ERR, "failed to query:", json.encode(tk_biz), ":",
err, ":", errcode, ":", sqlstate, ".")
return
end
if #syncs == 0 then
return "00", "SUCCESS"
end end
-- 超时设置
db_control:set_timeout(1000)
-- 重置MySQL连接 -- 连接tk_control
zx_base:close_db(db) local ok, err, errcode, sqlstate = db_control:connect{
db, err = mysql:new()
if not db then
ngx.log(ngx.ERR, "failed to instantiate mysql: ", err)
return
end
db:set_timeout(1000)
-- 连接总控机MySQL
ok, err, errcode, sqlstate = db:connect{
host = zx_base:_get_addr(tk_control['host']), host = zx_base:_get_addr(tk_control['host']),
port = tk_control['port'], port = tk_control['port'],
database = tk_control['database'], database = tk_control['database'],
...@@ -85,63 +66,58 @@ local function sync_sql(tk_biz, tk_control, tk_table) ...@@ -85,63 +66,58 @@ local function sync_sql(tk_biz, tk_control, tk_table)
charset = 'utf8' charset = 'utf8'
} }
if not ok then if not ok then
ngx.log(ngx.ERR, json.encode(tk_control), ":", err, errcode, sqlstate) log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: " .. json.encode(tk_control), ":", err, errcode, sqlstate)
return return false
end
-- 插入总控机
for i = 1, #syncs do
local sync = syncs[i]
local sql_result = zx_base:sql_concate("duplicate", tk_table, sync)
ngx.log(ngx.NOTICE, sql_result)
ok, err, errcode, sqlstate = db:query(sql_result)
if not ok then
ngx.log(ngx.ERR, "failed to query:", json.encode(tk_control), ":",
err, ":", errcode, ":", sqlstate, ".")
end
end end
ngx.log(ngx.NOTICE, "-----------------------> END") return true;
end end
-- 清理连接句柄
-- @param nil
-- @return nil
local function END()
zx_base:close_db(db_biz)
zx_base:close_db(db_control)
log_lua:END("tk_sync")
end
-- 异步运行 -- 表信息
-- @param table tk_biz 节点机数据库对象 -- @param table tk_biz 节点机数据库对象
-- table tk_control 总控机数据库对象 -- table tk_control 总控机数据库对象
-- table tk_table 数据同步表名 -- table tk_table 数据同步表名
-- @return nil -- @return nil
local function async(tk_biz, tk_control, tk_table) local function sync_sql(tk_biz, tk_control, tk_table)
local co = coroutine.wrap(
function()
sync_sql(tk_biz, tk_control, tk_table)
end
)
table.insert(tasks, co)
end
-- 协程调度 -- 查询节点机
-- @param nil local sql = string.format([[SELECT * FROM %s where update_time > %s]],
-- @return nil tk_table,
local function dispatch() os.date("%Y%m%d000000", os.time()-24*60*60)
local i = 1 )
while true do log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: ", sql)
if tasks[i] == nil then local syncs, err, errcode, sqlstate = db_biz:query(sql)
if tasks[1] == nil then if not syncs then
break log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: ", "failed to query:", json.encode(tk_biz), ":",
end err, ":", errcode, ":", sqlstate, ".")
i = 1 return
end end
if #syncs == 0 then
return "00", "SUCCESS"
end
local res = tasks[i]() -- 插入总控机
if not res then for i = 1, #syncs do
table.remove(tasks, i) local sync = syncs[i]
else local sql_result = zx_base:sql_concate("duplicate", tk_table, sync)
i = i + 1 log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: ", sql_result)
local ok, err, errcode, sqlstate = db_control:query(sql_result)
if not ok then
log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "ERR: ", "failed to query:", json.encode(tk_control), ":",
err, ":", errcode, ":", sqlstate, ".")
end end
end end
end end
...@@ -149,12 +125,15 @@ end ...@@ -149,12 +125,15 @@ end
-- @param nil -- @param nil
-- @return nil -- @return nil
function TK_SYNC.run() function TK_SYNC.run()
-- local dbs_st = zx_base:db_read(db_conf)
for i = 1, #dbs_st.tk_biz do for i = 1, #dbs_st.tk_biz do
async(dbs_st.tk_biz[i], dbs_st.tk_control, "tk_shop") local tk_biz = dbs_st.tk_biz[i]
async(dbs_st.tk_biz[i], dbs_st.tk_control, "tk_casher") local tk_control = dbs_st.tk_control
if BEGIN(tk_biz, tk_control) then
sync_sql(tk_biz, tk_control, "tk_shop")
sync_sql(tk_biz, tk_control, "tk_casher")
end
END()
end end
dispatch()
end end
...@@ -191,7 +170,10 @@ local function tk_sync() ...@@ -191,7 +170,10 @@ local function tk_sync()
else else
-- async(dbs_st.tk_biz[i], dbs_st.tk_control, data.dbTable) -- async(dbs_st.tk_biz[i], dbs_st.tk_control, data.dbTable)
sync_sql(dbs_st.tk_biz[i], dbs_st.tk_control, data.dbTable) if BEGIN(dbs_st.tk_biz[i], dbs_st.tk_control) then
sync_sql(dbs_st.tk_biz[i], dbs_st.tk_control, data.dbTable)
end
END()
code = "00" code = "00"
mesg = "SUCCESS" mesg = "SUCCESS"
...@@ -212,9 +194,12 @@ end ...@@ -212,9 +194,12 @@ end
function TK_SYNC.sync() function TK_SYNC.sync()
local code, mesg = tk_sync() local code, mesg = tk_sync()
-- http eof
ngx.say(json.encode({mesgRetCode=code, mesgRetDesc=mesg})) ngx.say(json.encode({mesgRetCode=code, mesgRetDesc=mesg}))
ngx.eof() ngx.eof()
ngx.log(ngx.NOTICE, ngx.var.request_body)
-- log eof
log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: ", ngx.var.request_body)
end end
......
...@@ -2,24 +2,6 @@ local ZX_BASE = {__index=_G} ...@@ -2,24 +2,6 @@ local ZX_BASE = {__index=_G}
local json = loadmod ('cjson') local json = loadmod ('cjson')
function ZX_BASE.__FILE__ () return debug.getinfo(2,'S').source end
function ZX_BASE.__LINE__ () return debug.getinfo(2,'l').currentline end
function ZX_BASE.log(self, fname, ...)
local fpath = string.format("%s/%s_%s.log", ngx.var.logs_path, tostring(fname), os.date("%Y%m%d"))
local f = io.open(fpath, "a+")
local str = ""
for i=1, select("#", ...) do
local tmp= tostring(select(i, ...))
str = string.format("%s %s", str, tmp)
end
f:write(os.date("<%Y-%m-%d %H:%M:%S> "))
f:write(str)
f:write("\n")
f:close()
end
function ZX_BASE.db_read(self, dbpath) function ZX_BASE.db_read(self, dbpath)
local f = io.open(ngx.var.conf_path.."/"..dbpath, "r") local f = io.open(ngx.var.conf_path.."/"..dbpath, "r")
local tmp = f:read("a*") local tmp = f:read("a*")
......
...@@ -83,7 +83,6 @@ function _G._read_dns_servers_from_resolv_file(self) ...@@ -83,7 +83,6 @@ function _G._read_dns_servers_from_resolv_file(self)
end end
end end
-- _G.fpath = string.format("/var/log/www/S_%s.log", os.date("%Y%m%d")) -- _G.fpath = string.format("/var/log/www/S_%s.log", os.date("%Y%m%d"))
-- _G.f = io.open(_G.fpath, "a+") -- _G.f = io.open(_G.fpath, "a+")
...@@ -99,19 +98,25 @@ _G.dbs_st = { ...@@ -99,19 +98,25 @@ _G.dbs_st = {
}, },
tk_control = { tk_control = {
host = "rm-bp1u9rp1p216nb15f.mysql.rds.aliyuncs.com", host = "rm-bp1u9rp1p216nb15f.mysql.rds.aliyuncs.com",
port = 3306,
database = "tk_control",
user = "tk_control_user", user = "tk_control_user",
password = "KJjsdn%zx3@jr#y57dhh20drYT!z", password = "KJjsdn%zx3@jr#y57dhh20drYT!z",
-- host = "192.168.254.10",
-- user = "root",
-- password = "control_pwd",
port = 3306,
database = "tk_control",
timeout = 30 timeout = 30
}, },
tk_biz = { tk_biz = {
{ {
host = "rm-bp1rob0a7ry7zmc0n.mysql.rds.aliyuncs.com", host = "rm-bp1rob0a7ry7zmc0n.mysql.rds.aliyuncs.com",
port = 3306,
database = "tk_biz",
user = "tk_node_user", user = "tk_node_user",
password = "KJjsnc%gs5@jr#y789sajkshdrYT!z", password = "KJjsnc%gs5@jr#y789sajkshdrYT!z",
-- host = "192.168.254.20",
-- user = "root",
-- password = "node_pwd",
port = 3306,
database = "tk_biz",
timeout = 30 timeout = 30
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment