refactor(compose): detect proper compose cmd
This commit is contained in:
parent
818483f92e
commit
475a0d0dd2
@ -9,6 +9,14 @@
|
|||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="GitSharedSettings">
|
||||||
|
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
||||||
|
<list>
|
||||||
|
<option value="master" />
|
||||||
|
<option value="main" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
|
@ -195,6 +195,7 @@ mcDockerCompose='/opt/mailcow-dockerized/docker-compose.yml'
|
|||||||
sqlRunning=0
|
sqlRunning=0
|
||||||
dockerStartTimeout=180
|
dockerStartTimeout=180
|
||||||
dockerStopTimeout=120
|
dockerStopTimeout=120
|
||||||
|
dockerCmd="docker compose"
|
||||||
|
|
||||||
### check if user is root
|
### check if user is root
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
@ -309,6 +310,14 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|||||||
if ! command -v docker >/dev/null; then
|
if ! command -v docker >/dev/null; then
|
||||||
consoleError '3' 'docker does not seem to be installed!'
|
consoleError '3' 'docker does not seem to be installed!'
|
||||||
fi
|
fi
|
||||||
|
# verify compose installed and set proper commands based on version
|
||||||
|
if ! (docker compose version >/dev/null 2>&1); then
|
||||||
|
if ! (docker-compose --version >/dev/null 2>&1); then
|
||||||
|
printf "\n%sERROR: Docker Compose not installed or not functioning%s\n\n" "$err" "$norm"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
dockerCmd="docker-compose"
|
||||||
|
fi
|
||||||
# mailcow.conf?
|
# mailcow.conf?
|
||||||
if [ ! -f "$mcConfig" ]; then
|
if [ ! -f "$mcConfig" ]; then
|
||||||
consoleError '1' "mailcow configuration file ($mcConfig) cannot be found."
|
consoleError '1' "mailcow configuration file ($mcConfig) cannot be found."
|
||||||
@ -384,7 +393,7 @@ if [ "$restoreSQL" -eq 1 ]; then
|
|||||||
if [ -n "$sqlBackup" ]; then
|
if [ -n "$sqlBackup" ]; then
|
||||||
# start mysql container if not already running
|
# start mysql container if not already running
|
||||||
if ! docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then
|
if ! docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then
|
||||||
docker-compose up -d mysql-mailcow > /dev/null 2>&1
|
"${dockerCmd}" up -d mysql-mailcow >/dev/null 2>&1
|
||||||
if docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then
|
if docker container inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_mysql-mailcow_1 >/dev/null 2>&1; then
|
||||||
sqlRunning=1
|
sqlRunning=1
|
||||||
else
|
else
|
||||||
@ -403,7 +412,7 @@ if [ "$restoreSQL" -eq 1 ]; then
|
|||||||
|
|
||||||
# restore sql
|
# restore sql
|
||||||
if [ "$sqlRunning" -eq 1 ]; then
|
if [ "$sqlRunning" -eq 1 ]; then
|
||||||
if docker exec -i "$(docker-compose ps -q mysql-mailcow)" mysql -u${DBUSER} -p${DBPASS} ${DBNAME} < "${sqlBackup}" > /dev/null 2>&1; then
|
if docker exec -i "$("${dockerCmd}" ps -q mysql-mailcow)" mysql -u${DBUSER} -p${DBPASS} ${DBNAME} <"${sqlBackup}" >/dev/null 2>&1; then
|
||||||
writeLog 'done'
|
writeLog 'done'
|
||||||
else
|
else
|
||||||
writeLog 'done' 'error'
|
writeLog 'done' 'error'
|
||||||
@ -415,7 +424,7 @@ fi
|
|||||||
|
|
||||||
### stop containers (necessary for all restore operations except SQL)
|
### stop containers (necessary for all restore operations except SQL)
|
||||||
writeLog 'task' "Stopping mailcow"
|
writeLog 'task' "Stopping mailcow"
|
||||||
if ! docker-compose down --timeout "${dockerStopTimeout}" > /dev/null 2>&1; then
|
if ! "${dockerCmd}" down --timeout "${dockerStopTimeout}" >/dev/null 2>&1; then
|
||||||
writeLog 'done' 'error'
|
writeLog 'done' 'error'
|
||||||
writeLog 'error' '20' "Unable to bring mailcow containers down -- cannot reliably restore. Aborting."
|
writeLog 'error' '20' "Unable to bring mailcow containers down -- cannot reliably restore. Aborting."
|
||||||
exitError 20
|
exitError 20
|
||||||
@ -436,7 +445,8 @@ if [ "$restoreMail" -eq 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# restore email messages
|
# restore email messages
|
||||||
doRestore "${COMPOSE_PROJECT_NAME}_vmail-vol-1" "$dockerVolumeMail"; ec="$?"
|
doRestore "${COMPOSE_PROJECT_NAME}_vmail-vol-1" "$dockerVolumeMail"
|
||||||
|
ec="$?"
|
||||||
case "$ec" in
|
case "$ec" in
|
||||||
0)
|
0)
|
||||||
if [ "$verbose" -eq 1 ]; then
|
if [ "$verbose" -eq 1 ]; then
|
||||||
@ -464,7 +474,8 @@ if [ "$restoreMail" -eq 1 ]; then
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# restore encryption key
|
# restore encryption key
|
||||||
doRestore "${COMPOSE_PROJECT_NAME}_crypt-vol-1" "$dockerVolumeCrypt"; ec="$?"
|
doRestore "${COMPOSE_PROJECT_NAME}_crypt-vol-1" "$dockerVolumeCrypt"
|
||||||
|
ec="$?"
|
||||||
case "$ec" in
|
case "$ec" in
|
||||||
0)
|
0)
|
||||||
if [ "$verbose" -eq 1 ]; then
|
if [ "$verbose" -eq 1 ]; then
|
||||||
@ -500,7 +511,8 @@ if [ "$restorePostfix" -eq 1 ]; then
|
|||||||
writeLog 'task' "Restoring postfix files"
|
writeLog 'task' "Restoring postfix files"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
doRestore "${COMPOSE_PROJECT_NAME}_postfix-vol-1" "$dockerVolumePostfix"; ec="$?"
|
doRestore "${COMPOSE_PROJECT_NAME}_postfix-vol-1" "$dockerVolumePostfix"
|
||||||
|
ec="$?"
|
||||||
case "$ec" in
|
case "$ec" in
|
||||||
0)
|
0)
|
||||||
if [ "$verbose" -eq 1 ]; then
|
if [ "$verbose" -eq 1 ]; then
|
||||||
@ -536,7 +548,8 @@ if [ "$restoreRspamd" -eq 1 ]; then
|
|||||||
writeLog 'task' "Restoring Rspamd files"
|
writeLog 'task' "Restoring Rspamd files"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
doRestore "${COMPOSE_PROJECT_NAME}_rspamd-vol-1" "$dockerVolumeRspamd"; ec="$?"
|
doRestore "${COMPOSE_PROJECT_NAME}_rspamd-vol-1" "$dockerVolumeRspamd"
|
||||||
|
ec="$?"
|
||||||
case "$ec" in
|
case "$ec" in
|
||||||
0)
|
0)
|
||||||
if [ "$verbose" -eq 1 ]; then
|
if [ "$verbose" -eq 1 ]; then
|
||||||
@ -572,7 +585,8 @@ if [ "$restoreRedis" -eq 1 ]; then
|
|||||||
writeLog 'task' "Restoring redis database"
|
writeLog 'task' "Restoring redis database"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
doRestore "${COMPOSE_PROJECT_NAME}_redis-vol-1" "$dockerVolumeRedis"; ec="$?"
|
doRestore "${COMPOSE_PROJECT_NAME}_redis-vol-1" "$dockerVolumeRedis"
|
||||||
|
ec="$?"
|
||||||
case "$ec" in
|
case "$ec" in
|
||||||
0)
|
0)
|
||||||
if [ "$verbose" -eq 1 ]; then
|
if [ "$verbose" -eq 1 ]; then
|
||||||
@ -602,7 +616,7 @@ fi
|
|||||||
|
|
||||||
### restart mailcow
|
### restart mailcow
|
||||||
writeLog 'task' "Starting mailcow"
|
writeLog 'task' "Starting mailcow"
|
||||||
if ! docker-compose up -d > /dev/null 2>&1; then
|
if ! "${dockerCmd}" up -d >/dev/null 2>&1; then
|
||||||
writeLog 'done' 'warn'
|
writeLog 'done' 'warn'
|
||||||
writeLog 'warn' '21' "Unable to automatically start mailcow containers. Please attempt a manual start and note any errors."
|
writeLog 'warn' '21' "Unable to automatically start mailcow containers. Please attempt a manual start and note any errors."
|
||||||
warnCount=$((warnCount + 1))
|
warnCount=$((warnCount + 1))
|
||||||
|
Loading…
Reference in New Issue
Block a user