1) Tengo un sitio estático y una varita para configurar "autopull" desde bitbucket.
2) Tengo webhook de bitbucket.
3) Tengo un script bash que hace "git pull"
¿Cómo puedo ejecutar este script cuando nginx captura la solicitud?
server { listen 80; server_name example.ru; root /path/to/root; index index.html; access_log /path/to/logs/nginx-access.log; error_log /path/to/logs/nginx-error.log; location /autopull { something to run autopull.sh; } location / { auth_basic "Hello, login please"; auth_basic_user_file /path/to/htpasswd; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } }Intenté el servicio lua_block y fastcgi, pero ambos fallaron. lua no ejecuta os.execute("/path/to/script") y no escribe el registro. fastcgi tiene más éxito, pero no tiene permisos, porque mi usuario de www-data no tiene ssh-key en mi repositorio de bitbuchet.
Problema resuelto.
No quería usar ningún script/proceso en otro puerto porque tengo varios sitios y necesito un puerto para cada uno.
Mi configuración final es:
server { listen 80; server_name example.ru; root /path/to/project; index index.html; access_log /path/to/logs/nginx-access.log; error_log /path/to/logs/nginx-error.log; location /autopull { content_by_lua_block { io.popen("bash /path/to/autopull.sh") } } location / { auth_basic "Hello, login please"; auth_basic_user_file /path/to/htpasswd; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; } }El problema estaba en el permiso del usuario www-data y su ssh-kay en el repositorio.
Basado en esto , crea un script py
#!/usr/bin/python from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer from subprocess import call PORT_NUMBER = 8080 autopull = '/path/to/autopull.sh' command = [autopull] #This class will handles any incoming request from #the browser class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() # Send the html message self.wfile.write("runing {}".format(autopull)) call(command) return try: #Create a web server and define the handler to manage the #incoming request server = HTTPServer(('', PORT_NUMBER), myHandler) print 'Started httpserver on port ' , PORT_NUMBER #Wait forever for incoming htto requests server.serve_forever() except KeyboardInterrupt: print '^C received, shutting down the web server' server.socket.close()Ejecútelo y en la configuración de nginx agregue
location /autopull { proxy_pass http://localhost:8080; }