File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,21 +46,45 @@ echo " URL : http://$IP:$PORT"
4646echo " Password : $PASSWORD "
4747echo " ============================================="
4848echo
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."
5050echo " -----------------------------------------------------------"
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
6589echo
6690echo " [+] Stopping code-server (files will not be removed)..."
You can’t perform that action at this time.
0 commit comments