10

Possible Duplicate:
Logrotate configuration for httpd (CentOS)

can I delete error log files in apache. Any issue? Because it eats my server space

  • 1
    Another "possible duplicate" that is not even close to being the same question. We need to crack down on this. Some answers provide partial coverage, but really this is nothing at all to do with logrotation and it may not even be implemented. – mckenzm Jan 25 '23 at 23:09

4 Answers4

16

If you must clear the log file, do

cp /dev/null /var/log/file

or

echo > /var/log/file

That truncates the file without closing any open file handles.

Edit: Using logrotate to deal with the files is the better long-term solution. Truncating the file should be an emergency measure.

kasperd
  • 30,455
  • 17
  • 76
  • 124
Rob Bos
  • 854
  • 7
  • 8
3

I would rather recommend going for logrotate in stead of deleting the old log files straight away. You might need them later for debugging something or to find out the pattern when system was running fine, for comparison purpose.

There is a reason that backup and recovery are so sought after. However if this is not any production server or something important, I wouldn't worry about deleting them.

Soham Chakraborty
  • 3,584
  • 17
  • 24
1

If you are not going to use them you can delete it. I would recomend you to delete all logs but not the current one, and if you can I should use log rotate.

0

If in use, deleting the log will make apache reload to re-open the just deleted file. What you can try is indeed logrotate, or try to empty the file. I think you'll need to SIGUSR1 apache though.

This link may help.

Edit: Just tested:

# > /var/log/apache2/access.log
# tail -F /var/log/apache2/access.log
.. Still prints lines ....
# rm /var/log/apache2/access.log ; touch /var/log/apache2/access.log
# tail -F /var/log/apache2/access.log
.. displays nothing ....
# kill -USR1 $(pidof apache2)
# tail -F /var/log/apache2/access.log
.. prints lines again ....

Edit2: thanks @voretaq for further info about signals on apache. SIGUSR1 is indeed less violent than SIGHUP.

aif
  • 381
  • 1
  • 8
  • 2
    A graceful restart (`SIGUSR1`) would generally be preferable to a "drop all connections and restart RIGHT FREAKIN' NOW!" (`SIGHUP`). – voretaq7 Oct 12 '12 at 17:11
  • 1
    Thanks @voretaq7 I didn't find out those information on the doc. Editing answer. – aif Oct 12 '12 at 17:34