Merge pull request #4916 from scholtalbers/add_maintenance_script

Add maintenance script..
This commit is contained in:
Marius van den Beek
2018-01-19 12:26:42 +01:00
committed by GitHub
2 changed files with 129 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# This file is sourced in the maintenance.sh script and could be sourced in ./run.sh or ./run_reports.sh
SCRIPTLOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# If there is a file that defines a shell environment specific to this
# instance of Galaxy, source the file.
if [ -z $GALAXY_LOCAL_ENV_FILE ];
then
GALAXY_LOCAL_ENV_FILE="$SCRIPTLOCATION/../config/local_env.sh"
fi
if [ -f $GALAXY_LOCAL_ENV_FILE ];
then
echo "Activating local env file: $GALAXY_LOCAL_ENV_FILE"
. $GALAXY_LOCAL_ENV_FILE
fi
# If there is a .venv/ directory, assume it contains a virtualenv that we
# should run this instance in.
GALAXY_VIRTUAL_ENV="${GALAXY_VIRTUAL_ENV:-$SCRIPTLOCATION/../.venv}"
if [ -d "$GALAXY_VIRTUAL_ENV" -a -z "$skip_venv" ];
then
[ -n "$PYTHONPATH" ] && { echo 'Unsetting $PYTHONPATH'; unset PYTHONPATH; }
echo "Activating virtualenv at $GALAXY_VIRTUAL_ENV"
. "$GALAXY_VIRTUAL_ENV/bin/activate"
fi
if [ -z "$GALAXY_CONFIG_FILE" ]; then
if [ -f "$SCRIPTLOCATION/../universe_wsgi.ini" ]; then
GALAXY_CONFIG_FILE=universe_wsgi.ini
elif [ -f "$SCRIPTLOCATION/../config/galaxy.ini" ]; then
GALAXY_CONFIG_FILE=config/galaxy.ini
else
GALAXY_CONFIG_FILE=config/galaxy.ini.sample
fi
export GALAXY_CONFIG_FILE
fi
echo "GALAXY_CONFIG_FILE: ${GALAXY_CONFIG_FILE}"
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
# Configure this script in a cron job to run some common cleanup operations
# Set the Environment variable GALAXY_CONFIG_FILE to use a custom galaxy config file.
set -e
display_help(){
scriptname=`basename $0`
printf "./$scriptname [--help] [--no-dry-run] [--days 10]
Will run the galaxy cleanup scripts in the recommend order. By default a 'dry-run' is started. Specify --no-dry-run to do the actual cleanup.
--help Show this help
--dry-run|--no-dry-run Dry run(default), will only print out what the scripts would have done. Specify --no-dry-run to do the actual cleanup.
--days Number of days to use as a cut off; do not act on objects updated more recently than this
"
}
# number of days to use as a cut off; do not act on objects updated more recently than this
DAYS=10
DRYRUN=true
while :
do
case "$1" in
--no-dry-run)
DRYRUN=false
shift
;;
--dry-run ) # default
DRYRUN=true
shift
;;
--days )
DAYS="$2"
shift; shift
;;
-h )
display_help
exit 1
;;
--help )
display_help
exit 1
;;
"")
break
;;
*)
shift
;;
esac
done
SCRIPTLOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${SCRIPTLOCATION}/common_startup_variables.sh
if [ "$DRYRUN" = true ]; then
MODE="--info_only"
else
MODE="-r"
fi
MAINTENANCE_LOG="$SCRIPTLOCATION/../maintenance.log"
COMMANDS=(
"python $SCRIPTLOCATION/cleanup_datasets/cleanup_datasets.py $GALAXY_CONFIG_FILE -d $DAYS $MODE --delete_userless_histories >> $MAINTENANCE_LOG"
"python $SCRIPTLOCATION/cleanup_datasets/cleanup_datasets.py $GALAXY_CONFIG_FILE -d $DAYS $MODE --purge_histories >> $MAINTENANCE_LOG"
"python $SCRIPTLOCATION/cleanup_datasets/cleanup_datasets.py $GALAXY_CONFIG_FILE -d $DAYS $MODE --purge_datasets >> $MAINTENANCE_LOG"
"python $SCRIPTLOCATION/cleanup_datasets/cleanup_datasets.py $GALAXY_CONFIG_FILE -d $DAYS $MODE --purge_folders >> $MAINTENANCE_LOG"
"python $SCRIPTLOCATION/cleanup_datasets/cleanup_datasets.py $GALAXY_CONFIG_FILE -d $DAYS $MODE --delete_datasets >> $MAINTENANCE_LOG"
"python $SCRIPTLOCATION/cleanup_datasets/cleanup_datasets.py $GALAXY_CONFIG_FILE -d $DAYS $MODE --purge_datasets >> $MAINTENANCE_LOG")
printf "\nDry run: $DRYRUN\nDays: $DAYS\n\n"
echo "Will run following commands and output in $MAINTENANCE_LOG"
for (( i = 0; i < ${#COMMANDS[@]} ; i++ )); do
echo "${COMMANDS[$i]}"
done
if [ "$DRYRUN" = false ]; then
echo "python $SCRIPTLOCATION/set_user_disk_usage.py >> $MAINTENANCE_LOG"
fi
# Run the commands
cd $SCRIPTLOCATION/../
for (( i = 0; i < ${#COMMANDS[@]} ; i++ )); do
eval "${COMMANDS[$i]}"
done
if [ "$DRYRUN" = false ]; then
python $SCRIPTLOCATION/set_user_disk_usage.py >> $MAINTENANCE_LOG
fi