From 2139d918c72b6b656a914f51add64b82adcc18d9 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 12 Feb 2024 17:32:52 -0800 Subject: Flush logs in on-the-pull It's not perfect (logs for requests that are rejected by the server are still buffered) but at least normal requests can be immediately be seen in the logs now. A better approach would be to use a logging function that flushes automatically. Also, wait for the queue thread to complete before exiting so things are left in a clean state. --- modules/gitmirror/files/on-the-pull | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/gitmirror/files/on-the-pull b/modules/gitmirror/files/on-the-pull index 7d3ede29..ec2f979b 100755 --- a/modules/gitmirror/files/on-the-pull +++ b/modules/gitmirror/files/on-the-pull @@ -189,6 +189,7 @@ class GitUpdater(Thread): print(str(e), file=sys.stderr) GitUpdaterQueue.task_done() + sys.stderr.flush() class TimeoutServer(http.server.HTTPServer): @@ -236,6 +237,8 @@ class PostHandler(http.server.BaseHTTPRequestHandler): self.send_response(500) self.end_headers() + sys.stderr.flush() + def Demote(pidfile, uid, gid): def result(): @@ -345,14 +348,17 @@ e.g. curl --header 'Content-Type: x-git/repo' --data 'my/repo/name' http://local parser.error("You can only specify a user if you're also deamonising (with a pid file).") print("Server started", file=sys.stderr) + sys.stderr.flush() srvr = TimeoutServer((options.addr, options.port), PostHandler) - GitUpdater(serverprefix, basefolder, options.repoprefix, options.branch, options.cmd).start() + updater = GitUpdater(serverprefix, basefolder, options.repoprefix, options.branch, options.cmd) + updater.start() try: srvr.serve_forever() except KeyboardInterrupt: - GitUpdaterQueue.put(None) srvr.socket.close() + GitUpdaterQueue.put(None) + updater.join() if __name__ == "__main__": -- cgit v1.2.1