Skip to content

Commit cc581af

Browse files
authored
Update code-server.sh
1 parent c7ba4e5 commit cc581af

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎tools/code-server.sh‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ echo "-----------------------------------------------------------"
5858

5959
STOPPING=0
6060
LOG_PID=""
61+
HANDLING=0
6162

6263
start_logs() {
63-
( trap '' INT; journalctl -u code-server@root -f --no-pager ) &
64+
pkill -f "journalctl -u code-server@root" 2>/dev/null || true
65+
( trap '' INT; exec journalctl -u code-server@root -f --no-pager ) &
6466
LOG_PID=$!
6567
}
6668

@@ -70,9 +72,15 @@ stop_logs() {
7072
wait "$LOG_PID" 2>/dev/null || true
7173
LOG_PID=""
7274
fi
75+
pkill -f "journalctl -u code-server@root" 2>/dev/null || true
7376
}
7477

7578
confirm_stop() {
79+
if [[ "$HANDLING" -eq 1 ]]; then
80+
return
81+
fi
82+
HANDLING=1
83+
trap '' SIGINT
7684
stop_logs
7785
echo
7886
read -rp "Are you sure you want to stop code-server? (y/n): " ans
@@ -81,6 +89,8 @@ confirm_stop() {
8189
else
8290
echo "Resuming logs... (press Ctrl+C again to stop)"
8391
start_logs
92+
HANDLING=0
93+
trap confirm_stop SIGINT
8494
fi
8595
}
8696

@@ -91,6 +101,7 @@ while [[ "$STOPPING" -eq 0 ]]; do
91101
sleep 1
92102
done
93103

104+
stop_logs
94105
echo
95106
echo "[+] Stopping code-server (files will not be removed)..."
96107
systemctl stop code-server@root 2>/dev/null || true

0 commit comments

Comments
 (0)