@@ -41,13 +41,15 @@ function waitForTtydSocket($socketName, $timeoutMs = 2000, $intervalMs = 100, $t
4141 * @param string $cmd The command to execute
4242 * @param bool $debug Whether to log debug messages
4343 * @param string $logFile Optional path to write a copy of the output
44+ * @param string $socketOverride Optional socket name to use instead of the global default
4445 */
45- function execComposeCommandInTTY ($ cmd , $ debug , $ logFile = '' )
46+ function execComposeCommandInTTY ($ cmd , $ debug , $ logFile = '' , $ socketOverride = '' )
4647{
4748 global $ socket_name ;
48- $ socketFile = rtrim (COMPOSE_TTYD_SOCKET_DIR , '/ ' ) . "/ $ socket_name.sock " ;
49+ $ effectiveSocket = $ socketOverride !== '' ? $ socketOverride : $ socket_name ;
50+ $ socketFile = rtrim (COMPOSE_TTYD_SOCKET_DIR , '/ ' ) . "/ $ effectiveSocket.sock " ;
4951 // Use pkill -f for more robust process matching instead of pgrep|awk pipeline
50- exec ("pkill -f " . escapeshellarg ("$ socket_name .sock " ) . " 2>/dev/null " );
52+ exec ("pkill -f " . escapeshellarg ("$ effectiveSocket .sock " ) . " 2>/dev/null " );
5153 usleep (300000 ); // 300ms for process to exit
5254 @unlink ($ socketFile );
5355 $ socketPath = escapeshellarg ($ socketFile );
@@ -64,7 +66,7 @@ function execComposeCommandInTTY($cmd, $debug, $logFile = '')
6466 clientDebug ("Executing command in ttyd: " . $ cmd , ['command ' => $ cmd ], 'user ' , 'debug ' , 'ttyd ' );
6567
6668 // Wait for the socket to be created to avoid 502 on first open.
67- waitForTtydSocket ($ socket_name );
69+ waitForTtydSocket ($ effectiveSocket );
6870}
6971
7072/**
@@ -178,9 +180,19 @@ function echoComposeCommand($action, $recreate = false, $background = false)
178180 return escapeshellarg ($ item );
179181 }, $ composeCommand );
180182 $ composeCommandStr = join (" " , $ composeCommandEscaped );
181- execComposeCommandInTTY ($ composeCommandStr , $ debug , $ logFile );
183+ // Use a per-stack socket for logs so viewing logs doesn't conflict
184+ // with action operations (up/update/pull) that share the default socket.
185+ $ logsSocket = '' ;
186+ if ($ action === 'logs ' ) {
187+ $ logsSocket = 'compose_logs_ ' . preg_replace ('/[^a-zA-Z0-9_.-]/ ' , '_ ' , basename ($ path ));
188+ }
189+ execComposeCommandInTTY ($ composeCommandStr , $ debug , $ logFile , $ logsSocket );
182190 clientDebug ("Executing command in ttyd: " . $ composeCommandStr , ['command ' => $ composeCommandStr ], 'user ' , 'debug ' , 'compose ' );
183- $ composeCommand = "/plugins/compose.manager/include/ShowTtyd.php " . ($ action !== 'logs ' ? "?done=1 " : "" );
191+ if ($ action === 'logs ' ) {
192+ $ composeCommand = "/plugins/compose.manager/include/ShowTtyd.php?socket= " . urlencode ($ logsSocket );
193+ } else {
194+ $ composeCommand = "/plugins/compose.manager/include/ShowTtyd.php?done=1 " ;
195+ }
184196 echo $ composeCommand ;
185197 } else {
186198 $ i = 0 ;
0 commit comments