Automatically run the prep, maintenance, and purge scripts. begin adding explicit double quotes.
This commit is contained in:
@@ -16,7 +16,7 @@ function usage() {
|
||||
# 1) The exit code used when leaving.
|
||||
exit_code=$1
|
||||
echo ""
|
||||
echo -n "Usage: $PROG [-A ( -u | -d | -b | -p | -c | -s )] " 1>&2
|
||||
echo -n "Usage: $PROG [-A ( -u | -d | -b | -p | -c | -m | -s )] " 1>&2
|
||||
echo "[-i CONTAINER] [-l CONTAINER] [-h]" 1>&2
|
||||
cat <<- EOF
|
||||
|
||||
@@ -26,7 +26,7 @@ function usage() {
|
||||
Parameters - Standalone:
|
||||
|
||||
(ALL)
|
||||
-A : Equivalent of specifying '-udbpcs' for a full upgrade service.
|
||||
-A : Equivalent of specifying '-udbpcms' for a full upgrade service.
|
||||
|
||||
(UP)
|
||||
-u : Start all containers with 'up -d'.
|
||||
@@ -43,6 +43,9 @@ function usage() {
|
||||
(CLEAN)
|
||||
-c : Remove any abandoned Docker objects using the 'prune' commands.
|
||||
|
||||
(MAINTENANCE)
|
||||
-m : Run any maintenance and/or purge scripts for each subproject.
|
||||
|
||||
(STATS)
|
||||
-s : Tune in to the 'stats' of how each container is running.
|
||||
|
||||
@@ -86,7 +89,7 @@ function check_container() {
|
||||
|
||||
## Parameters ##
|
||||
|
||||
while getopts ':Audbpcsi:l:h' opt; do
|
||||
while getopts ':Audbpcsi:l:mh' opt; do
|
||||
case $opt in
|
||||
A) all="Y" ;;
|
||||
u) up="Y" ;;
|
||||
@@ -97,30 +100,31 @@ while getopts ':Audbpcsi:l:h' opt; do
|
||||
s) stats="Y" ;;
|
||||
i) interact="$OPTARG" ;;
|
||||
l) logs="$OPTARG" ;;
|
||||
m) maintenance="Y" ;;
|
||||
h) usage 0 ;;
|
||||
*) echo "ERROR: Parameter '$OPTARG' not recognized." 1>&2 && usage 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is done outside the getopts for readability.
|
||||
if [[ -n $all ]]; then
|
||||
up="Y"; down="Y"; build="Y"; pull="Y"; clean="Y"; stats="Y"
|
||||
if [[ -n "$all" && "$all" == "Y" ]]; then
|
||||
up="Y"; down="Y"; build="Y"; pull="Y"; clean="Y"; stats="Y"; maintenance="Y"
|
||||
fi
|
||||
|
||||
## Validations ##
|
||||
|
||||
# Script will behave poorly if not run with admin privileges.
|
||||
if [[ $LOGNAME != "root" ]]; then
|
||||
if [[ "$LOGNAME" != "root" ]]; then
|
||||
echo "*************************************************************"
|
||||
echo "WARNING: Script is intended for root. Please su or sudo/doas."
|
||||
echo "*************************************************************"
|
||||
fi
|
||||
|
||||
# Options which only work if the container exists or is going to be started.
|
||||
if [[ -n $interact ]]; then
|
||||
if [[ -n "$interact" ]]; then
|
||||
check_container $interact interaction
|
||||
fi
|
||||
if [[ -n $logs ]]; then
|
||||
if [[ -n "$logs" ]]; then
|
||||
check_container $logs logs
|
||||
fi
|
||||
|
||||
@@ -128,14 +132,14 @@ fi
|
||||
|
||||
# If no parameters are passed, list all the containers which are running.
|
||||
if [[ -z $up && -z $down && -z $build && -z $pull && -z $clean
|
||||
&& -z $interact && -z $logs && -z $stats
|
||||
&& -z $interact && -z $logs && -z $stats && -z $maintenance
|
||||
]]; then
|
||||
docker ps --size
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Otherwise, loop through all the subproject configurations.
|
||||
if [[ -n $up || -n $down || -n $build || -n $pull ]]; then
|
||||
if [[ -n $up || -n $down || -n $build || -n $pull || -n $maintenance ]]; then
|
||||
cd $DOCKER_HOME/Config
|
||||
for dir in `ls`; do
|
||||
# If this is a directory, enter it, otherwise skip to the next listing.
|
||||
@@ -143,10 +147,10 @@ if [[ -n $up || -n $down || -n $build || -n $pull ]]; then
|
||||
echo ""
|
||||
pwd
|
||||
|
||||
# Ensure .env files exist so that all compose variables are populated.
|
||||
if [[ -e ./env.standard && ! -e ./.env ]]; then
|
||||
echo "WARNING: .env file was not found, copying standard as placeholder."
|
||||
cp -v env.standard .env
|
||||
# Ensure env file exists so that all compose variables are populated.
|
||||
if [[ -e ./example.env && ! -e ./.env ]]; then
|
||||
echo "WARNING: .env file was not found, copying example as placeholder."
|
||||
cp -v example.env .env
|
||||
fi
|
||||
|
||||
# Ensure all configuration files have been created.
|
||||
@@ -160,6 +164,21 @@ if [[ -n $up || -n $down || -n $build || -n $pull ]]; then
|
||||
done
|
||||
fi
|
||||
|
||||
# Run the prep script to create any necessary volumes.
|
||||
if [[ -f prep.sh ]]; then
|
||||
./prep.sh
|
||||
fi
|
||||
|
||||
# Run any maintenance scripts associate with the container.
|
||||
if [[ "$maintenance" == "Y" ]]; then
|
||||
if [[ -f "maintenance.sh" ]]; then
|
||||
./maintenance.sh
|
||||
fi
|
||||
if [[ -f "purge.sh" ]]; then
|
||||
./purge.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
# Shut off container.
|
||||
if [[ $down == "Y" ]]; then
|
||||
[ -e docker-compose.yml ] && docker compose down
|
||||
@@ -200,6 +219,9 @@ if [[ -n $clean ]]; then
|
||||
docker network prune
|
||||
docker builder prune -a
|
||||
docker system df
|
||||
echo "Syncing."
|
||||
sync
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
# Follow the logs of a container.
|
||||
|
||||
Reference in New Issue
Block a user