Skip to content

Commit

Permalink
Add option to force recreate containers on autostart.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcflachs committed Sep 30, 2023
1 parent d94e67d commit 2a2849f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
13 changes: 13 additions & 0 deletions source/compose.manager/compose.manager.settings.page
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ _(Debug Logging)_:
Enable debug logging.
</blockquote>

_(Recreate During Autostart)_:
: <select name="AUTOSTART_FORCE_RECREATE">
<?=mk_option($cfg['AUTOSTART_FORCE_RECREATE'], "false", _("Disabled"))?>
<?=mk_option($cfg['AUTOSTART_FORCE_RECREATE'], "true", _("Enabled"))?>
</select>

<blockquote class="inline_help" style="display: none;">
Use the --force-recreate option when autostarting stacks.<br>
This will recreate each stack container on startup.<br>
This can work around an issue where containers refuse to autostart because the
network they are attached to no longer exists.
</blockquote>

_(Patch unRAID WebUI)_:
: <select name="PATCH_UI">
<?=mk_option($cfg['PATCH_UI'], "false", _("No"))?>
Expand Down
3 changes: 2 additions & 1 deletion source/compose.manager/default.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OUTPUTSTYLE="ttyd"
PATCH_UI="false"
DEBUG_TO_LOG="false"
PROJECTS_FOLDER="/boot/config/plugins/compose.manager/projects"
PROJECTS_FOLDER="/boot/config/plugins/compose.manager/projects"
AUTOSTART_FORCE_RECREATE="false"
14 changes: 12 additions & 2 deletions source/compose.manager/event/started
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ sanitize() {
echo "${s,,}" # convert to lowercase
}

recreate=""
if [ "$AUTOSTART_FORCE_RECREATE" = "true" ]; then
recreate="--recreate"
fi

debug=""
if [ "$DEBUG_TO_LOG" = "true" ]; then
debug="--debug"
fi

for dir in $COMPOSE_ROOT/*; do
if [ -d "$dir" ]; then
if [ -f "$dir/docker-compose.yml" ] || [ -f "$dir/indirect" ]; then
Expand All @@ -32,10 +42,10 @@ for dir in $COMPOSE_ROOT/*; do
if [ -f "$dir/indirect" ]; then
indirect=${dir}/indirect
indirect=$(< "${indirect}")
eval $COMPOSE_WRAPPER -c up -d ${indirect@Q} -p ${name} $override > /dev/null &
eval $COMPOSE_WRAPPER -c up -d ${indirect@Q} -p ${name} $recreate $debug $override > /dev/null &
else
dir="$dir/docker-compose.yml"
eval $COMPOSE_WRAPPER -c up -f ${dir@Q} -p ${name} $override > /dev/null &
eval $COMPOSE_WRAPPER -c up -f ${dir@Q} -p ${name} $recreate $debug $override > /dev/null &
fi
fi
fi
Expand Down
11 changes: 8 additions & 3 deletions source/compose.manager/scripts/compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
export HOME=/root

SHORT=c:,f:,p:,d:,o:
LONG=command:,file:,project_name:,project_dir:,override:,debug
LONG=command:,file:,project_name:,project_dir:,override:,debug,recreate
OPTS=$(getopt -a -n compose --options $SHORT --longoptions $LONG -- "$@")

eval set -- "$OPTS"

files=""
project_dir=""
other_options=""
debug=false

while :
Expand All @@ -34,6 +35,10 @@ do
fi
shift 2
;;
--recreate )
other_options="--force-recreate"
shift;
;;
--debug )
debug=true
shift;
Expand All @@ -52,9 +57,9 @@ case $command in

up)
if [ "$debug" = true ]; then
logger "docker compose $files -p "$name" up -d"
logger "docker compose $files -p "$name" up $other_options -d"
fi
eval docker compose $files -p "$name" up -d 2>&1
eval docker compose $files -p "$name" up $other_options -d 2>&1
;;

down)
Expand Down

0 comments on commit 2a2849f

Please sign in to comment.