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:

#!/bin/bash
#
### BEGIN INIT INFO
# 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.
### END INIT INFO

#
# main()
#
case "${1:-''}" in
  'start')
   # 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
   ;;
  'stop')
   ;;
  'restart')
   ;;
  'reload'|'force-reload')
   ;;
  'status')
   ;;
  *)
   echo "Usage: $SELF start"
   exit 1
   ;;
esac

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

References: http://bernaerts.dyndns.org/linux/50-compactflash-tune-apache

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 !


    ReplyDelete