From d43bbf77fe60156d1a48abbefc026ab566030168 Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Fri, 13 Feb 2026 20:47:12 -0300 Subject: [PATCH] feat: Enhance `restart.sh` to include clean build, robust server startup with health check, graceful shutdown, and real-time log tailing. --- restart.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/restart.sh b/restart.sh index 0a0c5b54dc..d81d548a2c 100755 --- a/restart.sh +++ b/restart.sh @@ -64,5 +64,52 @@ if ! kill_by_port; then fi echo "" -echo "πŸš€ Iniciando npm run dev..." -npm run build && npm run start +echo "🧹 Limpando build anterior (.next)..." +rm -rf .next + +echo "πŸ”¨ Fazendo build limpo..." +npm run build +if [ $? -ne 0 ]; then + echo "❌ Build falhou!" + exit 1 +fi + +echo "" +echo "πŸš€ Iniciando servidor na porta $PORT..." +LOG_FILE="/tmp/omniroute.log" +> "$LOG_FILE" + +npx next start --port $PORT >> "$LOG_FILE" 2>&1 & +SERVER_PID=$! + +# Ao fechar (Ctrl+C), mata o servidor e libera a porta +cleanup() { + echo "" + echo "πŸ›‘ Parando servidor (PID: $SERVER_PID)..." + kill $SERVER_PID 2>/dev/null + wait $SERVER_PID 2>/dev/null + fuser -k $PORT/tcp 2>/dev/null + echo "βœ… Servidor parado. Porta $PORT liberada." + exit 0 +} +trap cleanup SIGINT SIGTERM + +# Aguarda o servidor ficar pronto +echo "⏳ Aguardando servidor iniciar (PID: $SERVER_PID)..." +for i in $(seq 1 15); do + sleep 1 + if curl -s -o /dev/null -w "" http://localhost:$PORT > /dev/null 2>&1; then + echo "" + echo "βœ… Servidor rodando em http://localhost:$PORT (PID: $SERVER_PID)" + echo "πŸ“„ Pressione Ctrl+C para parar" + echo "────────────────────────────────────────" + break + fi + printf "." +done + +# Fica mostrando os logs na tela atΓ© Ctrl+C +tail -f "$LOG_FILE" & +TAIL_PID=$! +wait $SERVER_PID 2>/dev/null +kill $TAIL_PID 2>/dev/null