Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evolve db flag #159

Merged
merged 3 commits into from
Aug 6, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions scripts/collins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,49 @@ function find_java() {

find_java

case "$1" in
initdb)
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';"
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 "$2" "$3"
evolve_db
;;

evolvedb)
evolve_db
;;

start)
Expand Down Expand Up @@ -159,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
Expand Down