-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart
More file actions
executable file
·174 lines (150 loc) · 10.1 KB
/
start
File metadata and controls
executable file
·174 lines (150 loc) · 10.1 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
ANSI_BLACK="\e[30m"
ANSI_BLACK_BACKGROUND="\e[40m"
ANSI_RED="\e[31m"
ANSI_RED_BACKGROUND="\e[41m"
ANSI_GREEN="\e[32m"
ANSI_GREEN_BACKGROUND="\e[42m"
ANSI_BROWN="\e[33m"
ANSI_BROWN_BACKGROUND="\e[43m"
ANSI_BLUE="\e[34m"
ANSI_BLUE_BACKGROUND="\e[44m"
ANSI_PURPLE="\e[35m"
ANSI_PURPLE_BACKGROUND="\e[45m"
ANSI_CYAN="\e[36m"
ANSI_CYAN_BACKGROUND="\e[46m"
ANSI_GREY="\e[37m"
ANSI_GREY_BACKGROUND="\e[47m"
## Style
ANSI_BOLD="\e[1m"
ANSI_ITALIAN="\e[3m"
ANSI_UNDERLINE="\e[4m"
ANSI_BLINK="\e[5m"
ANSI_REVERSED_VIDEO="\e[7m"
ANSI_STRIKETHROUGH="\e[9m"
ANSI_END="\e[0m"
echo -e "\n
${ANSI_BOLD}════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════${ANSI_END}
${ANSI_BOLD}${ANSI_BLUE}
▒▒
░░ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓ ▒▒▒▒
████ ▒▒▒▒ ░░ ▓▓▓▓▒▒▒▒▓▓
██ ▒▒▒▒▓▓▓▓░░▓▓░░▓▓░░░░░░ ▒▒
▒▒░░░░░░░░░░▓▓░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
▒▒▓▓▓▓ ░░░░░░░░░░░░░░░░░░░░░░
▓▓▓▓▓▓▓▓ ▓▓▓▓▒▒░░░░░░░░░░░░░░▒▒▓▓
▓▓▓▓▓▓▓▓ ░░ ░░▒▒▓▓▓▓░░▒▒▒▒▒▒▒▒▒▒▓▓▓▓▒▒
▓▓▓▓▓▓▓▓▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒░░▓▓▓▓▒▒▒▒
▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓ ▒▒▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▓▓▓▓▓▓▓▓▓▓▒▒▓▓▓▓▒▒▒▒▓▓▓▓▓▓▓▓▒▒▒▒▓▓▒▒░░▒▒░░ ▓▓▒▒▒▒▒▒▓▓▓▓▒▒▒▒
▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▓▓▒▒▒▒▒▒▓▓▓▓░░░░▒▒
▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▓▓░░▒▒
▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒░░░░
▓▓ ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒░░░░
▓▓▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒░░
▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░
▓▓▓▓▓▓▓▓▒▒ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒
██████╗██╗ ██╗██████╗ ██████╗ ███╗ ██╗██╗ ██████╗██╗ ███████╗
██╔════╝██║ ██║██╔══██╗██╔═══██╗████╗ ██║██║██╔════╝██║ ██╔════╝
██║ ███████║██████╔╝██║ ██║██╔██╗ ██║██║██║ ██║ █████╗
██║ ██╔══██║██╔══██╗██║ ██║██║╚██╗██║██║██║ ██║ ██╔══╝
╚██████╗██║ ██║██║ ██║╚██████╔╝██║ ╚████║██║╚██████╗███████╗███████╗
╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═════╝╚══════╝╚══════╝
${ANSI_END}
${ANSI_BOLD}════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════${ANSI_END}\n"
function inform {
TYPE="$1"
shift
case "$TYPE" in
0)
echo -e " ${ANSI_BOLD}${ANSI_CYAN}[-]${ANSI_END} ${ANSI_BOLD}[SERVICE_]:${ANSI_END} $*"
;;
1)
echo -e " ${ANSI_BOLD}${ANSI_BROWN}[*]${ANSI_END} ${ANSI_BOLD}[SERVICE_]:${ANSI_END} $*"
;;
2)
echo -e " ${ANSI_BOLD}${ANSI_RED}[!]${ANSI_END} ${ANSI_BOLD}[SERVICE_]:${ANSI_END} $*"
;;
esac
}
inform 0 "${1:-4} workers available."
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PYTHONPATH=/home/noam/Work_spaces/Personal/chronicle
export PYTHONPATH="$(realpath chronicle_core/bin):$PYTHONPATH"
set -euo pipefail
stty -echoctl
SCRIPT_DIR="$(realpath "$(dirname "$0")")"
CHRONICLE_WEB_UI="${SCRIPT_DIR}/chronicle_web_ui"
CHRONICLE_BASE="${SCRIPT_DIR}/chronicle_base"
serviceUp=true
# Check directories
[[ -d "$CHRONICLE_WEB_UI" ]] || {
inform 2 "$CHRONICLE_WEB_UI not found"
exit 1
}
[[ -d "$CHRONICLE_BASE" ]] || {
inform 2 "$CHRONICLE_BASE not found"
exit 1
}
# Check commands
command -v npm >/dev/null || {
inform 2 "npm not found"
exit 1
}
command -v uvicorn >/dev/null || {
inform 2 "uvicorn not found"
exit 1
}
command -v gunicorn >/dev/null || {
inform 2 "gunicorn not found"
exit 1
}
# Cleanup function to kill background jobs
cleanup() {
if $serviceUp; then
serviceUp=false
stty echoctl
inform 1 "Stopping all workers..."
pkill -P $$ || true # Kill all child processes of this script
wait
inform 0 "All processes terminated."
echo -e "\n${ANSI_BOLD}════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════${ANSI_END}\n"
fi
}
# Trap termination signals
trap cleanup SIGINT SIGTERM EXIT
# Start processes
inform 0 "Starting gunicorn server..."
gunicorn chronicle_base.main:app -k uvicorn.workers.UvicornWorker -w "${1:-4}" --log-config "${CHRONICLE_BASE}/gunicorn/gunicorn_log_config.ini" &
gunicorn=$!
if [ "${1:-4}" -gt 4 ]; then
sleep 2
else
sleep 1
fi
if ! kill -0 "$gunicorn" 2>/dev/null; then
inform 2 "Failed to start gunicorn server."
cleanup
exit 1
fi
inform 0 "Starting npm development server..."
npm --prefix "$CHRONICLE_WEB_UI" run dev >/dev/null &
npm_pid=$!
sleep 0.1
if ! kill -0 "$npm_pid" 2>/dev/null; then
inform 2 "Failed to start npm dev server."
cleanup
exit 1
fi
inform 0 "Serving Chronicle at: ${ANSI_BOLD}${ANSI_CYAN}${ANSI_UNDERLINE}http://localhost:3000/${ANSI_END}"
wait