@@ -28,17 +28,19 @@ const ProcessIDFilePath = "/.devspace/devspace-pid"
2828// HelperScript is the content of the restart script in the container
2929const HelperScript = `#!/bin/sh
3030#
31- # A process wrapper script to simulate a container restart. This file was injected with devspace during the build process
31+ # DevSpace Restart Helper
3232#
3333set -e
3434
3535restart=true
3636screenSessionName="devspace"
37- screenLogFile="/tmp/screen.log"
38- pidFile="/.devspace/devspace-pid"
37+ workDir="$PWD"
38+ tmpDir="/.devspace"
39+ screenLogFile="$tmpDir/screenlog.0"
40+ pidFile="$tmpDir/devspace-pid"
41+ sidFile="$tmpDir/devspace-sid"
3942
40- mkdir -p $(dirname $screenLogFile)
41- mkdir -p $(dirname $pidFile)
43+ mkdir -p $tmpDir
4244
4345trap quit TERM INT
4446quit() {
@@ -53,8 +55,8 @@ quit() {
5355 timeout 5 tail --pid=$pidToKill -f /dev/null 2>&1
5456 fi
5557
56- if [ -f "$pidFile.screen " ]; then
57- pidToKill="$(cat $pidFile.screen )"
58+ if [ -f "$ppidFile " ]; then
59+ pidToKill="$(cat $ppidFile )"
5860 kill -9 $((0-$pidToKill)) >/dev/null 2>&1
5961 fi
6062}
@@ -63,14 +65,20 @@ while $restart; do
6365 set +e
6466 if command -v screen >/dev/null; then
6567 rm -f "$screenLogFile"
66- commandAndArguments="$@"
67- echo screen -L -Logfile "$screenLogFile" -dmS $screenSessionName sh -c "echo \$$>$pidFile; echo \$PPID>$pidFile.screen; exec "'"'"$commandAndArguments"'"'"; exit;" > /tmp/test-command
68- screen -L -Logfile "$screenLogFile" -dmS $screenSessionName sh -c "echo \$$>$pidFile; echo \$PPID>$pidFile.screen; exec "'"'"$commandAndArguments"'"'"; exit;"
69- while [ ! -f "$pidFile" ]; do
68+ rm -f "$pidFile"
69+ rm -f "$sidFile"
70+
71+ cd "$tmpDir"
72+
73+ screen -q -L -dmS $screenSessionName sh -c 'echo $$>"'$pidFile'"; echo $PPID>"'$sidFile'"; cd "'$workDir'"; exec "$@"; exit;' _ "$@"
74+
75+ while [ ! -f "$sidFile" ]; do
7076 sleep 0.1
7177 done
72- screen -r $ screenSessionName -X colon "logfile flush 1^M "
78+ sid="$(cat $sidFile).${ screenSessionName} "
7379 pid="$(cat $pidFile)"
80+
81+ screen -q -S "${sid}" -X colon "logfile flush 1^M"
7482 tail --pid=$pid -f "$screenLogFile"
7583 else
7684 setsid "$@" &
0 commit comments