Created
February 17, 2019 02:41
-
-
Save Snawoot/af5205849c1bfa649e3e1664c3ada401 to your computer and use it in GitHub Desktop.
Snippets for remote nginx reload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# located at /etc/nginx/conf.d/lualib.conf | |
lua_package_path "/etc/nginx/lualib/?.lua;;"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location /reload { | |
content_by_lua_block { | |
local reload = require "reload" | |
ngx.say(reload.reload()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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