Skip to content
Snippets Groups Projects
Commit 84f3bc30 authored by felmer's avatar felmer
Browse files

LMS-2471 bugs fixed, making scripts more robust

SVN: 22806
parent 58ae419f
No related branches found
No related tags found
No related merge requests found
Showing
with 74 additions and 24 deletions
#! /bin/bash #! /bin/bash
# #
# This script checks whether openBIS AS server is a sprint server installed in the current week # This script checks whether openBIS AS server is a sprint server installed in the current week
# or not. If yes exit (with exit code 0) is executed. # or not. If yes it exits with exit code 1.
# #
# usage: check-and-exit-if-new-sprint-server.sh <servers> # usage: check-and-exit-if-new-sprint-server.sh <servers> <version file>
# #
# where # where
# <servers> is the path to the directory containing the server folders 'openBIS-server' # <servers> is the path to the directory containing the server folders 'openBIS-server'
# and 'datastore_server', # and 'datastore_server',
# <version file> is a file which will contain the time stamp of first installation of
# a major version. If it doesn't exist it will be created.
# #
if [ $# -ne 1 ]; then #
echo "Usage: check-and-exit-if-new-sprint-server.sh <servers>" set -o nounset
exit 1 set -o errexit
fi
function getValue {
file="$1"
if [ -f "$file" ]; then
awk -F ' *= *' -v key=$2 '{map[$1] = $2} END {print map[key]}' "$file"
fi
}
SERVERS="$1" SERVERS="$1"
VERSION_FILE="$2"
LOG_FILE=$SERVERS/openBIS-server/jetty/logs/jetty.out LOG_FILE=$SERVERS/openBIS-server/jetty/logs/jetty.out
CURRENT_VERSION=UNKNOWN CURRENT_VERSION=UNKNOWN
if [ -f $LOG_FILE ]; then if [ -f $LOG_FILE ]; then
CURRENT_VERSION=`awk '/STATUS.CISDContextLoaderListener - Version/ {print $1" "$2" "$8" "$9}' $LOG_FILE | tail -1` CURRENT_VERSION=`awk '/STATUS.CISDContextLoaderListener - Version/ {print $1" "$2" "$8" "$9}' $LOG_FILE | head -n 1`
CURRENT_VERSION_NAME=`echo $CURRENT_VERSION|awk '{print $3}'`
if [ $CURRENT_VERSION_NAME == "" ]; then
echo "Current version of openBIS Application Server not known"
exit
fi
echo "Current openBIS Application Server: $CURRENT_VERSION" echo "Current openBIS Application Server: $CURRENT_VERSION"
if [ "SNAPSHOT" != "`echo $CURRENT_VERSION|awk '{print $3}'`" ]; then if [ "SNAPSHOT" != $CURRENT_VERSION_NAME ]; then
TIME_STAMP="`echo $CURRENT_VERSION|awk '{print $1, $2}'`" CURRENT_MAJOR_VERSION=${CURRENT_VERSION_NAME%.*}
WEEK=`date --date="$TIME_STAMP" "+%W"` echo "Current major version: $CURRENT_MAJOR_VERSION"
if [ $? -ne 0 ]; then TIME_STAMP=`getValue "$VERSION_FILE" $CURRENT_MAJOR_VERSION`
if [ -z "$TIME_STAMP" ]; then
TIME_STAMP="`echo $CURRENT_VERSION|awk '{print $1, $2}'`"
echo "$CURRENT_MAJOR_VERSION = $TIME_STAMP" >> "$VERSION_FILE"
fi
echo "Time stamp of major version: $TIME_STAMP"
if ! WEEK=`date --date="$TIME_STAMP" "+%W"`; then
# Mac OSX has a different flavor of date command # Mac OSX has a different flavor of date command
WEEK=`date -j -f "%Y-%m-%d %H:%M:%S" "$TIME_STAMP" "+%W"` WEEK=`date -j -f "%Y-%m-%d %H:%M:%S" "$TIME_STAMP" "+%W"`
fi fi
CURRENT_WEEK=`date "+%W"` CURRENT_WEEK=`date "+%W"`
if [ "$WEEK" = "$CURRENT_WEEK" ]; then if [ "$WEEK" = "$CURRENT_WEEK" ]; then
echo "Sprint server not replaced until next week." echo "Sprint server not replaced until next week."
exit exit 1
fi fi
fi fi
fi fi
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
# Empty lines and lines starting with '#' are ignored # Empty lines and lines starting with '#' are ignored
# #
# #
set -o nounset
set -o errexit
if [ $# -lt 3 ]; then if [ $# -lt 3 ]; then
echo "Usage: create-config-snapshot.sh <servers> <snapshot repository> <config file list 1> ... <config file list n>" echo "Usage: create-config-snapshot.sh <servers> <snapshot repository> <config file list 1> ... <config file list n>"
exit 1 exit 1
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
# Dependencies: # Dependencies:
# - create-snapshot.sh # - create-snapshot.sh
# #
set -o nounset
set -o errexit
BIN_DIR=`dirname "$0"` BIN_DIR=`dirname "$0"`
REPOSITORY=~/snapshots REPOSITORY=~/snapshots
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
# - Store dump doesn't contain archived data sets and data sets in a share which is a symbolic link. # - Store dump doesn't contain archived data sets and data sets in a share which is a symbolic link.
# - The configuration file of the argument is stored in the snapshot. It is used for restoring. # - The configuration file of the argument is stored in the snapshot. It is used for restoring.
# #
set -o nounset
set -o errexit
function getValue { function getValue {
file=$1 file=$1
key=$2 key=$2
...@@ -91,8 +94,7 @@ for path in "$STORE"/*; do ...@@ -91,8 +94,7 @@ for path in "$STORE"/*; do
else else
echo "Start dumping share $file_name." echo "Start dumping share $file_name."
parent_folder=${path:0:$index_of_last_slash} parent_folder=${path:0:$index_of_last_slash}
tar -rf "$SNAPSHOT/store.tar" -C "$parent_folder" $file_name if ! tar -rf "$SNAPSHOT/store.tar" -C "$parent_folder" $file_name; then
if [ $? -ne 0 ]; then
echo "Error while dumping share $file_name. Snapshot creation aborted." echo "Error while dumping share $file_name. Snapshot creation aborted."
exit 1 exit 1
fi fi
...@@ -103,23 +105,20 @@ done ...@@ -103,23 +105,20 @@ done
echo "Dump of store $STORE has been successfully created." echo "Dump of store $STORE has been successfully created."
############## dump databases ############## ############## dump databases ##############
for db in $DATABASES; do for db in $DATABASES; do
pg_dump -U postgres -O $db > "$SNAPSHOT/$db.sql" if ! pg_dump -U postgres -O $db > "$SNAPSHOT/$db.sql"; then
if [ $? -ne 0 ]; then
echo "Error dumping database '$db'. Snapshot creation aborted." echo "Error dumping database '$db'. Snapshot creation aborted."
exit 1 exit 1
fi fi
echo "Database '$db' has been successfully dumped." echo "Database '$db' has been successfully dumped."
done done
############## dump index ############## ############## dump index ##############
tar -cf "$SNAPSHOT/index.tar" -C "$INDEX" . if ! tar -cf "$SNAPSHOT/index.tar" -C "$INDEX" .; then
if [ $? -ne 0 ]; then
echo "Error creating index dump. Snapshot creation aborted." echo "Error creating index dump. Snapshot creation aborted."
exit 1 exit 1
fi fi
echo "Dump of index $INDEX has been successfully created." echo "Dump of index $INDEX has been successfully created."
############## packaging ############## ############## packaging ##############
tar -zcf "$SNAPSHOT.tgz" -C "$REPOSITORY" "$SNAPSHOT_FOLDER_NAME" if ! tar -zcf "$SNAPSHOT.tgz" -C "$REPOSITORY" "$SNAPSHOT_FOLDER_NAME"; then
if [ $? -ne 0 ]; then
echo "Error packaging snapshot $SNAPSHOT." echo "Error packaging snapshot $SNAPSHOT."
exit 1 exit 1
fi fi
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
# Dependencies: # Dependencies:
# - create-snapshot.sh # - create-snapshot.sh
# #
set -o nounset
set -o errexit
BIN_DIR=`dirname "$0"` BIN_DIR=`dirname "$0"`
REPOSITORY=~/screening/snapshots REPOSITORY=~/screening/snapshots
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
# If the p option is specified only artifact file names matching the regular expression will # If the p option is specified only artifact file names matching the regular expression will
# be loaded from Hudson. # be loaded from Hudson.
# #
set -o nounset
set -o errexit
CI_HOST=cisd-ci.ethz.ch:8090 CI_HOST=cisd-ci.ethz.ch:8090
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# Dependencies: # Dependencies:
# - fetch-ci-artifacts.sh # - fetch-ci-artifacts.sh
# #
set -o nounset
set -o errexit
BIN_DIR=`dirname "$0"` BIN_DIR=`dirname "$0"`
SCRIPT="$BIN_DIR/fetch-ci-artifacts.sh" SCRIPT="$BIN_DIR/fetch-ci-artifacts.sh"
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# Dependencies: # Dependencies:
# - fetch-ci-artifacts.sh # - fetch-ci-artifacts.sh
# #
set -o nounset
set -o errexit
BIN_DIR=`dirname "$0"` BIN_DIR=`dirname "$0"`
SCRIPT="$BIN_DIR/fetch-ci-artifacts.sh" SCRIPT="$BIN_DIR/fetch-ci-artifacts.sh"
......
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
# - restore-config-snapshot.sh # - restore-config-snapshot.sh
# - install.sh of the openBIS AS distribution # - install.sh of the openBIS AS distribution
# #
set -o nounset
set -o errexit
if [ $# -le 4 ]; then if [ $# -lt 4 ]; then
echo "Usage: install-servers.sh <servers> <config snapshot repository> <builds fetching script> <config file list 1> ... <config file list n>" echo "Usage: install-servers.sh <servers> <config snapshot repository> <builds fetching script> <config file list 1> ... <config file list n>"
exit 1 exit 1
fi fi
......
...@@ -17,13 +17,16 @@ ...@@ -17,13 +17,16 @@
# - servers-startup-from-latest-snapshot.sh # - servers-startup-from-latest-snapshot.sh
# - config-files.txt # - config-files.txt
# #
set -o nounset
set -o errexit
BIN_DIR=`dirname "$0"` BIN_DIR=`dirname "$0"`
SERVERS=sprint SERVERS=sprint
VERSION_FILE=sprint-versions.txt
echo ":::::::::::::::::::: Nightly Upgrade Generic openBIS Servers [`date`] :::::::::::::::::::::" echo ":::::::::::::::::::: Nightly Upgrade Generic openBIS Servers [`date`] :::::::::::::::::::::"
"$BIN_DIR/check-and-exit-if-new-sprint-server.sh" "$SERVERS" if ! "$BIN_DIR/check-and-exit-if-new-sprint-server.sh" "$SERVERS" "$VERSION_FILE"; then exit; fi
################################################## ##################################################
# #
......
...@@ -18,14 +18,18 @@ ...@@ -18,14 +18,18 @@
# - config-files.txt # - config-files.txt
# - config-files-screening.txt # - config-files-screening.txt
# #
set -o nounset
set -o errexit
BIN_DIR=`dirname "$0"` BIN_DIR=`dirname "$0"`
SERVERS=screening/servers SERVERS=screening/servers
VERSION_FILE=screening/sprint-versions.txt
echo ":::::::::::::::::::: Nightly Upgrade Screening openBIS Servers [`date`] :::::::::::::::::::::" echo ":::::::::::::::::::: Nightly Upgrade Screening openBIS Servers [`date`] :::::::::::::::::::::"
"$BIN_DIR/check-and-exit-if-new-sprint-server.sh" "$SERVERS" if ! "$BIN_DIR/check-and-exit-if-new-sprint-server.sh" "$SERVERS" "$VERSION_FILE"; then exit; fi
echo we exit
exit
################################################## ##################################################
# #
# Upgrade servers and restart them # Upgrade servers and restart them
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
# <servers folder>/datastore_server # <servers folder>/datastore_server
# If one of these folders do not exists shutdown is aborted. # If one of these folders do not exists shutdown is aborted.
# #
set -o nounset
set -o errexit
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then
echo "Usage: servers-shutdown.sh <servers folder>" echo "Usage: servers-shutdown.sh <servers folder>"
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
# Dependencies: # Dependencies:
# - servers-startup-from-snapshot.sh # - servers-startup-from-snapshot.sh
# #
set -o nounset
set -o errexit
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
echo "Usage: servers-startup-from-latest-snapshot.sh <servers> <snapshot repository>" echo "Usage: servers-startup-from-latest-snapshot.sh <servers> <snapshot repository>"
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
# - servers-shutdown.sh # - servers-shutdown.sh
# - servers-startup.sh # - servers-startup.sh
# #
set -o nounset
set -o errexit
function getValue { function getValue {
file=$1 file=$1
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
# <servers folder>/datastore_server # <servers folder>/datastore_server
# If one of these folders do not exists there will be no start up. # If one of these folders do not exists there will be no start up.
# #
set -o nounset
set -o errexit
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then
echo "Usage: servers-startup.sh <servers folder>" echo "Usage: servers-startup.sh <servers folder>"
......
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