Skip to content
Snippets Groups Projects
Commit 8a7783ea authored by Piotr Gawron's avatar Piotr Gawron
Browse files

debian scripts use either default db properties (from...

debian scripts use either default db properties (from persist/main/src/resource/db.properties file) or user defined db properties (/etc/minerva/db.properties)
parent 012cefe5
No related branches found
No related tags found
1 merge request!284Resolve "database configuration should be outside war file"
...@@ -70,6 +70,14 @@ then ...@@ -70,6 +70,14 @@ then
exit 1; exit 1;
fi fi
#default connection params (if /etc/minerva/db.properties is not defined)
DB_HOST=`cat persist/src/main/resources/db.properties |grep "uri" |cut -f3 -d"/" |cut -f1 -d":"`
DB_PORT=`cat persist/src/main/resources/db.properties |grep "uri" |cut -f3 -d"/" |cut -f2 -d":"`
DB_DATABASE_NAME=`cat persist/src/main/resources/db.properties |grep "uri" |cut -f4 -d"/"`
DB_USERNAME=`cat persist/src/main/resources/db.properties |grep "username" |cut -f2 -d"="`
DB_PASSWORD=`cat persist/src/main/resources/db.properties |grep "password" |cut -f2 -d"="`
#------------------------------------------ #------------------------------------------
# Now we have all db schema diff files. Let's start preparing # Now we have all db schema diff files. Let's start preparing
# debian package # debian package
...@@ -107,11 +115,20 @@ sed -i "s/__LOG_FILE__/$LOG_FILE/g" common.sh ...@@ -107,11 +115,20 @@ sed -i "s/__LOG_FILE__/$LOG_FILE/g" common.sh
#in the filesystem where package is installed #in the filesystem where package is installed
sed -i "s/__DB_SCRIPT_DIR__/$DB_SCRIPT_DIR/g" common.sh sed -i "s/__DB_SCRIPT_DIR__/$DB_SCRIPT_DIR/g" common.sh
sed -i "s/__DB_HOST__/$DB_HOST/g" common.sh
sed -i "s/__DB_PORT__/$DB_PORT/g" common.sh
sed -i "s/__DB_DATABASE_NAME__/$DB_DATABASE_NAME/g" common.sh
sed -i "s/__DB_USERNAME__/$DB_USERNAME/g" common.sh
sed -i "s/__DB_PASSWORD__/$DB_PASSWORD/g" common.sh
sed -i -e "1r common.sh" debian/postinst sed -i -e "1r common.sh" debian/postinst
sed -i -e "1r common.sh" debian/postrm sed -i -e "1r common.sh" debian/postrm
sed -i -e "1r common.sh" debian/preinst sed -i -e "1r common.sh" debian/preinst
sed -i -e "1r common.sh" debian/prerm sed -i -e "1r common.sh" debian/prerm
#put scripts into $DB_SCRIPT_DIR (it's a bit different than varaiable because it's not #put scripts into $DB_SCRIPT_DIR (it's a bit different than varaiable because it's not
#escaped #escaped
echo db_0.sql /usr/share\/minerva/schema >> debian/install echo db_0.sql /usr/share\/minerva/schema >> debian/install
......
...@@ -27,3 +27,74 @@ if [ "$TOMCAT8_OK" != "" ]; ...@@ -27,3 +27,74 @@ if [ "$TOMCAT8_OK" != "" ];
then then
TOMCAT_PACKAGE='tomcat8' TOMCAT_PACKAGE='tomcat8'
fi fi
POSTGRES_OK=$(dpkg-query -W --showformat='${Status}\n' postgresql|grep "install ok installed")
DB_HOST="__DB_HOST__"
DB_PORT="__DB_PORT__"
DB_DATABASE_NAME="__DB_DATABASE_NAME__"
DB_USERNAME="__DB_USERNAME__"
DB_PASSWORD="__DB_PASSWORD__"
if [ -f /etc/minerva/db.properties ]; then
DB_PROPERTIES_FILE="/etc/minerva/db.properties"
log "$DB_PROPERTIES_FILE file found"
DB_HOST=`cat $DB_PROPERTIES_FILE |grep "uri" |cut -f3 -d"/" |cut -f1 -d":"`
DB_PORT=`cat $DB_PROPERTIES_FILE |grep "uri" |cut -f3 -d"/" |cut -f2 -d":"`
DB_DATABASE_NAME=`cat $DB_PROPERTIES_FILE |grep "uri" |cut -f4 -d"/"`
DB_USERNAME=`cat $DB_PROPERTIES_FILE |grep "username" |cut -f2 -d"="`
DB_PASSWORD=`cat $DB_PROPERTIES_FILE |grep "password" |cut -f2 -d"="`
fi
#if we connect to something that is not in localhost then we need to provide login and password
#because we won't have access to it as postgres user
if [ "$DB_HOST" != "localhost" ] && [ "$DB_HOST" != "127.0.0.1" ]
then
log "DB is located on the remote server: $DB_HOST"
IS_REMOTE_DB=true
else
log "DB is at localhost: $DB_HOST"
IS_REMOTE_DB=false
fi
exec_sql(){
log "Execute SQL : '$1'"
echo "$1" |PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USERNAME $DB_DATABASE_NAME >>$LOG_FILE 2>>$LOG_FILE
}
exec_sql_file(){
log "Execute SQL file: $1"
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USERNAME $DB_DATABASE_NAME -f $1 >>$LOG_FILE 2>>$LOG_FILE
}
create_db(){
if [ $IS_REMOTE_DB = false ]
then
su - postgres -c "createuser -d -r -s -p $DB_PORT $DB_USERNAME" >>$LOG_FILE 2>>$LOG_FILE
log "User created"
su - postgres -c "echo \"ALTER USER $DB_USERNAME WITH PASSWORD '$DB_PASSWORD';\"| psql -p $DB_PORT " >>$LOG_FILE 2>>$LOG_FILE
log "User credentials updated"
su - postgres -c "createdb -p $DB_PORT -O $DB_USERNAME $DB_DATABASE_NAME" >>$LOG_FILE 2>>$LOG_FILE
log "Db created"
hba_conf=`su - postgres -c "psql -t -P format=unaligned -c 'show hba_file';"`;
cp $hba_conf $hba_conf".bac"
cat $hba_conf".bac" |grep -v "all[ \t]*peer" >$hba_conf
printf "local all all md5\n" >>$hba_conf
invoke-rc.d postgresql restart
else
log "HOST is remote, assuming db and user are already there"
fi
}
stop_postgres() {
if [ $IS_REMOTE_DB = false ]
then
invoke-rc.d postgresql stop || true
fi
}
start_postgres() {
if [ $IS_REMOTE_DB = false ]
then
invoke-rc.d postgresql restart
fi
}
...@@ -21,29 +21,21 @@ set -e ...@@ -21,29 +21,21 @@ set -e
case "$1" in case "$1" in
configure) configure)
invoke-rc.d postgresql start start_postgres
#if we install #if we install
if [ "$OLD_VERSION" = "" ] if [ "$OLD_VERSION" = "" ]
then then
su - postgres -c "createuser -d -r -s map_viewer" >>$LOG_FILE 2>>$LOG_FILE create_db
su - postgres -c "echo \"ALTER USER map_viewer WITH PASSWORD '123qweasdzxc';\"| psql" >>$LOG_FILE 2>>$LOG_FILE
su - postgres -c "createdb -O map_viewer map_viewer" >>$LOG_FILE 2>>$LOG_FILE
hba_conf=`su - postgres -c "psql -t -P format=unaligned -c 'show hba_file';"`;
cp $hba_conf $hba_conf".bac"
cat $hba_conf".bac" |grep -v "all[ \t]*peer" >$hba_conf
printf "local all all md5\n" >>$hba_conf
invoke-rc.d postgresql restart
#install base version of the framework #install base version of the framework
su - postgres -c "psql map_viewer -f $DB_SCRIPT_DIR/db_0.sql" >>$LOG_FILE 2>>$LOG_FILE exec_sql_file "$DB_SCRIPT_DIR/db_0.sql"
#install patch to current version #install patch to current version
su - postgres -c "psql map_viewer -f $DB_SCRIPT_DIR/db_0_to_$CURRENT_VERSION\".sql\"" >>$LOG_FILE 2>>$LOG_FILE exec_sql_file "$DB_SCRIPT_DIR/db_0_to_${CURRENT_VERSION}.sql"
else else
#if we update the package #if we update the package
su - postgres -c "psql map_viewer -f $DB_SCRIPT_DIR/db_$OLD_VERSION\"_to_\"$CURRENT_VERSION\".sql\"" >>$LOG_FILE 2>>$LOG_FILE exec_sql_file "$DB_SCRIPT_DIR/db_${OLD_VERSION}_to_${CURRENT_VERSION}.sql"
fi fi
#print a disclaimer #print a disclaimer
......
...@@ -10,15 +10,6 @@ ...@@ -10,15 +10,6 @@
log "Running postrm" $1 $2; log "Running postrm" $1 $2;
log "Checking postgresql...";
POSTGRES_OK=$(dpkg-query -W --showformat='${Status}\n' postgresql|grep "install ok installed")
if [ "" = "$POSTGRES_OK" ]
then
log "postgresql not found";
else
log "postgresql found";
fi
# we execute it here because if some packages are missing then dpkg will return non-zero exit code # we execute it here because if some packages are missing then dpkg will return non-zero exit code
set -e set -e
...@@ -26,34 +17,41 @@ case "$1" in ...@@ -26,34 +17,41 @@ case "$1" in
upgrade) upgrade)
rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva
rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva.war rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva.war
# invoke-rc.d $TOMCAT_PACKAGE start || true
# invoke-rc.d postgresql start || true
;; ;;
remove) remove)
rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva
rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva.war rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva.war
invoke-rc.d $TOMCAT_PACKAGE start || true invoke-rc.d $TOMCAT_PACKAGE start || true
if [ "" = "$POSTGRES_OK" ] if [ $IS_REMOTE_DB = true ]
then then
log "No postgresql package found."; exec_sql "drop owned by $DB_USERNAME;"
else else
invoke-rc.d postgresql start if [ "" = "$POSTGRES_OK" ]
su - postgres -c "dropdb map_viewer" then
su - postgres -c "dropuser map_viewer" log "No postgresql package found.";
else
start_postgres
su - postgres -c "dropdb -p $DB_PORT $DB_DATABASE_NAME"
su - postgres -c "dropuser -p $DB_PORT $DB_USERNAME"
fi
fi fi
;; ;;
abort-install) abort-install)
invoke-rc.d $TOMCAT_PACKAGE start || true invoke-rc.d $TOMCAT_PACKAGE start || true
if [ $IS_REMOTE_DB = true ]
if [ "" = "$POSTGRES_OK" ];
then then
log "No postgresql package found."; exec_sql "drop owned by $DB_USER"
else else
invoke-rc.d postgresql restart if [ "" = "$POSTGRES_OK" ];
su - postgres -c "dropdb map_viewer" then
su - postgres -c "dropuser map_viewer" log "No postgresql package found.";
else
start_postgres
su - postgres -c "dropdb -p $DB_PORT $DB_DATABASE_NAME"
su - postgres -c "dropuser -p $DB_PORT $DB_USERNAME"
fi
fi fi
;; ;;
*) *)
echo "postrm called with unknown argument \`$1'" >&2 echo "postrm called with unknown argument \`$1'" >&2
exit 1 exit 1
......
...@@ -24,12 +24,12 @@ ln -s $path $DEFAULT_JAVA_SYMLINK ...@@ -24,12 +24,12 @@ ln -s $path $DEFAULT_JAVA_SYMLINK
case "$1" in case "$1" in
install|upgrade) install|upgrade)
invoke-rc.d $TOMCAT_PACKAGE stop || true invoke-rc.d $TOMCAT_PACKAGE stop || true
invoke-rc.d postgresql stop || true stop_postgres
;; ;;
abort-upgrade) abort-upgrade)
invoke-rc.d $TOMCAT_PACKAGE stop || true invoke-rc.d $TOMCAT_PACKAGE stop || true
invoke-rc.d postgresql stop || true stop_postgres
;; ;;
*) *)
echo "preinst called with unknown argument \`$1'" >&2 echo "preinst called with unknown argument \`$1'" >&2
......
...@@ -17,20 +17,20 @@ set -e ...@@ -17,20 +17,20 @@ set -e
log Running prerm $1 $2; log Running prerm $1 $2;
invoke-rc.d postgresql start || true invoke-rc.d postgresql start || true
TIMESTAMP=$(date +"%F") TIMESTAMP=$(date +"%F_%H%M%S")
DUMP_FILE=$DB_SCRIPT_DIR/dump_$TIMESTAMP DUMP_FILE=$DB_SCRIPT_DIR/dump_$TIMESTAMP
log "dump map_viewer database to file $DUMP_FILE" log "dump $DB_DATABASE_NAME database to file $DUMP_FILE"
su - postgres -c "pg_dump map_viewer" | gzip > "$DUMP_FILE".gz PGPASSWORD=$DB_PASSWORD pg_dump -h $DB_HOST -p $DB_PORT -U $DB_USERNAME $DB_DATABASE_NAME | gzip > "$DUMP_FILE".gz
case "$1" in case "$1" in
upgrade) upgrade)
invoke-rc.d $TOMCAT_PACKAGE stop || true invoke-rc.d $TOMCAT_PACKAGE stop || true
invoke-rc.d postgresql stop || true stop_postgres
;; ;;
remove) remove)
invoke-rc.d $TOMCAT_PACKAGE stop || true invoke-rc.d $TOMCAT_PACKAGE stop || true
invoke-rc.d postgresql stop || true stop_postgres
;; ;;
*) *)
echo "prerm called with unknown argument \`$1'" >&2 echo "prerm called with unknown argument \`$1'" >&2
......
...@@ -45,38 +45,30 @@ ...@@ -45,38 +45,30 @@
"litemol": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412" "litemol": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412"
}, },
"dependencies": { "dependencies": {
"ProtVista": {
"version": "git://github.com/davidhoksza/protvista.git#4e4bb737ba1e183291505bd25f8bae2e651ce21e",
"dev": true,
"requires": {
"d3": "3.5.17",
"file-saver": "1.3.3",
"jquery": "2.2.4",
"jszip": "3.1.4",
"underscore": "1.8.3"
},
"dependencies": {
"jquery": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz",
"integrity": "sha1-LInWiJterFIqfuoywUUhVZxsvwI=",
"dev": true
}
}
},
"jquery": { "jquery": {
"version": "3.3.1", "version": "3.3.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz",
"integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==", "integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==",
"dev": true "dev": true
}, }
"litemol": { }
"version": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412", },
"dev": true, "ProtVista": {
"requires": { "version": "git://github.com/davidhoksza/protvista.git#4e4bb737ba1e183291505bd25f8bae2e651ce21e",
"@types/react": "15.6.15", "dev": true,
"@types/react-dom": "15.5.7" "requires": {
} "d3": "3.5.17",
"file-saver": "1.3.3",
"jquery": "2.2.4",
"jszip": "3.1.4",
"underscore": "1.8.3"
},
"dependencies": {
"jquery": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz",
"integrity": "sha1-LInWiJterFIqfuoywUUhVZxsvwI=",
"dev": true
} }
} }
}, },
...@@ -2058,6 +2050,14 @@ ...@@ -2058,6 +2050,14 @@
"immediate": "3.0.6" "immediate": "3.0.6"
} }
}, },
"litemol": {
"version": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412",
"dev": true,
"requires": {
"@types/react": "15.6.15",
"@types/react-dom": "15.5.7"
}
},
"lodash": { "lodash": {
"version": "4.17.4", "version": "4.17.4",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment