Skip to content

Instantly share code, notes, and snippets.

@Snawoot
Created February 17, 2019 02:41
Show Gist options
  • Save Snawoot/af5205849c1bfa649e3e1664c3ada401 to your computer and use it in GitHub Desktop.
Save Snawoot/af5205849c1bfa649e3e1664c3ada401 to your computer and use it in GitHub Desktop.
Snippets for remote nginx reload
# located at /etc/nginx/conf.d/lualib.conf
lua_package_path "/etc/nginx/lualib/?.lua;;";
-- located at /etc/nginx/lualib/reload.lua
local _M = {}
local ffi = require "ffi"
ffi.cdef[[
int32_t getppid();
int kill(int32_t pid, int signal);
]]
SIGHUP = 1
local function getppid()
return ffi.C.getppid()
end
local function kill(pid, sig)
return ffi.C.kill(pid, sig)
end
local function reload()
return kill(getppid(), SIGHUP)
end
_M.reload = reload
return _M
location /reload {
content_by_lua_block {
local reload = require "reload"
ngx.say(reload.reload())
}
#!/bin/sh
setcap cap_net_bind_service+ep `which nginx`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment