You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/08/31 10:37:41 UTC

[GitHub] [apisix] tzssangglass commented on a diff in pull request #7826: fix: wait old nginx quit when compress in log roate

tzssangglass commented on code in PR #7826:
URL: https://github.com/apache/apisix/pull/7826#discussion_r959429748


##########
apisix/plugins/log-rotate.lua:
##########
@@ -219,24 +247,41 @@ end
 
 
 local function rotate_file(files, now_time, max_kept)
+    if isempty(files) then
+        return
+    end
+
+    local new_files = new_tab(2, 0)
+    -- rename the log files
     for _, file in ipairs(files) do
         local now_date = os_date("%Y-%m-%d_%H-%M-%S", now_time)
         local new_file = rename_file(default_logs[file], now_date)
         if not new_file then
             return
         end
 
-        local pid = process.get_master_pid()
-        core.log.warn("send USR1 signal to master process [", pid, "] for reopening log file")
-        local ok, err = signal.kill(pid, signal.signum("USR1"))
-        if not ok then
-            core.log.error("failed to send USR1 signal for reopening log file: ", err)
-        end
+        tab_insert(new_files, new_file)
+    end
 
-        if enable_compression then
+    -- send signal to reopen
+    local pid = process.get_master_pid()
+    core.log.warn("send USR1 signal to master process [", pid, "] for reopening log file")
+    local ok, err = signal.kill(pid, signal.signum("USR1"))
+    if not ok then
+        core.log.error("failed to send USR1 signal for reopening log file: ", err)
+    end
+
+    if enable_compression then
+        -- to avoid losing logs during compression
+        ngx_sleep(0.5)
+        wait_old_nginx_exit()

Review Comment:
   sleeping 0.5s then 10s seems strange, sleeping 10s directly?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org