Skip to content

Instantly share code, notes, and snippets.

@KlausTrainer
Created February 8, 2012 09:11
Show Gist options
  • Save KlausTrainer/1767033 to your computer and use it in GitHub Desktop.
Save KlausTrainer/1767033 to your computer and use it in GitHub Desktop.
MySQL in tmpfs
# MySQL Service
description "MySQL Server"
author "Mario Limonciello <superm1@ubuntu.com>"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
respawn
env HOME=/etc/mysql
umask 007
# The default of 5 seconds is too low for mysql which needs to flush buffers
kill timeout 300
pre-start script
#Sanity checks
[ -r $HOME/my.cnf ]
[ -d /var/run/mysqld ] || install -m 755 -o mysql -g root -d /var/run/mysqld
/lib/init/apparmor-profile-load usr.sbin.mysqld
[ -k /var/lib/mysql ] && umount -f /var/lib/mysql
rm -rf /var/lib/mysql
mkdir -m 0700 /var/lib/mysql
mount -t tmpfs none /var/lib/mysql
chown mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql --ldata=/var/lib/mysql
LC_ALL=C BLOCKSIZE= df --portability /var/lib/mysql/. | tail -n 1 | awk '{ exit ($4<4096) }'
end script
exec /usr/sbin/mysqld
post-start script
for i in `seq 1 30` ; do
/usr/bin/mysqladmin --defaults-file="${HOME}"/debian.cnf ping && {
exec "${HOME}"/debian-start
# should not reach this line
exit 2
}
sleep 1
done
exit 1
end script
post-stop script
[ -k /var/lib/mysql ] && umount -f /var/lib/mysql
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment