Skip to content

Instantly share code, notes, and snippets.

@mozhu1024
Created July 9, 2018 14:40
Show Gist options
  • Save mozhu1024/4edbfa8b22638b8fa1da50c8d91efed7 to your computer and use it in GitHub Desktop.
Save mozhu1024/4edbfa8b22638b8fa1da50c8d91efed7 to your computer and use it in GitHub Desktop.
[Github Webhook with LuaJit]
local ffi = nil
local token = 'xxx'
ffi = require("ffi")
ffi.load("z")
ffi.cdef[[int system(const char * string);]]
if "POST" == ngx.var.request_method then
ngx.req.read_body()
local args, err = ngx.req.get_post_args()
if args ~= nil then
local _token = nil
for key, val in pairs(args) do
if key == "token" then
if val ~= nil then
_token = val
end
end
end
if _token == token then
ffi.C.system("cd /var/www/blog && git pull >> /var/log/updatelua.log")
ngx.say("ok")
ngx.exit(0)
end
end
end
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment