From 6631c02d1ea75c4173403e0d79fdadee24ddaa6e Mon Sep 17 00:00:00 2001 From: Joe Mackey Date: Wed, 10 Jul 2013 17:00:02 -0700 Subject: [PATCH 1/3] Adding evolvedb to collins init script Divide out creating the DB from actually evolving it. --- scripts/collins.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/collins.sh b/scripts/collins.sh index 08abb4f2f..1d34d6b64 100755 --- a/scripts/collins.sh +++ b/scripts/collins.sh @@ -48,8 +48,7 @@ function find_java() { find_java -case "$1" in - initdb) +initialize_db() { echo "mysql root password. Enter for none." mysql -u root -p -e 'create database if not exists collins;' if [ -z "$2" ]; then @@ -66,14 +65,29 @@ case "$1" in fi echo "mysql root password. Enter for none." mysql -u root -p -e "grant all privileges on collins.* to $db_username@'127.0.0.1' identified by '$db_password';" + +} + +evolve_db() { if [ ! -x $JAVA_HOME/bin/java ]; then echo "FAIL" echo "Didn't find $JAVA_HOME/bin/java, check JAVA_HOME?" exit 1 fi + echo "Running migrations" ${JAVA_HOME}/bin/java ${APP_OPTS} -cp "$APP_HOME/lib/*" DbUtil $APP_HOME/conf/evolutions/ echo "Database initialization attempted" > /var/run/$APP_NAME/install.log +} + +case "$1" in + initdb) + initialize_db $1 $2 $3 + evolve_db + ;; + + evolvedb) + evolve_db ;; start) From 8ea70871033ef086474b90547fafbf3358e739a3 Mon Sep 17 00:00:00 2001 From: Benjamin VanEvery Date: Tue, 27 May 2014 19:55:04 -0700 Subject: [PATCH 2/3] Clean up the db initialization script --- scripts/collins.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/scripts/collins.sh b/scripts/collins.sh index 1d34d6b64..54be96707 100755 --- a/scripts/collins.sh +++ b/scripts/collins.sh @@ -49,40 +49,43 @@ function find_java() { find_java initialize_db() { + declare db_username="$1"; + declare db_password="$2"; + echo "mysql root password. Enter for none." - mysql -u root -p -e 'create database if not exists collins;' - if [ -z "$2" ]; then + mysql -u root -p -e 'CREATE DATABASE IF NOT EXISTS collins;' + + if [ -z "$db_username" ]; then read -p "Application Database Username: " db_username else - db_username=$2; + db_username="$2"; fi - if [ -z "$3" ]; then + if [ -z "$db_password" ]; then stty -echo read -p "Application Database Password: " db_password; echo stty echo else - db_password=$3; + db_password="$3"; fi - echo "mysql root password. Enter for none." - mysql -u root -p -e "grant all privileges on collins.* to $db_username@'127.0.0.1' identified by '$db_password';" + echo "mysql root password. Enter for none." + mysql -u root -p -e "GRANT ALL PRIVILEGES ON collins.* to $db_username@'127.0.0.1' IDENTIFIED BY '$db_password';" } evolve_db() { if [ ! -x $JAVA_HOME/bin/java ]; then - echo "FAIL" - echo "Didn't find $JAVA_HOME/bin/java, check JAVA_HOME?" + echo "FAIL. Didn't find $JAVA_HOME/bin/java, check JAVA_HOME?" exit 1 fi echo "Running migrations" ${JAVA_HOME}/bin/java ${APP_OPTS} -cp "$APP_HOME/lib/*" DbUtil $APP_HOME/conf/evolutions/ - echo "Database initialization attempted" > /var/run/$APP_NAME/install.log + echo "Database initialization attempted" >> /var/run/$APP_NAME/install.log } case "$1" in initdb) - initialize_db $1 $2 $3 + initialize_db "$2" "$3" evolve_db ;; From a16a790fc4708a84ebad036b7bf8650d9ba27561 Mon Sep 17 00:00:00 2001 From: Benjamin VanEvery Date: Tue, 27 May 2014 20:05:27 -0700 Subject: [PATCH 3/3] Update "help" message --- scripts/collins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/collins.sh b/scripts/collins.sh index 54be96707..70a8fbb54 100755 --- a/scripts/collins.sh +++ b/scripts/collins.sh @@ -176,8 +176,8 @@ case "$1" in ;; *) - echo "Usage: /etc/init.d/${APP_NAME}.sh {start|stop|restart|status|initdb}" - echo "Note: initdb can optionally be passed a username followed by a password to initialize the db" + echo "Usage: $0 {start|stop|restart|status|initdb|evolvedb}" + echo "Note: 'initdb' can optionally be passed a username followed by a password to initialize the db" exit 1 ;; esac