Skip to content

Commit 5a47ffa

Browse files
authored
Update code-server.sh
1 parent 112fc33 commit 5a47ffa

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

‎tools/code-server.sh‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,45 @@ echo " URL : http://$IP:$PORT"
4646
echo " Password : $PASSWORD"
4747
echo "============================================="
4848
echo
49-
echo "[Live logs below] Type STOP and press Enter at any time to stop the service."
49+
echo "[Live logs below] Press Ctrl+C at any time to stop the service."
5050
echo "-----------------------------------------------------------"
5151

52-
journalctl -u code-server@root -f --no-pager &
53-
LOG_PID=$!
52+
STOPPING=0
53+
LOG_PID=""
5454

55-
while true; do
56-
read -rp "" CONFIRM
57-
if [[ "$CONFIRM" == "STOP" ]]; then
58-
break
55+
start_logs() {
56+
( trap '' INT; journalctl -u code-server@root -f --no-pager ) &
57+
LOG_PID=$!
58+
}
59+
60+
stop_logs() {
61+
if [[ -n "$LOG_PID" ]]; then
62+
kill "$LOG_PID" 2>/dev/null || true
63+
wait "$LOG_PID" 2>/dev/null || true
64+
LOG_PID=""
5965
fi
60-
done
66+
}
67+
68+
confirm_stop() {
69+
# immediately silence logs so the prompt is clean
70+
stop_logs
71+
echo
72+
read -rp "Are you sure you want to stop code-server? (y/n): " ans
73+
if [[ "$ans" == "y" || "$ans" == "Y" ]]; then
74+
STOPPING=1
75+
else
76+
echo "Resuming logs... (press Ctrl+C again to stop)"
77+
start_logs
78+
fi
79+
}
80+
81+
trap confirm_stop SIGINT
6182

62-
kill "$LOG_PID" 2>/dev/null || true
63-
wait "$LOG_PID" 2>/dev/null || true
83+
start_logs
84+
85+
while [[ "$STOPPING" -eq 0 ]]; do
86+
sleep 1
87+
done
6488

6589
echo
6690
echo "[+] Stopping code-server (files will not be removed)..."

0 commit comments

Comments
 (0)