A couple days ago i received an alert that one of the disks on our linux production machines is filling up very quickly. It was the application server machine and the logging partition was running out of space rapidly. Logs filled up my disk
How logs filled up my disk
Gladly the log files are located on a separated partition which is great, because even if the log partition fills up the application and the application server is still operating normally, we just lose the logging data since the application won’t be able to write to a full partition anymore.
But as we all know, having access to current log files and logging data very is important and it is necessary to fix the issue asap and resume normal operation of the application server. Continue reading to find out how logs filled up my disk and how i quickly resolved the situation.
There is a really easy trick to clean out the log file instantly and free up disk space in linux, without having to restart any service due to file locks, but there is also a catch you must be aware of.
How to clear the log file without service restart?
You can clear the log file by running the following command in linux:
[root@geekpeek ~]# > /path/to/log/file
This will empty out all of the data from the log file reducing it’s size to 0 in matter of seconds without any service disruption whatsoever. Once the log file is emptied out, the service will continue to write to the log file as if nothing happened.
Watch out one thing!
Please note that triggering the above command will delete all of the data from the log file. Usually it is good to check the log file before clearing it out since it probably holds information about the error which caused your log file to grow.
It is best – if possible – to make a copy of the existing log file to a different partition. This way you won’t lose any data.
Practical example:
Here is a practical example of cleaning out a quite big Apache Tomee catalina.out log file while the Tomee service is up and running:
[root@geekpeek logs]# ll -h catalina.out -rw-rw---- 1 tomee tomee 3.1G Jul 29 13:31 catalina.out [root@geekpeek logs]# > catalina.out [root@geekpeek logs]# ll -h catalina.out -rw-rw---- 1 tomee tomee 369 Jul 29 13:31 catalina.out
Catalina.out file was successfully emptied out without any disruption to Tomee service. That’s how i easily solved the situation when the logs filled up my disk.