forked from thunder-id/thunderid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·127 lines (115 loc) · 3.59 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·127 lines (115 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# ----------------------------------------------------------------------------
# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
#
# WSO2 LLC. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# Default settings
BACKEND_PORT=${BACKEND_PORT:-8090}
DEBUG_PORT=${DEBUG_PORT:-2345}
DEBUG_MODE=${DEBUG_MODE:-false}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--debug)
DEBUG_MODE=true
shift
;;
--debug-port)
DEBUG_PORT="$2"
shift 2
;;
--port)
BACKEND_PORT="$2"
shift 2
;;
--help)
echo "Thunder Server Startup Script"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --debug Enable debug mode with remote debugging"
echo " --port PORT Set application port (default: 8090)"
echo " --debug-port PORT Set debug port (default: 2345)"
echo " --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
set -e # Exit immediately if a command exits with a non-zero status
# Kill known ports
function kill_port() {
local port=$1
lsof -ti tcp:$port | xargs kill -9 2>/dev/null || true
}
# Kill ports before binding
kill_port $BACKEND_PORT
if [ "$DEBUG_MODE" = "true" ]; then
kill_port $DEBUG_PORT
fi
sleep 1
# Check if Delve is available for debug mode
if [ "$DEBUG_MODE" = "true" ]; then
# Check for dlv in PATH
if ! command -v dlv &> /dev/null; then
echo "❌ Debug mode requires Delve debugger"
echo ""
echo "💡 Install Delve using:"
echo " go install github.com/go-delve/delve/cmd/dlv@latest"
echo ""
echo "🔧 Add Delve to PATH"
echo ""
echo "🔧 After installation, run: $0 --debug"
exit 1
fi
fi
# Run thunder
if [ "$DEBUG_MODE" = "true" ]; then
echo "⚡ Starting Thunder Server in DEBUG mode..."
echo "📝 Application will run on: https://localhost:$BACKEND_PORT"
echo "🐛 Remote debugger will listen on: localhost:$DEBUG_PORT"
echo ""
echo "💡 Connect using remote debugging configuration:"
echo " Host: 127.0.0.1, Port: $DEBUG_PORT"
echo ""
# Run debugger
dlv exec --listen=:$DEBUG_PORT --headless=true --api-version=2 --accept-multiclient --continue ./thunder &
THUNDER_PID=$!
else
echo "⚡ Starting Thunder Server ..."
BACKEND_PORT=$BACKEND_PORT ./thunder &
THUNDER_PID=$!
fi
# Cleanup function
cleanup() {
echo -e "\n🛑 Stopping server..."
if [ -n "$THUNDER_PID" ]; then
kill $THUNDER_PID 2>/dev/null || true
fi
}
# Cleanup on Ctrl+C
trap cleanup SIGINT
# Status
echo ""
echo "🚀 Server running"
echo "Press Ctrl+C to stop the server."
# Wait for background processes
wait $THUNDER_PID