Jump to content
Sign in to follow this  
jim

Folders & files in /var/log/ keep disappearing!

Recommended Posts

Hi,

I have installed LAMP and it is working really well, until I reboot the system.  Apache doesn't start up and complains that it can't find the /var/log/apache2 directory for it to write log files to. 

I then create the directory, which appeases Apache, and it starts up nicely again.

It seems that after every reboot, the /var/log/apache2 folder keeps disappearing, and so I have to recreate it every time.

It has the same owner, group (root) and permissions as other folders in that directory so I am not sure what is going on.

Is anyone else using apache2?

I tried creating other folders and put dummy test log files in /var/log/ and they disappear as well!  Is there a 'berbudaTriagle -no_way' command available? 

I am new to Linux so any advice would be appreciated.

Thanks,
macro

PS  Where are all those files and folders going?  Are they appearing out of a worm-hole at the other side of the universe somewhere?

Share this post


Link to post
Share on other sites

By default /var is a tmpfs file system... it is recreated on each boot. This is done to lower the write cycles to the flash memory and to keep from filling the permanent storage.

There are two simple solutions available to you. First, you can add commands /etc/rc.local to create the necessary directory in /var/log on each boot. Alternatively, you can choose to not have /var/log as a tmpfs -- just comment out the in /etc/fstab. 

Enjoy!
Bill

Share this post


Link to post
Share on other sites

Thanks Bill,  I didn't know that about the /var directory.  I must have missed a step that told me that.

I went another way to fix the problem in the hope that it wouldn't increase the write cycles.  It seems to work well, but do you see any possible hitches with the following?


I edited Apache's environment variables file ( /etc/apache2/envvars ) by commenting out:
#export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

and adding:
export APACHE_LOG_DIR=/etc/apache2$SUFFIX


I then created a file called:
/home/ubuntu/.config/autostart/StartApache.desktop

that contained the following:
[Desktop Entry]
Type=Application
Exec=sudo service apache2 restart


As I said all runs well but as I am new to this I thought I better check.   undecided.gif

Share this post


Link to post
Share on other sites

This will be writing to your /etc directory instead of the /var/log. Meaning you will be writing to your flash. Also, the log file will not be in the log rotation list, so may eventually fill all available space in your root file system.

A better solution would be updating /etc/rc.local with this line (immediately before the 'exit 0'):

Code: [select]

mkdir -p /var/log/apache2
By updating /etc/rc.local, you should not need to restart the apache2 service with a desktop autostart item.

Enjoy!
Bill

Share this post


Link to post
Share on other sites

I understand now.  I am grateful for your reply, and so is my flash!

I added the entry to /etc/rc.local as you suggested and it works great now.

Thanks again for your help.   smiley.gif

Share this post


Link to post
Share on other sites

Having encountered the same problem, I stumbled onto this thread.  Even after commenting the line out of fstab, I found that /var/log/apache2 would STILL disappear or reboot.  Only after I put a dummy file in the folder did it quit getting deleted.  I don't know if that lucky happenstance or some rational, explainable behavior.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×