Skip to content

Commit 2a2849f

Browse files
committed
Add option to force recreate containers on autostart.
1 parent d94e67d commit 2a2849f

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

source/compose.manager/compose.manager.settings.page

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ _(Debug Logging)_:
6363
Enable debug logging.
6464
</blockquote>
6565

66+
_(Recreate During Autostart)_:
67+
: <select name="AUTOSTART_FORCE_RECREATE">
68+
<?=mk_option($cfg['AUTOSTART_FORCE_RECREATE'], "false", _("Disabled"))?>
69+
<?=mk_option($cfg['AUTOSTART_FORCE_RECREATE'], "true", _("Enabled"))?>
70+
</select>
71+
72+
<blockquote class="inline_help" style="display: none;">
73+
Use the --force-recreate option when autostarting stacks.<br>
74+
This will recreate each stack container on startup.<br>
75+
This can work around an issue where containers refuse to autostart because the
76+
network they are attached to no longer exists.
77+
</blockquote>
78+
6679
_(Patch unRAID WebUI)_:
6780
: <select name="PATCH_UI">
6881
<?=mk_option($cfg['PATCH_UI'], "false", _("No"))?>

source/compose.manager/default.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
OUTPUTSTYLE="ttyd"
22
PATCH_UI="false"
33
DEBUG_TO_LOG="false"
4-
PROJECTS_FOLDER="/boot/config/plugins/compose.manager/projects"
4+
PROJECTS_FOLDER="/boot/config/plugins/compose.manager/projects"
5+
AUTOSTART_FORCE_RECREATE="false"

source/compose.manager/event/started

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ sanitize() {
1414
echo "${s,,}" # convert to lowercase
1515
}
1616

17+
recreate=""
18+
if [ "$AUTOSTART_FORCE_RECREATE" = "true" ]; then
19+
recreate="--recreate"
20+
fi
21+
22+
debug=""
23+
if [ "$DEBUG_TO_LOG" = "true" ]; then
24+
debug="--debug"
25+
fi
26+
1727
for dir in $COMPOSE_ROOT/*; do
1828
if [ -d "$dir" ]; then
1929
if [ -f "$dir/docker-compose.yml" ] || [ -f "$dir/indirect" ]; then
@@ -32,10 +42,10 @@ for dir in $COMPOSE_ROOT/*; do
3242
if [ -f "$dir/indirect" ]; then
3343
indirect=${dir}/indirect
3444
indirect=$(< "${indirect}")
35-
eval $COMPOSE_WRAPPER -c up -d ${indirect@Q} -p ${name} $override > /dev/null &
45+
eval $COMPOSE_WRAPPER -c up -d ${indirect@Q} -p ${name} $recreate $debug $override > /dev/null &
3646
else
3747
dir="$dir/docker-compose.yml"
38-
eval $COMPOSE_WRAPPER -c up -f ${dir@Q} -p ${name} $override > /dev/null &
48+
eval $COMPOSE_WRAPPER -c up -f ${dir@Q} -p ${name} $recreate $debug $override > /dev/null &
3949
fi
4050
fi
4151
fi

source/compose.manager/scripts/compose.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
export HOME=/root
33

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

88
eval set -- "$OPTS"
99

1010
files=""
1111
project_dir=""
12+
other_options=""
1213
debug=false
1314

1415
while :
@@ -34,6 +35,10 @@ do
3435
fi
3536
shift 2
3637
;;
38+
--recreate )
39+
other_options="--force-recreate"
40+
shift;
41+
;;
3742
--debug )
3843
debug=true
3944
shift;
@@ -52,9 +57,9 @@ case $command in
5257

5358
up)
5459
if [ "$debug" = true ]; then
55-
logger "docker compose $files -p "$name" up -d"
60+
logger "docker compose $files -p "$name" up $other_options -d"
5661
fi
57-
eval docker compose $files -p "$name" up -d 2>&1
62+
eval docker compose $files -p "$name" up $other_options -d 2>&1
5863
;;
5964

6065
down)

0 commit comments

Comments
 (0)