Skip to content
This repository was archived by the owner on Apr 4, 2026. It is now read-only.

Commit 4871b62

Browse files
committed
Add autostart functionality
1 parent bf45d3f commit 4871b62

7 files changed

Lines changed: 84 additions & 10 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
COMPOSE_ROOT=/boot/config/plugins/compose.manager/projects
4+
COMPOSE_WRAPPER=/usr/local/emhttp/plugins/compose.manager/scripts/compose.sh
5+
6+
for dir in $COMPOSE_ROOT/*; do
7+
if [ -d "$dir" ]; then
8+
if [ -f "$dir/compose.yml" ]; then
9+
if [ -f "$dir/autostart" ]; then
10+
if [ 'true' == "$(cat $dir/autostart)" ]; then
11+
# echo "$dir/compose.yml"
12+
logger "Starting compose stack: $(cat $dir/Name)"
13+
$COMPOSE_WRAPPER up "$dir/compose.yml" "$(cat $dir/Name)" > /dev/null &
14+
fi
15+
fi
16+
fi
17+
fi
18+
done
19+
20+
wait
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
COMPOSE_ROOT=/boot/config/plugins/compose.manager/projects
4+
COMPOSE_WRAPPER=/usr/local/emhttp/plugins/compose.manager/scripts/compose.sh
5+
6+
for dir in $COMPOSE_ROOT/*; do
7+
if [ -d "$dir" ]; then
8+
if [ -f "$dir/compose.yml" ]; then
9+
# echo "$dir/compose.yml"
10+
logger "Stopping compose stack: $(cat $dir/Name)"
11+
$COMPOSE_WRAPPER stop "$dir/compose.yml" "$(cat $dir/Name)" > /dev/null &
12+
fi
13+
fi
14+
done
15+
16+
wait

source/compose.manager/php/compose_manager_main.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@
2828
} else {
2929
$description = $variables['description'] ? $variables['description'] : "No description<br>($compose_root/$script)";
3030
}
31+
32+
$autostart = '';
33+
if ( is_file("$compose_root/$script/autostart") ) {
34+
$autostarttext = @file_get_contents("$compose_root/$script/autostart");
35+
if ( strpos($autostarttext, 'true') !== false ) {
36+
$autostart = 'checked';
37+
}
38+
}
39+
3140
$o .= "<span class='ca_descEdit' data-scriptName=".escapeshellarg($script)." id='desc$id'>$description</span>";
3241
$o .= "</td>";
33-
$o .= "<td width=30%></td>";
42+
$o .= "<td width=25%></td>";
3443
$o .= "<td width=5%><input type='button' value='Compose Up' class='up$id' id='$id' onclick='ComposeUp(&quot;$compose_root/$script&quot;);'></td>";
35-
$o .= "<td width=5%><input type='button' value='Compose Down' class='up$id' id='$id' onclick='ComposeDown(&quot;$compose_root/$script&quot;);'></td>";
36-
$o .= "<td width=5%><input type='button' value='Compose Pull' class='up$id' id='$id' onclick='ComposePull(&quot;$compose_root/$script&quot;);'></td>";
44+
$o .= "<td width=5%><input type='button' value='Compose Down' class='down$id' id='$id' onclick='ComposeDown(&quot;$compose_root/$script&quot;);'></td>";
45+
$o .= "<td width=5%><input type='button' value='Compose Pull' class='pull$id' id='$id' onclick='ComposePull(&quot;$compose_root/$script&quot;);'></td>";
46+
$o .= "<td width=5%><input type='checkbox' class='auto_start' data-scriptName=".escapeshellarg($script)." id='$id' style='display:none' $autostart></td>";
3747
}
3848
?>
3949

@@ -68,6 +78,12 @@ functionBefore: function(instance,helper) {
6878
instance.content(stackName + "<br><center><input type='button' value='Edit Name' onclick='editName(&quot;"+myID+"&quot;);'><input type='button' value='Edit Description' onclick='editDesc(&quot;"+myID+"&quot;);'><input type='button' onclick='editStack(&quot;"+myID+"&quot;);' value='Edit Stack'><input type='button' onclick='editEnv(&quot;"+myID+"&quot;);' value='Edit ENV'><input type='button' onclick='deleteStack(&quot;"+myID+"&quot;);' value='Delete Stack'></center>");
6979
}
7080
});
81+
$('.auto_start').switchButton({labels_placement:'right', on_label:"On", off_label:"Off"});
82+
$('.auto_start').change(function(){
83+
var script = $(this).attr("data-scriptname");
84+
var auto = $(this).prop('checked');
85+
$.post(caURL,{action:'updateAutostart',script:script,autostart:auto});
86+
});
7187
});
7288

7389
function addStack() {
@@ -278,6 +294,7 @@ function ComposePull(path) {
278294

279295
<span class='tipsterallowed' hidden></span><br>
280296
<table>
297+
<thead><tr><th style="text-align:left">Stack</th><th></th><th style="text-align:left" colspan="3">Commands</th><th style="text-align:left">Auto Start</th></tr></thead>
281298
<?=$o?>
282299
</table>
283300
<br>

source/compose.manager/php/compose_util.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ function echoComposeCommand($action)
7171
case 'composePull':
7272
echoComposeCommand('pull');
7373
break;
74+
case 'composeStop':
75+
echoComposeCommand('stop');
76+
break;
7477
}
7578
?>

source/compose.manager/php/exec.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ function getElement($element) {
1111
switch ($_POST['action']) {
1212
case 'addStack':
1313
$stackName = isset($_POST['stackName']) ? urldecode(($_POST['stackName'])) : "";
14-
$folderName = str_replace('"',"",$stackName);
15-
$folderName = str_replace("'","",$folderName);
16-
$folderName = str_replace("&","",$folderName);
17-
$folderName = str_replace("(","",$folderName);
18-
$folderName = str_replace(")","",$folderName);
19-
$folderName = preg_replace("/ {2,}/", " ", $folderName);
14+
$folderName = str_replace('"',"",$stackName);
15+
$folderName = str_replace("'","",$folderName);
16+
$folderName = str_replace("&","",$folderName);
17+
$folderName = str_replace("(","",$folderName);
18+
$folderName = str_replace(")","",$folderName);
19+
$folderName = preg_replace("/ {2,}/", " ", $folderName);
2020
$folder = "$compose_root/$folderName";
2121
while ( true ) {
2222
if ( is_dir($folder) ) {
@@ -44,7 +44,7 @@ function getElement($element) {
4444
$script = isset($_POST['script']) ? urldecode(($_POST['script'])) : "";
4545
$newName = isset($_POST['newName']) ? urldecode(($_POST['newName'])) : "";
4646
file_put_contents("$compose_root/$script/name",trim($newName));
47-
echo "ok";
47+
echo "ok";
4848
break;
4949
case 'changeDesc':
5050
$script = isset($_POST['script']) ? urldecode(($_POST['script'])) : "";
@@ -83,6 +83,19 @@ function getElement($element) {
8383
file_put_contents("$compose_root/$script/.env",$scriptContents);
8484
echo "$compose_root/$script/.env saved";
8585
break;
86+
case 'updateAutostart':
87+
$script = isset($_POST['script']) ? urldecode(($_POST['script'])) : "";
88+
if ( ! $script ) {
89+
echo "huh?";
90+
break;
91+
}
92+
$autostart = isset($_POST['autostart']) ? urldecode(($_POST['autostart'])) : "false";
93+
$fileName = "$compose_root/$script/autostart";
94+
if ( is_file($fileName) ) {
95+
exec("rm ".escapeshellarg($fileName));
96+
}
97+
file_put_contents($fileName,$autostart);
98+
break;
8699
}
87100

88101
?>

source/compose.manager/scripts/compose.sh

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ case $1 in
1414
docker compose -f "$2" -p "$3" pull 2>&1
1515
;;
1616

17+
stop)
18+
docker compose -f "$2" -p "$3" stop 2>&1
19+
;;
20+
1721
*)
1822
echo -n "unknown command"
1923
;;

source/pkg_build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cp -RT /mnt/source/compose.manager/ $tmpdir/usr/local/emhttp/plugins/compose.man
1212

1313
cd $tmpdir
1414

15+
chmod -R +x $tmpdir/usr/local/emhttp/plugins/compose.manager/event/
1516
chmod -R +x $tmpdir/usr/local/emhttp/plugins/compose.manager/scripts/
1617
chmod -R +x $tmpdir/usr/local/emhttp/plugins/compose.manager/php/
1718

0 commit comments

Comments
 (0)