Ubuntu – MySQL server Upstart script not working on boot

bootMySQLopenvzserverupstart

For some reason the Upstart script for the MySQL server isn't working when I boot my server, however it does work once the server has booted and I execute sudo start mysql manually.

I'm running an OpenVZ VPS with Ubuntu 10.04 installed and MySQL version 5.1.41 (latest stable from the repository). MySQL is a fresh install with no config changed.

/etc/init/mysql.conf:

# 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

pre-start script
    #Sanity checks
    [ -r $HOME/my.cnf ]
    [ -d /var/run/mysqld ] || install -m 755 -o mysql -g root -d /var/run/mysqld
    # Load AppArmor profile
    if aa-status --enabled 2>/dev/null; then
        apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld || true
    fi
    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

Best Answer

Turns out Upstart start up jobs can have problems on OpenVZ.

Changing:

start on (net-device-up
          and local-filesystems
      and runlevel [2345])

to:

start on runlevel [2345]

fixed the problem for me.