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