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
#
### 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
I had the same problem with Tomcat which must write in /var/log/tomcat6.
ReplyDeleteI copied and changed your script and everything works!
Thank you !