Skip to content
Browse files

Merge "speed up mysql provision"

  • Loading branch information...
2 parents 032f508 + 82be97c commit cf4238a8107ee49bf21278dff5e1f691217e8591 @EagleChen EagleChen committed with Gerrit Code Review Nov 14, 2012
View
9 jobs/mysql_node_ng/templates/my.cnf.erb
@@ -5,22 +5,23 @@ plan = properties.plan || "free"
plan_conf = plan_enabled && properties.service_plans.send(service.to_sym).send(plan.to_sym).configuration
warden = plan_conf.warden
use_warden = warden && warden.enable
+base_folder = use_warden ? '/store/instance' : '/var/vcap/sys/run/mysqld'
%>
[client]
port = 3306
-socket = /var/vcap/sys/run/mysqld/mysqld.sock
+socket = <%= "#{base_folder}/mysqld.sock" %>
[mysqld_safe]
-socket = /var/vcap/sys/run/mysqld/mysqld.sock
+socket = <%= "#{base_folder}/mysqld.sock" %>
nice = 0
log-error = <%= use_warden ? '/store/log/mysqld.err.log' : '/var/vcap/sys/log/mysql/mysqld.err.log' %>
[mysqld]
collation_server = utf8_unicode_ci
character_set_server = utf8
user = vcap
-pid-file = /var/vcap/sys/run/mysqld/mysqld.pid
-socket = /var/vcap/sys/run/mysqld/mysqld.sock
+pid-file = <%= "#{base_folder}/mysqld.pid" %>
+socket = <%= "#{base_folder}/mysqld.sock" %>
port = 3306
basedir = /var/vcap/packages/mysql
datadir = <%= use_warden ? '/store/instance/data' : '/var/vcap/store/mysql' %>
View
9 jobs/mysql_node_ng/templates/my55.cnf.erb
@@ -5,22 +5,23 @@ plan = properties.plan || "free"
plan_conf = plan_enabled && properties.service_plans.send(service.to_sym).send(plan.to_sym).configuration
warden = plan_conf.warden
use_warden = warden && warden.enable
+base_folder = use_warden ? '/store/instance' : '/var/vcap/sys/run/mysqld'
%>
[client]
port = 3307
-socket = /var/vcap/sys/run/mysqld/mysqld55.sock
+socket = <%= "#{base_folder}/mysqld55.sock" %>
[mysqld_safe]
-socket = /var/vcap/sys/run/mysqld/mysqld55.sock
+socket = <%= "#{base_folder}/mysqld55.sock" %>
nice = 0
log-error = <%= use_warden ? '/store/log/mysqld55.err.log' : '/var/vcap/sys/log/mysql/mysqld55.err.log' %>
[mysqld]
collation_server = utf8_unicode_ci
character_set_server = utf8
user = vcap
-pid-file = /var/vcap/sys/run/mysqld/mysqld55.pid
-socket = /var/vcap/sys/run/mysqld/mysqld55.sock
+pid-file = <%= "#{base_folder}/mysqld55.pid" %>
+socket = <%= "#{base_folder}/mysqld55.sock" %>
port = 3307
basedir = /var/vcap/packages/mysql55
datadir = <%= use_warden ? '/store/instance/data' : '/var/vcap/store/mysql55' %>
View
1 jobs/mysql_node_ng/templates/pre_service_start.sh
@@ -1,2 +1 @@
chown vcap:vcap -R /store
-chown vcap:vcap -R /var/vcap
View
64 jobs/mysql_node_ng/templates/warden_ctl
@@ -7,6 +7,64 @@ MYSQL55_DIR=/var/vcap/packages/mysql55
source /var/vcap/packages/mysql_node_ng/common/services/utils.sh
+create_initdb () {
+ initdb_name=$1
+ mysql_dir=$2
+ i=0
+ server_startup_timeout=10
+ server_shutdown_timeout=10
+
+ rm -rf $ROOT_DIR/$mysql_dir/$initdb_name
+ rm -rf /var/vcap/data/$initdb_name
+ mkdir -p /var/vcap/data/$initdb_name
+ chmod -R 1777 /var/vcap/data/$initdb_name
+
+ echo "Initialize data directory for mysql in $mysql_dir"
+
+ $mysql_dir/bin/mysql_install_db --basedir=$mysql_dir --user=vcap \
+ --datadir=/var/vcap/data/$initdb_name
+ cd $mysql_dir
+ ./bin/mysqld_safe --user=vcap --datadir=/var/vcap/data/$initdb_name &
+
+ while test $i -ne $server_startup_timeout; do
+ if test -s /var/vcap/data/$initdb_name/*.pid; then
+ i='' && break
+ fi
+ sleep 1
+ i=`expr $i + 1`
+ done
+
+ if test -n "$i"; then
+ echo "Fail to start the temporary mysql server in $msyql_dir"
+ exit 1
+ fi
+
+ export LD_LIBRARY_PATH=$mysql_dir/lib/mysql
+ ./bin/mysqladmin shutdown
+ i=0
+ while test $i -ne $server_shutdown_timeout; do
+ if test ! -s /var/vcap/data/$initdb_name/*.pid; then
+ i='' && break
+ fi
+ sleep 1
+ i=`expr $i + 1`
+ done
+
+ if test -n "$i"; then
+ echo "Fail to shutdown the temporary mysql server in $mysql_dir"
+ exit 1
+ fi
+
+ if test ! -d /var/vcap/data/$initdb_name/mysql; then
+ echo "Fail to initialize database directory in $mysql_dir"
+ exit 1
+ fi
+
+ rsync -arl --exclude=test --exclude=*.err \
+ /var/vcap/data/$initdb_name $ROOT_DIR/$mysql_dir
+ chmod -R 777 $ROOT_DIR/$mysql_dir/$initdb_name
+}
+
case $1 in
start)
@@ -24,11 +82,17 @@ case $1 in
install -m 0755 -d $ROOT_DIR/$JOB_DIR/config
rsync -arl $JOB_DIR/config/warden_mysql_init $ROOT_DIR/$JOB_DIR/config/mysql_init
+ chmod 0644 $ROOT_DIR/$JOB_DIR/config/mysql_init
rsync -arl $JOB_DIR/config/my.cnf $ROOT_DIR/$JOB_DIR/config/my.cnf
rsync -arl $JOB_DIR/config/my55.cnf $ROOT_DIR/$JOB_DIR/config/my55.cnf
+ chmod 0644 $ROOT_DIR/$JOB_DIR/config/my.cnf
+ chmod 0644 $ROOT_DIR/$JOB_DIR/config/my55.cnf
install -m 0755 -t $ROOT_DIR/usr/sbin $JOB_DIR/bin/pre_service_start.sh
+ create_initdb "initdb" $MYSQL_DIR
+ create_initdb "initdb55" $MYSQL55_DIR
+
echo "Starting warden."
start_warden
View
4 jobs/mysql_node_ng/templates/warden_service_ctl
@@ -5,7 +5,9 @@ case $1 in
version=$1
mkdir -p /store/instance/mysql_tmp
- mkdir -p /var/vcap/sys/run
+ if test ! -d /store/instance/data/mysql; then
+ rsync -arl /var/vcap/packages/mysql${version}/initdb${version}/* /store/instance/data
+ fi
/var/vcap/packages/mysql${version}/libexec/mysql_warden.server start /var/vcap/jobs/mysql_node_ng/config/my${version}.cnf
;;
View
4 src/mysql/mysql55_warden.server
@@ -21,8 +21,8 @@ service_startup_timeout=900
# The following variables are only set for letting mysql.server find things.
# Set some defaults
-pid_file=/var/vcap/sys/run/mysqld/mysqld.pid
-server_pid_file=/var/vcap/sys/run/mysqld/mysqld.pid
+pid_file=/store/instance/mysqld55.pid
+server_pid_file=/store/instance/mysqld55.pid
use_mysqld_safe=1
user=vcap
View
4 src/mysql/mysql_warden.server
@@ -21,8 +21,8 @@ service_startup_timeout=900
# The following variables are only set for letting mysql.server find things.
# Set some defaults
-pid_file=/var/vcap/sys/run/mysqld/mysqld.pid
-server_pid_file=/var/vcap/sys/run/mysqld/mysqld.pid
+pid_file=/store/instance/mysqld.pid
+server_pid_file=/store/instance/mysqld.pid
use_mysqld_safe=1
user=vcap

0 comments on commit cf4238a

Please sign in to comment.
Something went wrong with that request. Please try again.