Ubuntu 24.04 LTS conformance mods
* docker-compose-v2 compatibility * MySQL/MariaDB dual comaptibility ACME client minor upgrade
This commit is contained in:
parent
47211a6ea8
commit
005d0503e2
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,12 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# Dumps a MySQL database from a native or dockerized MySQL instance running
|
||||
# on this box. This is a wrapper script to the mysqldump tool.
|
||||
# Dumps a MySQL or MariaDB database from a native or dockerized instance running
|
||||
# on this box. This is a wrapper script to the mysqldump or mariadb-dump tool.
|
||||
#
|
||||
# If the MySQL is dockerized you need call as a Docker manager user
|
||||
# If the DB engine is dockerized you need call as a Docker manager user
|
||||
# (member of the docker Linux group).
|
||||
#
|
||||
# Accepts few mysql_dump options as well as the optional database password
|
||||
# Accepts few mysql/mariadb-dump options as well as the optional database password
|
||||
# and the optional output pathname:
|
||||
#
|
||||
# $0 [-u dbuser] [-p dbpass] [-h dbhost] [-P dbport]
|
||||
@ -16,6 +16,9 @@
|
||||
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
||||
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
# 2024-08-24 v1.1
|
||||
# mod: MariaDB and MySQL dual compatibility (native and dockerized).
|
||||
# Tested with Ubuntu 24.04 LTS.
|
||||
# 2023-06-18 v1.0
|
||||
# new: forked from the "SMARTERP_skeleton" repository.
|
||||
# 2023-02-15 v0.3
|
||||
@ -47,7 +50,7 @@ MYOPTIONS=""
|
||||
# Other initialisations.
|
||||
#
|
||||
MYDUMPFORCED="" # Dumps despite failed checks
|
||||
# Our default parameters for the mysqldump.
|
||||
# Our default parameters for the mysql/mariadb-dump
|
||||
# Content of the MYOPTIONS will also appended during the actual dump.
|
||||
dumpparameters="--comments --events --routines --triggers "
|
||||
dumpparameters+="--complete-insert --dump-date --force --no-create-db "
|
||||
@ -127,10 +130,16 @@ done; shift $((OPTIND -1))
|
||||
|
||||
# Checks the dependencies.
|
||||
#
|
||||
# Conditional dependencies (according to native or dockerized environment).
|
||||
[[ -z "$MYCONTAINER" ]] \
|
||||
&& additem="mysql mysqldump" \
|
||||
|| additem="docker"
|
||||
# Conditional dependencies.
|
||||
if [ -n "$MYCONTAINER" ]; then
|
||||
# Dockerized
|
||||
additem="docker"
|
||||
else
|
||||
# Native - MySQL or MariaDB CLI?
|
||||
if [ -n "$(which mysql)" ]
|
||||
then additem="mysql mysqldump"
|
||||
else additem="mariadb mariadb-dump"; fi
|
||||
fi
|
||||
# Common dependencies.
|
||||
TR=$(which tr 2>/dev/null)
|
||||
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
||||
@ -142,6 +151,12 @@ do
|
||||
done
|
||||
# All dependencies are available via "$THECOMMAND" (upper case) call.
|
||||
#
|
||||
# Unifies the call of the clients in a native environment.
|
||||
if [ -z "$MYCONTAINER" ]; then
|
||||
if [ -z "$MYSQL" -a -n "$MARIADB" ]; then MYSQL="$MARIADB"; fi
|
||||
if [ -z "$MYSQLDUMP" -a -n "$MARIADB_DUMP" ]; then MYSQLDUMP="$MARIADB_DUMP"; fi
|
||||
fi
|
||||
#
|
||||
# An additional bugfix (use "$(which gzip)" instead of "$GZIP"):
|
||||
# https://www.gnu.org/software/gzip/manual/html_node/Environment.html
|
||||
GZIP=""
|
||||
@ -205,10 +220,20 @@ my_connect=""
|
||||
|
||||
# Checks credentials and existence of the database given.
|
||||
#
|
||||
[[ -n "$MYCONTAINER" ]] \
|
||||
&& databases=$("$DOCKER" exec $MYCONTAINER sh -c "mysql -N --batch $my_connect --execute='show databases;'" 2>/dev/null) \
|
||||
|| databases=$("$MYSQL" -N --batch $my_connect --execute='show databases;' 2>/dev/null )
|
||||
# Credentials?
|
||||
if [ -z "$MYCONTAINER" ]; then
|
||||
databases=$("$MYSQL" -N --batch $my_connect --execute='show databases;' 2>/dev/null )
|
||||
else
|
||||
# In a containerized environment we've to find out which CLIs are inside.
|
||||
# Try the mysql first:
|
||||
MYSQL="mysql"; MYSQLDUMP="mysqldump"
|
||||
databases=$("$DOCKER" exec $MYCONTAINER sh -c "$MYSQL -N --batch $my_connect --execute='show databases;'" 2>/dev/null)
|
||||
# On failure try the mariadb:
|
||||
if [ -z "$databases" ]; then
|
||||
MYSQL="mariadb"; MYSQLDUMP="mariadb-dump"
|
||||
databases=$("$DOCKER" exec $MYCONTAINER sh -c "$MYSQL -N --batch $my_connect --execute='show databases;'" 2>/dev/null)
|
||||
fi
|
||||
fi
|
||||
# CLI and Credentials are OK?
|
||||
[[ -z "$databases" ]] \
|
||||
&& echo "$MSG_BADCRED ($MYUSER@$([[ -n "$MYCONTAINER" ]] && echo "$MYCONTAINER:")$MYHOST)." >&2 && exit 1
|
||||
# Existence?
|
||||
@ -228,7 +253,7 @@ if [ -n "$MYDUMP" ]; then
|
||||
SQLVERB+="GROUP BY table_schema;"
|
||||
if [ -n "$MYCONTAINER" ]; then
|
||||
# Dockerized database.
|
||||
dbsize=$("$DOCKER" exec $MYCONTAINER sh -c "echo \"$SQLVERB\" | mysql -N --batch $my_connect" 2>/dev/null | \
|
||||
dbsize=$("$DOCKER" exec $MYCONTAINER sh -c "echo \"$SQLVERB\" | "$MYSQL" -N --batch $my_connect" 2>/dev/null | \
|
||||
"$CUT" -d$'\t' -f2)
|
||||
else
|
||||
# Self-hosted database.
|
||||
@ -281,7 +306,7 @@ if [ -n "$MYDUMP" ]; then
|
||||
# Dumps into a file (then optionally compresses). Writes a separate log too.
|
||||
# TODO: pipelined compress - doesn't work with Docker yet(?).
|
||||
[[ -n "$MYCONTAINER" ]] \
|
||||
&& "$DOCKER" exec $MYCONTAINER sh -c "mysqldump $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
|
||||
&& "$DOCKER" exec $MYCONTAINER sh -c "$MYSQLDUMP $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
|
||||
>"$MYDUMP" 2>>"$logfile" \
|
||||
|| "$MYSQLDUMP" $my_connect $dumpparameters $MYOPTIONS $MYDATABASE \
|
||||
>"$MYDUMP" 2>>"$logfile"
|
||||
@ -290,7 +315,7 @@ if [ -n "$MYDUMP" ]; then
|
||||
else
|
||||
# Dumps to STDOUT without logging.
|
||||
[[ -n "$MYCONTAINER" ]] \
|
||||
&& "$DOCKER" exec $MYCONTAINER sh -c "mysqldump $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
|
||||
&& "$DOCKER" exec $MYCONTAINER sh -c "$MYSQLDUMP $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
|
||||
2>/dev/null \
|
||||
|| "$MYSQLDUMP" $my_connect $dumpparameters $MYOPTIONS $MYDATABASE \
|
||||
2>>/dev/null
|
||||
|
24
tools/build
24
tools/build
@ -8,6 +8,8 @@
|
||||
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
||||
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
# 2024-08-24 v1.1
|
||||
# new: docker-compose v2 compatibility - tested with Ubuntu 24.04 LTS.
|
||||
# 2023-06-18 v1.0
|
||||
# new: forked from the "Smartfront's DOCKER_skeleton" repository.
|
||||
# 2021-10-03 v0.2
|
||||
@ -28,12 +30,28 @@ MSG_MISSINGYML="Fatal: didn't find the docker-compose.yml file"
|
||||
# Checks the dependencies.
|
||||
TR=$(which tr 2>/dev/null)
|
||||
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
||||
for item in dirname docker-compose readlink
|
||||
for item in dirname docker readlink
|
||||
do
|
||||
if [ -n "$(which $item)" ]
|
||||
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]' | "$TR" '-' '_')=$(which $item)
|
||||
else echo "$MSG_MISSINGDEP $item." >&2; exit 1; fi
|
||||
done
|
||||
#
|
||||
# Let's find which version of docker-compose is installed.
|
||||
commandstring=""
|
||||
if [ $($DOCKER compose version 2>&1 >/dev/null; echo $?) -eq 0 ]; then
|
||||
# We'll use v2 if it is available.
|
||||
DOCKER_COMPOSE="$DOCKER"
|
||||
commandstring="compose"
|
||||
else
|
||||
# Otherwise falling back to v1.
|
||||
DOCKER_COMPOSE="$(which docker-compose)"
|
||||
commandstring=""
|
||||
fi
|
||||
# One of the two is mandatory.
|
||||
if [ -z "$DOCKER_COMPOSE" ];then echo "$MSG_MISSINGDEP docker-compose" >&2; exit 1; fi
|
||||
# All dependencies are available via "$THECOMMAND" (upper case) call.
|
||||
# In addition "docker-compose" should be called as "$DOCKER_COMPOSE" $commandstring.
|
||||
|
||||
# Where I'm?
|
||||
# https://gist.github.com/TheMengzor/968e5ea87e99d9c41782
|
||||
@ -64,10 +82,10 @@ if [ -z "$BASE_DIR" -o ! -r "$BASE_DIR/$YMLFILE" ]; then
|
||||
fi
|
||||
|
||||
# Doesn't attempts to build if the service is running.
|
||||
if [ -n "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" ps --services --filter "status=running")" ]; then
|
||||
if [ -n "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring ps --services --filter "status=running")" ]; then
|
||||
echo "$MSG_ALREADYRUN" >&2; exit 1
|
||||
fi
|
||||
# Pulls the components and builds the service (if necessary).
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" rm -f; "$DOCKER_COMPOSE" pull; "$DOCKER_COMPOSE" build)
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring rm -f; "$DOCKER_COMPOSE" $commandstring pull; "$DOCKER_COMPOSE" $commandstring build)
|
||||
|
||||
# That's all, Folks!
|
||||
|
@ -10,6 +10,8 @@
|
||||
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
||||
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
# 2024-08-24 v1.1
|
||||
# new: docker-compose v2 compatibility - tested with Ubuntu 24.04 LTS.
|
||||
# 2023-06-18 v1.0
|
||||
# new: forked from the "Smartfront's DOCKER_skeleton" repository.
|
||||
# 2021-09-14 v0.2
|
||||
@ -39,13 +41,27 @@ PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin"; fi
|
||||
# Checks the dependencies.
|
||||
TR=$(which tr 2>/dev/null)
|
||||
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
||||
for item in basename date dirname docker-compose logrotate readlink
|
||||
for item in basename date dirname docker logrotate readlink
|
||||
do
|
||||
if [ -n "$(which $item)" ]
|
||||
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]' | "$TR" '-' '_')=$(which $item)
|
||||
else echo "$MSG_MISSINGDEP $item." >&2; exit 1; fi
|
||||
done
|
||||
# All dependencies are available via "$THECOMMAND" (upper case) call.
|
||||
#
|
||||
# Let's find which version of docker-compose is installed.
|
||||
if [ $($DOCKER compose version 2>&1 >/dev/null; echo $?) -eq 0 ]; then
|
||||
# We'll use v2 if it is available.
|
||||
DOCKER_COMPOSE="$DOCKER"
|
||||
commandstring="compose"
|
||||
else
|
||||
# Otherwise falling back to v1.
|
||||
DOCKER_COMPOSE="$(which docker-compose)"
|
||||
commandstring=""
|
||||
fi
|
||||
# One of the two is mandatory.
|
||||
if [ -z "$DOCKER_COMPOSE" ];then echo "$MSG_MISSINGDEP docker-compose" >&2; exit 1; fi
|
||||
# Below docker-compose should be called as "$DOCKER_COMPOSE" $commandstring sequence.
|
||||
|
||||
# Where I'm?
|
||||
# https://gist.github.com/TheMengzor/968e5ea87e99d9c41782
|
||||
@ -83,7 +99,7 @@ STATEFILE="$CONFDIR/.${SCRFILE%.*}.state"
|
||||
LOGDIR="${PAR_LOGDIR:-$BASE_DIR/$LOGDIR}"
|
||||
|
||||
# Doesn't rotate logs for stopped services.
|
||||
[[ -z "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" ps --services --filter "status=running")" ]] \
|
||||
[[ -z "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring ps --services --filter "status=running")" ]] \
|
||||
&& exit 0
|
||||
|
||||
# Locates the worker script.
|
||||
|
@ -7,6 +7,10 @@
|
||||
#
|
||||
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
# 2024-08-24 v1.1
|
||||
# new: docker-compose v2 compatibility - tested with Ubuntu 24.04 LTS.
|
||||
# 2023-06-18 v1.0
|
||||
# new: forked from the "Smartfront's DOCKER_skeleton" repository.
|
||||
# 2021-09-02 v0.1 Initial release
|
||||
|
||||
# Accepted environment variables and their defaults.
|
||||
@ -23,12 +27,27 @@ MSG_MISSINGYML="Fatal: didn't find the docker-compose.yml file"
|
||||
# Checks the dependencies.
|
||||
TR=$(which tr 2>/dev/null)
|
||||
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
||||
for item in dirname docker-compose readlink
|
||||
for item in dirname docker readlink
|
||||
do
|
||||
if [ -n "$(which $item)" ]
|
||||
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]' | "$TR" '-' '_')=$(which $item)
|
||||
else echo "$MSG_MISSINGDEP $item." >&2; exit 1; fi
|
||||
done
|
||||
# All dependencies are available via "$THECOMMAND" (upper case) call.
|
||||
#
|
||||
# Let's find which version of docker-compose is installed.
|
||||
if [ $($DOCKER compose version 2>&1 >/dev/null; echo $?) -eq 0 ]; then
|
||||
# We'll use v2 if it is available.
|
||||
DOCKER_COMPOSE="$DOCKER"
|
||||
commandstring="compose"
|
||||
else
|
||||
# Otherwise falling back to v1.
|
||||
DOCKER_COMPOSE="$(which docker-compose)"
|
||||
commandstring=""
|
||||
fi
|
||||
# One of the two is mandatory.
|
||||
if [ -z "$DOCKER_COMPOSE" ];then echo "$MSG_MISSINGDEP docker-compose" >&2; exit 1; fi
|
||||
# Below docker-compose should be called as "$DOCKER_COMPOSE" $commandstring sequence.
|
||||
|
||||
# Where I'm?
|
||||
# https://gist.github.com/TheMengzor/968e5ea87e99d9c41782
|
||||
@ -59,10 +78,10 @@ if [ -z "$BASE_DIR" -o ! -r "$BASE_DIR/$YMLFILE" ]; then
|
||||
fi
|
||||
|
||||
# Doesn't stop if it isn't running.
|
||||
if [ -z "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" ps --services --filter "status=running")" ]; then
|
||||
if [ -z "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring ps --services --filter "status=running")" ]; then
|
||||
echo "$MSG_DOESNOTRUN" >&2; exit 1
|
||||
fi
|
||||
# Stops the service.
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" down)
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring down)
|
||||
|
||||
# That's all, Folks!
|
||||
|
@ -8,6 +8,10 @@
|
||||
#
|
||||
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
||||
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
# 2024-08-24 v1.1
|
||||
# new: docker-compose v2 compatibility - tested with Ubuntu 24.04 LTS.
|
||||
# 2023-06-18 v1.0
|
||||
# new: forked from the "Smartfront's DOCKER_skeleton" repository.
|
||||
# 2021-09-02 v0.1 Initial release
|
||||
|
||||
# Accepted environment variables and their defaults.
|
||||
@ -27,12 +31,27 @@ MSG_MISSINGYML="Fatal: didn't find the docker-compose.yml file"
|
||||
# Checks the dependencies.
|
||||
TR=$(which tr 2>/dev/null)
|
||||
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
|
||||
for item in dirname docker-compose readlink
|
||||
for item in dirname docker readlink
|
||||
do
|
||||
if [ -n "$(which $item)" ]
|
||||
then export $(echo $item | "$TR" '[:lower:]' '[:upper:]' | "$TR" '-' '_')=$(which $item)
|
||||
else echo "$MSG_MISSINGDEP $item." >&2; exit 1; fi
|
||||
done
|
||||
# All dependencies are available via "$THECOMMAND" (upper case) call.
|
||||
#
|
||||
# Let's find which version of docker-compose is installed.
|
||||
if [ $($DOCKER compose version 2>&1 >/dev/null; echo $?) -eq 0 ]; then
|
||||
# We'll use v2 if it is available.
|
||||
DOCKER_COMPOSE="$DOCKER"
|
||||
commandstring="compose"
|
||||
else
|
||||
# Otherwise falling back to v1.
|
||||
DOCKER_COMPOSE="$(which docker-compose)"
|
||||
commandstring=""
|
||||
fi
|
||||
# One of the two is mandatory.
|
||||
if [ -z "$DOCKER_COMPOSE" ];then echo "$MSG_MISSINGDEP docker-compose" >&2; exit 1; fi
|
||||
# Below docker-compose should be called as "$DOCKER_COMPOSE" $commandstring sequence.
|
||||
|
||||
# Where I'm?
|
||||
# https://gist.github.com/TheMengzor/968e5ea87e99d9c41782
|
||||
@ -63,24 +82,24 @@ if [ -z "$BASE_DIR" -o ! -r "$BASE_DIR/$YMLFILE" ]; then
|
||||
fi
|
||||
|
||||
# Doesn't start if it is already running.
|
||||
if [ -n "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" ps --services --filter "status=running")" ]; then
|
||||
if [ -n "$(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring ps --services --filter "status=running")" ]; then
|
||||
echo "$MSG_ALREADYRUN" >&2; exit 1
|
||||
fi
|
||||
# Starts the service.
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" up -d)
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring up -d)
|
||||
|
||||
|
||||
# Starts the logger - this/these process(es) will automatically terminate
|
||||
# when the docker-compose stops.
|
||||
if [ -n "$PAR_AGGLOGS" ]; then
|
||||
# Aggregated logs
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" logs --no-color -t -f >> "$BASE_DIR/$LOGFILE" &)
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring logs --no-color -t -f >> "$BASE_DIR/$LOGFILE" &)
|
||||
else
|
||||
# Separate logs, each for every running service.
|
||||
for service in $(cd "$BASE_DIR"; "$DOCKER_COMPOSE" ps --services) ""
|
||||
for service in $(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring ps --services) ""
|
||||
do
|
||||
if [ -n "$service" ]; then
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" logs --no-color -t -f $service >> "$BASE_DIR/$LOGDIR/$service.log" &)
|
||||
(cd "$BASE_DIR"; "$DOCKER_COMPOSE" $commandstring logs --no-color -t -f $service >> "$BASE_DIR/$LOGDIR/$service.log" &)
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user