Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move events sock path to conf #10732

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ env {*name*};
thread_pool grpc-client-nginx-module threads=1;

lua {
lua_shared_dict apisix 1m;
{% if enabled_stream_plugins["prometheus"] then %}
lua_shared_dict prometheus-metrics {* meta.lua_shared_dict["prometheus-metrics"] *};
{% end %}
Expand Down Expand Up @@ -202,7 +203,7 @@ stream {
{% if (events.module or "") == "lua-resty-events" then %}
# the server block for lua-resty-events
server {
listen unix:{*apisix_lua_home*}/logs/stream_worker_events.sock;
listen unix:{*apisix_lua_home*}/tmp/stream_worker_events.sock;
access_log off;
content_by_lua_block {
require("resty.events.compat").run()
Expand Down Expand Up @@ -497,7 +498,7 @@ http {
{% if (events.module or "") == "lua-resty-events" then %}
# the server block for lua-resty-events
server {
listen unix:{*apisix_lua_home*}/logs/worker_events.sock;
listen unix:{*apisix_lua_home*}/tmp/worker_events.sock;
access_log off;
location / {
content_by_lua_block {
Expand Down
42 changes: 42 additions & 0 deletions apisix/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ local table = require("apisix.core.table")
local log = require("apisix.core.log")
local string = require("apisix.core.string")
local dns_client = require("apisix.core.dns.client")
local apisix_home = require("apisix.core.profile").apisix_home
local ngx_re = require("ngx.re")
local ipmatcher = require("resty.ipmatcher")
local ffi = require("ffi")
local base = require("resty.core.base")
local pl_path = require("pl.path")
local open = io.open
local sub_str = string.sub
local str_byte = string.byte
Expand All @@ -43,6 +45,8 @@ local ffi_string = ffi.string
local get_string_buf = base.get_string_buf
local exiting = ngx.worker.exiting
local ngx_sleep = ngx.sleep
local os_remove = os.remove
local apisix_shm = ngx.shared.apisix

local hostname
local dns_resolvers
Expand Down Expand Up @@ -272,6 +276,44 @@ function _M.gethostname()
end


-- Clean up and make sure the tmp folder exists, for code base internal use only
function _M.init_tmp_directory()
local initialized_flag = "tmp_directory_initialized"
-- skip initialize when reload
if apisix_shm:get(initialized_flag) then
return
end

local tmp_path = apisix_home .. "tmp/"

-- remove current tmp directory
if pl_path.exists(tmp_path) then
-- check if the folder is empty
for file in pl_path.dir(tmp_path) do
if file ~= "." and file ~= ".." then
local abs_path = tmp_path..file
local ok, err = os_remove(abs_path)
if not ok then
log.error("failed to cleanup files in tmp directory, error: ", err)
end
end
end

local ok, err = pl_path.rmdir(tmp_path)
if not ok then
log.error("failed to cleanup tmp directory, error: ", err)
end
end

-- create new tmp directory
local ok, err = pl_path.mkdir(tmp_path)
if not ok then
log.error("failed to create tmp directory, error: ", err)
end
apisix_shm:set(initialized_flag, true)
end


local function sleep(sec)
if sec <= max_sleep_interval then
return ngx_sleep(sec)
Expand Down
2 changes: 1 addition & 1 deletion apisix/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
local function init_resty_events()
_M.events_module = _M.EVENTS_MODULE_LUA_RESTY_EVENTS

local listening = "unix:" .. ngx.config.prefix() .. "logs/"
local listening = "unix:" .. ngx.config.prefix() .. "tmp/"
if ngx.config.subsystem == "http" then
listening = listening .. "worker_events.sock"
else
Expand Down
1 change: 1 addition & 0 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ local _M = {version = 0.4}


function _M.http_init(args)
core.utils.init_tmp_directory()
core.resolver.init_resolver(args)
core.id.init()
core.env.init()
Expand Down
5 changes: 3 additions & 2 deletions t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ _EOC_
thread_pool grpc-client-nginx-module threads=1;

lua {
lua_shared_dict apisix 1m;
lua_shared_dict prometheus-metrics 15m;
}
_EOC_
Expand Down Expand Up @@ -440,7 +441,7 @@ _EOC_
$extra_stream_config

server {
listen unix:$apisix_home/t/servroot/logs/stream_worker_events.sock;
listen unix:$apisix_home/t/servroot/tmp/stream_worker_events.sock;
access_log off;
content_by_lua_block {
require("resty.events.compat").run()
Expand Down Expand Up @@ -701,7 +702,7 @@ _EOC_

$http_config .= <<_EOC_;
server {
listen unix:$apisix_home/t/servroot/logs/worker_events.sock;
listen unix:$apisix_home/t/servroot/tmp/worker_events.sock;
access_log off;
location / {
content_by_lua_block {
Expand Down