10

I have over 10.0G logs under /var/log and /var/log/nginx. How can I safely clean it?

7.8G /var/log/nginx/custom 2.0G /var/log/nginx 2.0G /var/log

0

1 Answer 1

7

To control application's lifecycle Unix provides a mechanism called Unix signals. USR1 is custom and usually handles the log rotation, other signal like HUP is standard and performs reload.

http://nginx.org/en/docs/control.html

TERM, INT   fast shutdown
QUIT    graceful shutdown
HUP changing configuration, keeping up with a changed time zone (only for FreeBSD and Linux), starting new worker processes with a new configuration, graceful shutdown of old worker processes
USR1    re-opening log files
USR2    upgrading an executable file
WINCH   graceful shutdown of worker processes

Before send a signal to PID rename the file. After you rename it log entries will still be going into the same file because inode hasn't been changed.

cd /var/log/nginx
mv access.log access.log.old
mv error.log error.log.old
kill -USR1 `cat /var/run/nginx.pid`
1
  • @angelokh Nginx error and access log should both rotate. Maybe you ask about not Nginx logs? It depends on the application, usually USR1 supported by vast majority Linux applications
    – Anatoly
    Sep 6, 2015 at 10:52

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.