Mar 14, 2012

Laptop, SSD, tmpfs and Apache

When you have SSD disk in your laptop, you probably use tmpfs for /var/log. There is usually no need to store logs between restarts. The number of writes to the disk is much lower with tmpfs. It means the SSD disk lasts longer ;-).

The problem with tmpfs is Apache won't start without /var/log/apache2 directory created. We have to create it before the apache2 service will start.

So let's create a file:

$ sudo nano /etc/init.d/apache2-tmpfs

with this content:

# Provides:          apache2-tmpfs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Required-Start:  
# Required-Stop:   
# Short-Description: Create /var/log/apache2/error.log on tmpfs at startup
# Description:       Create /var/log/apache2/error.log needed by Apache.

# main()
case "${1:-''}" in
   # create the /var/log/apache2/error.log needed by apache
   mkdir /var/log/apache2
   chmod 777 /var/log/apache2
   touch /var/log/apache2/error.log
   chmod 777 /var/log/apache2/error.log
   echo "Usage: $SELF start"
   exit 1

Let's make this file executable:

$ sudo chmod 0755 /etc/init.d/apache2-tmpfs

And set it to start and stop before apache2 service when booting or halting the computer:

$ sudo update-rc.d apache2-tmpfs defaults 90 10


1 comment:

  1. I had the same problem with Tomcat which must write in /var/log/tomcat6.

    I copied and changed your script and everything works!

    Thank you !