Is there a way to start up MySQL Instance before Apache Instance on Scalr?

2.3k Views Asked by At

I am using Scalr for scaling the website server.

On the Apache server, I have installed Sakai, and created an boot-up script for Linux machine.

The question is, how can I ensure that MySQL Instance is booted up and running before the Apache server is booted up, because if Apache server gets booted up first, then the connection for running Sakai will fail, and that causes all sorts of problems.

How I can ensure the instance start at the way I need it to start? I am still new to Scalr so any help would be appreciated.

Thanks

1

There are 1 best solutions below

0
On

If you wrote the Apache startup-script yourself, you can include a check if the database instance is already running.

You can include a simple wait-loop:

MYSQL_OK=1
while ["$MYSQL_OK" -ne 0] ; do
   echo "SELECT version();" | mysql -utestuser -ptestpassword testdb
   MYSQL_OK=$?
   sleep 5
done

Obivously you have to create some testuser and the test-database in Mysql:

CREATE DATABASE testdb;
GRANT USAGE,SELECT ON testdb.* TO 'testuser'@'localhost' IDENTIFIED BY 'testpassword';
FLUSH PRIVILEGES;

Simply put the while-loop somewhere in the start) part of your script. If your system is some kind of Redhat-system, you will notice that the start-script /etc/init.d/httpd has a line like this:

Required-Start: $local_fs $remote_fs $network $named

If you add $mysqld to that line, Apache will insist on a running mysqld before startup:

Required-Start: $local_fs $remote_fs $network $named $mysqld

However, the disadvantage is that the Apache startup will fail instead of waiting for running mylsqd.

Good luck, Alex.