Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openresty
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tangku7
openresty
Commits
9ed7a0f8
Commit
9ed7a0f8
authored
Sep 19, 2018
by
周尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimized code structure
parent
264197f6
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
458 additions
and
223 deletions
+458
-223
nginx/conf/nginx.conf
nginx/conf/nginx.conf
+41
-26
nginx/conf/nginx.conf.142
nginx/conf/nginx.conf.142
+235
-0
nginx/lua/luabiz/async.lua
nginx/lua/luabiz/async.lua
+2
-3
nginx/lua/luabiz/check.lua
nginx/lua/luabiz/check.lua
+3
-3
nginx/lua/luabiz/log.lua
nginx/lua/luabiz/log.lua
+2
-1
nginx/lua/luabiz/node_asb.lua
nginx/lua/luabiz/node_asb.lua
+2
-3
nginx/lua/luabiz/node_asbdetail.lua
nginx/lua/luabiz/node_asbdetail.lua
+2
-3
nginx/lua/luabiz/node_card.lua
nginx/lua/luabiz/node_card.lua
+2
-8
nginx/lua/luabiz/node_chgrule.lua
nginx/lua/luabiz/node_chgrule.lua
+2
-3
nginx/lua/luabiz/node_cs.lua
nginx/lua/luabiz/node_cs.lua
+1
-2
nginx/lua/luabiz/node_csdetail.lua
nginx/lua/luabiz/node_csdetail.lua
+2
-3
nginx/lua/luabiz/node_ms.lua
nginx/lua/luabiz/node_ms.lua
+2
-3
nginx/lua/luabiz/node_payment.lua
nginx/lua/luabiz/node_payment.lua
+2
-3
nginx/lua/luabiz/node_psb.lua
nginx/lua/luabiz/node_psb.lua
+3
-4
nginx/lua/luabiz/node_psbdetail.lua
nginx/lua/luabiz/node_psbdetail.lua
+3
-4
nginx/lua/luabiz/node_rchg.lua
nginx/lua/luabiz/node_rchg.lua
+2
-3
nginx/lua/luabiz/node_rchgdetail.lua
nginx/lua/luabiz/node_rchgdetail.lua
+2
-3
nginx/lua/luabiz/node_saledetail.lua
nginx/lua/luabiz/node_saledetail.lua
+2
-3
nginx/lua/luabiz/node_saleorder.lua
nginx/lua/luabiz/node_saleorder.lua
+1
-2
nginx/lua/luabiz/node_shift.lua
nginx/lua/luabiz/node_shift.lua
+2
-3
nginx/lua/luabiz/node_sku.lua
nginx/lua/luabiz/node_sku.lua
+2
-3
nginx/lua/luabiz/node_sms.lua
nginx/lua/luabiz/node_sms.lua
+2
-3
nginx/lua/luabiz/node_smsvip.lua
nginx/lua/luabiz/node_smsvip.lua
+2
-3
nginx/lua/luabiz/node_ticket.lua
nginx/lua/luabiz/node_ticket.lua
+7
-11
nginx/lua/luabiz/node_vipacct.lua
nginx/lua/luabiz/node_vipacct.lua
+4
-5
nginx/lua/luabiz/settle.lua
nginx/lua/luabiz/settle.lua
+1
-24
nginx/lua/luabiz/sync.lua
nginx/lua/luabiz/sync.lua
+2
-2
nginx/lua/luabiz/tk_sdt.lua
nginx/lua/luabiz/tk_sdt.lua
+3
-5
nginx/lua/luabiz/tk_sync.lua
nginx/lua/luabiz/tk_sync.lua
+2
-6
nginx/lua/luabiz/zx_base.lua
nginx/lua/luabiz/zx_base.lua
+1
-1
nginx/lua/luainit/db_conf.lua
nginx/lua/luainit/db_conf.lua
+63
-0
nginx/lua/luainit/init.lua
nginx/lua/luainit/init.lua
+38
-77
nginx/lua/luainit/mods.lua
nginx/lua/luainit/mods.lua
+18
-0
No files found.
nginx/conf/nginx.conf
View file @
9ed7a0f8
...
...
@@ -2,14 +2,14 @@
worker_processes
auto
;
#error_log logs/error.log;
error_log
logs/error
.log
notice
;
#
error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events
{
worker_connections
10
000
;
worker_connections
10
24
;
}
# worker_rlimit_nofile 30000;
...
...
@@ -33,8 +33,9 @@ http {
lua_code_cache
on
;
lua_package_path
"/Users/zhoush/openresty/nginx/lua/
luabiz/
?.lua
;
;
"
;
lua_package_path
"/Users/zhoush/openresty/nginx/lua/?.lua
;
;
"
;
init_by_lua_file
"lua/luainit/init.lua"
;
init_worker_by_lua_file
"lua/luabiz/settle.lua"
;
...
...
@@ -61,50 +62,64 @@ http {
#charset koi8-r;
# access_log logs/host.access.log main;
location
/
{
root
/Users/zhoush/Documents/Private/Notes
;
index
README.html
;
}
#access_log logs/host.access.log main;
# 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;
# root /Users/zhoush/Documents/Private/Notes;
# index README.html;
# }
location
/
{
root
/Users/zhoush/Documents/Private/Notes/
;
index
README.html
;
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
/get_addr
{
content_by_lua_block
{
local
zx_base
=
loadmod("
zx_base")
local
zx_base
=
_G.zx_base
or
loadmod("luabiz.
zx_base")
local
host
=
zx_base:_get_addr("www.baidu.com")
ngx.say(host)
}
}
location
/pos
{
content_by_lua_file
"lua/luabiz/pos.lua"
;
}
location
/settle
{
content_by_lua_block
{
local
settle
=
loadmod("settle")
--
local
settle
=
loadmod("settle")
settle:run()
}
}
location
/table_sync
{
content_by_lua_block
{
local
tk_sync
=
loadmod("
tk_sync")
--
local
tk_sync
=
loadmod("luabiz.
tk_sync")
tk_sync:sync()
}
}
location
/log
{
}
location
/echo
{
content_by_lua_block
{
...
...
@@ -114,7 +129,7 @@ http {
}
location
/check
{
content_by_lua_file
"lua/check.lua"
;
content_by_lua_file
"lua/
luabiz/
check.lua"
;
}
...
...
nginx/conf/nginx.conf.142
0 → 100644
View file @
9ed7a0f8
user root;
# user nobody;
worker_processes auto;
error_log logs/error.log;
error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
# worker_rlimit_nofile 30000;
http {
include mime.types;
# include blockip.conf;
default_type application/octet-stream;
#log_format main "'$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#valid_refers none blocked icm-test.suixingpay.com *.suixingpay.com;
lua_package_path "/root/www/openresty/nginx/lua/luabiz/?.lua;;";
init_by_lua_file "lua/luainit/init.lua";
init_worker_by_lua_file "lua/luabiz/settle.lua";
#gzip on;
server {
# resolver 100.100.2.138 100.100.2.136;
listen 8080 default;
# server_name localhost;
server_name xingdata.com;
set $flag 0;
if ($host != "icm-test.suixingpay.com" ) {
set $flag "${flag}1";
}
if ($host != localhost) {
set $flag "${flag}1";
}
if ($remote_addr != "192.168.254.182") {
set $flag "${flag}1";
}
#if ($flag = "011") {
# return 403;
#}
allow 192.168.254.182;
allow 127.0.0.1;
allow 106.37.197.50;
allow 124.64.166.185;
allow 221.216.75.237;
deny all;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
set $server_dir /root/www/openresty;
# set $lua_dir lua/;
set $biz_dir lua/luabiz;
set $logs_path $server_dir/nginx/logs;
set $conf_path $server_dir/nginx/conf;
lua_need_request_body on;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root /Users/zhoush/Documents/Private/Notes;
# index README.html;
# }
location / {
root html;
index index.html index.htm;
lua_code_cache on;
}
location /log {
content_by_lua_block {
local logger = require "resty.logger.socket"
if not logger.initted() then
local ok, err = logger.init{
-- host = '121.196.219.142',
host = "0.0.0.0",
port = 1234,
flush_limit = 1, --日志长度大于flush_limit的时候会将msg信息推送一次
drop_limit = 99999,
}
if not ok then
ngx.log(ngx.ERR, "failed to initialize the logger: ",err)
return
end
end
local msg = string.format("hello","nginx")
local bytes, err = logger.log(msg)
if err then
ngx.log(ngx.ERR, "failed to log message: ", err)
return
end
}
}
location /settle {
content_by_lua_block {
local settle = loadmod("settle")
settle:run()
}
}
location /table_sync {
content_by_lua_block {
local tk_sync = loadmod("luabiz.tk_sync")
tk_sync:sync()
}
}
location /echo {
content_by_lua_block {
ngx.log(ngx.ERR, ngx.var.request_body)
ngx.say(ngx.var.request_body)
}
}
location /check {
content_by_lua_file "lua/check.lua";
}
location /async {
content_by_lua_file "lua/luabiz/async.lua";
}
location /sync {
content_by_lua_file "lua/luabiz/sync.lua";
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
# server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate /Users/zhoush/openresty/nginx/cert/server.pem;
# ssl_certificate_key /Users/zhoush/openresty/nginx/cert/server.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
# }
}
nginx/lua/luabiz/async.lua
View file @
9ed7a0f8
local
_ASYNC
=
{}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
json
=
loadmod
(
'cjson'
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
-- local function async_sql_ins()
-- local pay_type
...
...
nginx/lua/luabiz/check.lua
View file @
9ed7a0f8
local
resty_md5
=
loadmod
"resty.md5"
local
resty_md5
=
_G
.
loadmod
"resty.md5"
function
is_table_empty
(
t
)
...
...
@@ -115,7 +115,7 @@ local function check_mesg(data)
return
ret
end
local
json
=
loadmod
"cjson"
local
json
=
_G
.
loadmod
"cjson"
local
data
=
json
.
decode
(
ngx
.
var
.
request_body
)
local
s
=
""
...
...
@@ -146,7 +146,7 @@ if not ok then
end
local
digest
=
md5
:
final
()
local
str
=
loadmod
"resty.string"
local
str
=
_G
.
loadmod
"resty.string"
local
sign
=
string.upper
(
str
.
to_hex
(
digest
))
if
sign
~=
data
[
'mesgSign'
]
then
...
...
nginx/lua/luabiz/log.lua
View file @
9ed7a0f8
...
...
@@ -9,8 +9,9 @@ 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',
host
=
'0.0.0.0'
,
port
=
123
4
,
port
=
51
4
,
flush_limit
=
2048
,
--日志长度大于flush_limit的时候会将msg信息推送一次
drop_limit
=
99999
,
}
...
...
nginx/lua/luabiz/node_asb.lua
View file @
9ed7a0f8
local
_ASB
=
{}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_asbdetail.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _ASBDETAIL = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_card.lua
View file @
9ed7a0f8
local
NODE_CARD
=
{}
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
log_lua
=
loadmod
(
"log"
)
local
M
=
string.format
(
"%-16s"
,
"<NODE_CARD>"
)
-- local json = loadmod('cjson')
-- local json = _G.loadmod('cjson')
-- local db_conf = "tk7_dbs.json"
local
db_biz
...
...
nginx/lua/luabiz/node_chgrule.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _CR = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_cs.lua
View file @
9ed7a0f8
...
...
@@ -3,8 +3,7 @@ local NODE_CS = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
db_conf
=
"tk7_dbs.json"
local
MODULE
=
"S"
...
...
nginx/lua/luabiz/node_csdetail.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _CSDETAIL = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_ms.lua
View file @
9ed7a0f8
local
_MS
=
{}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_payment.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _PAYMENT = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_psb.lua
View file @
9ed7a0f8
...
...
@@ -3,8 +3,7 @@ local _PSB = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
tasks
=
{}
...
...
@@ -95,8 +94,8 @@ local function dispatch()
end
function
_PSB
.
run
()
local
zx_base
=
loadmod
(
'zx_base'
)
local
json
=
loadmod
(
'cjson'
)
local
zx_base
=
_G
.
loadmod
(
"luabiz.zx_base"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
-- local dbs_st = zx_base:db_read(db_conf)
local
interval
=
3
-- the month interval
for
i
=
1
,
#
dbs_st
.
tk_biz
do
...
...
nginx/lua/luabiz/node_psbdetail.lua
View file @
9ed7a0f8
...
...
@@ -3,8 +3,7 @@ local _PSBDETAIL = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
tasks
=
{}
...
...
@@ -95,8 +94,8 @@ local function dispatch()
end
function
_PSBDETAIL
.
run
()
local
zx_base
=
loadmod
(
'zx_base'
)
local
json
=
loadmod
(
'cjson'
)
local
zx_base
=
_G
.
loadmod
(
"luabiz.zx_base"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
-- local dbs_st = zx_base:db_read(db_conf)
local
interval
=
3
-- the month interval
for
i
=
1
,
#
dbs_st
.
tk_biz
do
...
...
nginx/lua/luabiz/node_rchg.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _RCHG = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_rchgdetail.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _RCHGDETAIL = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_saledetail.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _SALEDETAIL = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_saleorder.lua
View file @
9ed7a0f8
...
...
@@ -3,8 +3,7 @@ local _SALEORDER = {}
local
MODULE
=
"NODE"
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_shift.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _SHIFT = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_sku.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _SKU = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_sms.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _SMS = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_smsvip.lua
View file @
9ed7a0f8
...
...
@@ -3,9 +3,8 @@ local _SMSVIP = {}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
nginx/lua/luabiz/node_ticket.lua
View file @
9ed7a0f8
local
NODE_TICKET
=
{}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
'zx_base'
)
local
logger
=
loadmod
(
"log"
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
db_conf
=
"tk7_dbs.json"
local
M
=
string.format
(
"%-16s"
,
"<NODE_TICKET>"
)
local
db_biz
local
function
BEGIN
(
tk_biz
)
log
ger
:
BEGIN
(
"node_ticket"
)
log
_lua
:
BEGIN
(
"node_ticket"
)
local
err
db_biz
,
err
=
mysql
:
new
()
if
not
db_biz
then
log
ger
:
log
(
logger
:
__FILE__
()
..
":"
..
logger
:
__LINE__
(),
"ERR: "
,
"failed to instantiate mysql: "
,
err
)
log
_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
,
"failed to instantiate mysql: "
,
err
)
return
false
end
...
...
@@ -31,7 +29,7 @@ local function BEGIN(tk_biz)
}
if
not
ok
then
log
ger
:
log
(
logger
:
__FILE__
()
..
":"
..
logger
:
__LINE__
(),
"ERR: "
,
err
,
": "
,
errcode
,
" "
,
sqlstate
)
log
_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
,
err
,
": "
,
errcode
,
" "
,
sqlstate
)
return
false
end
...
...
@@ -40,19 +38,17 @@ end
local
function
END
()
zx_base
:
close_db
(
db_biz
)
log
ger
:
END
(
"node_ticket"
)
log
_lua
:
END
(
"node_ticket"
)
end
local
function
ticket_sql
()
logger
:
BEGIN
(
"node_ticket"
)
-- UPDATE tickets' status
local
sql_update
=
string.format
(
[[UPDATE node_ticket SET ticket_status = 8 WHERE %d > ticket_exp]]
,
os.date
(
"%Y%m%d"
))
log
ger
:
log
(
logger
:
__FILE__
()
..
":"
..
logger
:
__LINE__
(),
"NOTICE: "
,
sql_update
)
log
_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
sql_update
)
local
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
sql_update
)
if
not
res
then
log
ger
:
log
(
logger
:
__FILE__
()
..
":"
..
logger
:
__LINE__
(),
"ERR: "
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
log
_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
,
"bad result: "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
end
end
...
...
nginx/lua/luabiz/node_vipacct.lua
View file @
9ed7a0f8
...
...
@@ -4,9 +4,8 @@ local MODULE = "S"
-- 加载模块
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
tasks
=
{}
...
...
@@ -134,8 +133,8 @@ local function dispatch()
end
function
_VIPACCT
.
run
()
local
zx_base
=
loadmod
(
'zx_base'
)
local
json
=
loadmod
(
'cjson'
)
local
zx_base
=
_G
.
loadmod
(
"luabiz.zx_base"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
-- local dbs_st = zx_base:db_read(db_conf)
for
i
=
1
,
#
dbs_st
.
tk_biz
do
async
(
dbs_st
.
tk_biz
[
i
])
...
...
nginx/lua/luabiz/settle.lua
View file @
9ed7a0f8
local
SETTLE
=
{}
-- Settle modules
local
zx_base
=
loadmod
(
'zx_base'
)
-- local node_asb = loadmod('node_asb')
-- local node_asbdetail = loadmod('node_asbdetail')
local
node_card
=
loadmod
(
'node_card'
)
-- local node_chgrule = loadmod('node_chgrule')
-- local node_cs = loadmod('node_cs')
-- local node_csdetail = loadmod('node_csdetail')
-- local node_ms = loadmod('node_ms')
-- local node_payment = loadmod('node_payment')
-- local node_psb = loadmod('node_psb')
-- local node_psbdetail = loadmod('node_psbdetail')
-- local node_rchg = loadmod('node_rchg')
-- local node_rchgdetail = loadmod('node_rchgdetail')
-- local node_saledetail = loadmod('node_saledetail')
-- local node_saleorder = loadmod('node_saleorder')
-- local node_shift = loadmod('node_shift')
-- local node_sku = loadmod('node_sku')
-- local node_sms = loadmod('node_sms')
-- local node_smsvip = loadmod('node_smsvip')
local
node_ticket
=
loadmod
(
'node_ticket'
)
-- local node_vipacct = loadmod('node_vipacct')
local
tk_sdt
=
loadmod
(
'tk_sdt'
)
local
tk_sync
=
loadmod
(
'tk_sync'
)
-- Settle modules
-- local delay = 5 -- delaytime
...
...
nginx/lua/luabiz/sync.lua
View file @
9ed7a0f8
local
_SYNC
=
{}
local
mysql
=
loadmod
(
"resty.mysql"
)
local
json
=
loadmod
'cjson'
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
'cjson'
local
dbs
=
{
host
=
"127.0.0.1"
,
...
...
nginx/lua/luabiz/tk_sdt.lua
View file @
9ed7a0f8
...
...
@@ -2,10 +2,8 @@ local TK_SDT = {}
-- 加载模块
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
log_lua
=
loadmod
(
'log'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_biz
-- tk_biz handle
...
...
@@ -592,7 +590,7 @@ function TK_SDT.run(self, total_time)
local
tk_biz
=
dbs_st
.
tk_biz
[
i
]
local
tk_control
=
dbs_st
.
tk_control
if
BEGIN
(
tk_biz
,
tk_control
)
then
sdt_sql
(
tk_biz
,
tk_controltotal_time
)
sdt_sql
(
tk_biz
,
tk_control
,
total_time
)
end
END
()
end
...
...
nginx/lua/luabiz/tk_sync.lua
View file @
9ed7a0f8
local
TK_SYNC
=
{}
local
MODULE
=
"S"
-- Settle
-- 加载模块
local
mysql
=
loadmod
(
"resty.mysql"
)
local
zx_base
=
loadmod
(
"zx_base"
)
local
json
=
loadmod
(
'cjson'
)
local
db_conf
=
"tk7_dbs.json"
local
log_lua
=
loadmod
(
'log'
)
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_biz
...
...
nginx/lua/luabiz/zx_base.lua
View file @
9ed7a0f8
local
ZX_BASE
=
{
__index
=
_G
}
local
json
=
loadmod
(
'cjson'
)
local
json
=
_G
.
loadmod
(
'cjson'
)
function
ZX_BASE
.
db_read
(
self
,
dbpath
)
local
f
=
io.open
(
ngx
.
var
.
conf_path
..
"/"
..
dbpath
,
"r"
)
...
...
nginx/lua/luainit/db_conf.lua
0 → 100644
View file @
9ed7a0f8
local
function
get_hostname
()
local
f
=
io.popen
(
"/bin/hostname"
)
local
hostname
=
f
:
read
(
"*a"
)
or
""
f
:
close
()
hostname
=
string.gsub
(
hostname
,
"
\n
$"
,
""
)
return
hostname
end
local
hostname
=
get_hostname
()
-- 唐库 7 数据库配置
_G
.
dbs_st
=
{}
if
hostname
==
"zzd-mer01"
then
-- 生产
_G
.
dbs_st
=
{
tk_control
=
{
host
=
"rm-bp1u9rp1p216nb15f.mysql.rds.aliyuncs.com"
,
user
=
"tk_control_user"
,
password
=
"KJjsdn%zx3@jr#y57dhh20drYT!z"
,
port
=
3306
,
database
=
"tk_control"
,
timeout
=
30
},
tk_biz
=
{
{
host
=
"rm-bp1rob0a7ry7zmc0n.mysql.rds.aliyuncs.com"
,
user
=
"tk_node_user"
,
password
=
"KJjsnc%gs5@jr#y789sajkshdrYT!z"
,
port
=
3306
,
database
=
"tk_biz"
,
timeout
=
30
}
}
}
else
_G
.
dbs_st
=
{
tk_sku
=
{
host
=
"192.168.254.100"
,
port
=
3306
,
database
=
"tk_sku"
,
user
=
"root"
,
password
=
""
,
timeout
=
30
},
tk_control
=
{
host
=
"192.168.254.10"
,
user
=
"root"
,
password
=
"control_pwd"
,
port
=
3306
,
database
=
"tk_control"
,
timeout
=
30
},
tk_biz
=
{
{
host
=
"192.168.254.20"
,
user
=
"root"
,
password
=
"node_pwd"
,
port
=
3306
,
database
=
"tk_biz"
,
timeout
=
30
}
}
}
end
nginx/lua/luainit/init.lua
View file @
9ed7a0f8
--- 定义NULL常量
_G
.
NULL
=
ngx
.
null
local
pcall
=
pcall
local
io_open
=
io.open
local
ngx_re_gmatch
=
ngx
.
re
.
gmatch
local
ok
,
new_tab
=
pcall
(
require
,
"table.new"
)
if
not
ok
then
new_tab
=
function
(
narr
,
nrec
)
return
{}
end
end
_G
.
_dns_servers
=
new_tab
(
5
,
0
)
local
function
_read_file_data
(
path
)
local
f
,
err
=
io_open
(
path
,
'r'
)
if
not
f
or
err
then
return
nil
,
err
end
local
data
=
f
:
read
(
'*all'
)
f
:
close
()
return
data
,
nil
end
function
_G
.
_read_dns_servers_from_resolv_file
(
self
)
local
text
=
_read_file_data
(
'/etc/resolv.conf'
)
local
captures
,
it
,
err
it
,
err
=
ngx_re_gmatch
(
text
,
[[^nameserver\s+(\d+?\.\d+?\.\d+?\.\d+$)]]
,
"jomi"
)
for
captures
,
err
in
it
do
if
not
err
then
_G
.
_dns_servers
[
#
_G
.
_dns_servers
+
1
]
=
captures
[
1
]
end
end
end
--- 已加载的包
local
__loaded_mods
=
{}
--- 加载模块
--
-- @param string namespace 模块名
...
...
@@ -45,79 +81,4 @@ function _G.loadmod(namespace)
error
(
module
,
2
)
end
local
pcall
=
pcall
local
io_open
=
io.open
local
ngx_re_gmatch
=
ngx
.
re
.
gmatch
local
json
=
require
(
"cjson"
)
local
ok
,
new_tab
=
pcall
(
require
,
"table.new"
)
if
not
ok
then
new_tab
=
function
(
narr
,
nrec
)
return
{}
end
end
_G
.
_dns_servers
=
new_tab
(
5
,
0
)
local
function
_read_file_data
(
path
)
local
f
,
err
=
io_open
(
path
,
'r'
)
if
not
f
or
err
then
return
nil
,
err
end
local
data
=
f
:
read
(
'*all'
)
f
:
close
()
return
data
,
nil
end
function
_G
.
_read_dns_servers_from_resolv_file
(
self
)
local
text
=
_read_file_data
(
'/etc/resolv.conf'
)
local
captures
,
it
,
err
it
,
err
=
ngx_re_gmatch
(
text
,
[[^nameserver\s+(\d+?\.\d+?\.\d+?\.\d+$)]]
,
"jomi"
)
for
captures
,
err
in
it
do
if
not
err
then
_G
.
_dns_servers
[
#
_G
.
_dns_servers
+
1
]
=
captures
[
1
]
end
end
end
-- _G.fpath = string.format("/var/log/www/S_%s.log", os.date("%Y%m%d"))
-- _G.f = io.open(_G.fpath, "a+")
-- 唐库 7 数据库文件
_G
.
dbs_st
=
{
tk_sku
=
{
host
=
"192.168.254.100"
,
port
=
3306
,
database
=
"tk_sku"
,
user
=
"root"
,
password
=
""
,
timeout
=
30
},
tk_control
=
{
host
=
"rm-bp1u9rp1p216nb15f.mysql.rds.aliyuncs.com"
,
user
=
"tk_control_user"
,
password
=
"KJjsdn%zx3@jr#y57dhh20drYT!z"
,
-- host = "192.168.254.10",
-- user = "root",
-- password = "control_pwd",
port
=
3306
,
database
=
"tk_control"
,
timeout
=
30
},
tk_biz
=
{
{
host
=
"rm-bp1rob0a7ry7zmc0n.mysql.rds.aliyuncs.com"
,
user
=
"tk_node_user"
,
password
=
"KJjsnc%gs5@jr#y789sajkshdrYT!z"
,
-- host = "192.168.254.20",
-- user = "root",
-- password = "node_pwd",
port
=
3306
,
database
=
"tk_biz"
,
timeout
=
30
}
}
}
require
(
'luainit.mods'
)
nginx/lua/luainit/mods.lua
0 → 100644
View file @
9ed7a0f8
-- dbs config
_G
.
loadmod
(
'luainit.db_conf'
)
-- custom base module
_G
.
zx_base
=
_G
.
zx_base
or
require
(
'luabiz.zx_base'
)
-- settle module
_G
.
settle
=
_G
.
settle
or
require
(
'luabiz.settle'
)
-- settle detail
_G
.
tk_sync
=
_G
.
tk_sync
or
require
(
'luabiz.tk_sync'
)
_G
.
tk_sdt
=
_G
.
tk_sdt
or
require
(
'luabiz.tk_sdt'
)
_G
.
node_card
=
_G
.
node_card
or
require
(
'luabiz.node_card'
)
_G
.
node_ticket
=
_G
.
node_ticket
or
require
(
'luabiz.node_ticket'
)
-- logging module
_G
.
log_lua
=
_G
.
log_lua
or
require
(
'luabiz.log'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment