forked from ontoportal/ontoportal_docker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathontoportal
executable file
·197 lines (173 loc) · 4.29 KB
/
ontoportal
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
setup() {
echo "[+] Setup"
if [ -f ".env" ]; then
echo "[+] Env file exist"
else
echo "[+] Env file does not exist"
cp .env.sample .env
fi
}
which_service() {
if [ -z "$1" ]; then
SERVICE="ontoportal"
else
SERVICE="$1"
fi
echo "$SERVICE"
}
clean() {
echo "[+] Cleaning the server"
# Check if the -f flag is set
FORCE=false
for arg in "$@"; do
if [ "$arg" == "-f" ]; then
FORCE=true
break
fi
done
if [ "$FORCE" == true ]; then
answer="y"
else
read -p "Too risky and not needed in production, useful only locally to reset all the containers and volumes. Do you want to continue? (y/n): " answer
fi
if [[ "$answer" == "y" ]]; then
./bin/run_ui.sh clean
./bin/run_api.sh clean
else
echo "You chose to exit. Goodbye!"
fi
}
update() {
SERVICE=$(which_service "$1")
if [ "$SERVICE" == "api" ]; then
echo "[+] Updating API images to latest version"
./bin/run_api.sh update
elif [ "$SERVICE" == "ui" ]; then
echo "[+] Updating UI images to latest version"
./bin/run_ui.sh update
else
echo "[+] Updating UI and API images to latest version"
./bin/run_api.sh update
./bin/run_ui.sh update
fi
}
stop() {
SERVICE=$(which_service "$1")
echo "[+] Stopping $SERVICE services"
if [ "$SERVICE" == "api" ]; then
./bin/run_api.sh stop
elif [ "$SERVICE" == "ui" ]; then
./bin/run_ui.sh stop
else
./bin/run_ui.sh stop
./bin/run_api.sh stop
fi
}
logs() {
SERVICE=$(which_service "$1")
if [ "$SERVICE" == "api" ]; then
./bin/run_api.sh logs
elif [ "$SERVICE" == "ui" ]; then
./bin/run_ui.sh logs
else
echo "Choose which service to display logs API or UI"
fi
}
deploy() {
./bin/deploy.sh "$1"
}
start() {
local service=""
local provision=""
for arg in "$@"
do
case "$arg" in
"api" | "ui")
service="$arg"
;;
"--no-provision")
provision="--no-provision"
;;
*)
echo "Invalid argument: $arg"
return 1
;;
esac
done
# Update SERVICE variable in .env
SERVICE=$(which_service "$service")
awk -v SERVICE="$SERVICE" '/^SERVICE=/{sub(/=.*/, "=" SERVICE)} 1' .env >temp && mv temp .env
source .env
if [ "$SERVICE" == "api" ]; then
awk '/^API_URL=/ {sub(/^API_URL=.*/, "API_URL=http://localhost:9393")} 1' .env > temp && mv temp .env
./bin/run_api.sh start "$provision"
elif [ "$SERVICE" == "ui" ]; then
./bin/run_ui.sh start
elif [ "$SERVICE" == "ontoportal" ]; then
awk '/^API_URL=/ {sub(/^API_URL=.*/, "API_URL=http://api-service:9393")} 1' .env > temp && mv temp .env
./bin/run_api.sh start "$provision"
./bin/run_ui.sh start
else
echo "[x] Service not recognized, Exiting"
exit 1
fi
}
show_help() {
echo "Usage: $0 <command> [arguments]"
echo
echo "Commands:"
echo " start : Start the ontologies API and UI in either Default Mode or Personalized Mode."
echo " Usage: $0 start [api|ui] [--no-provision]"
echo " --no-provision: Start the appliance without any data (an empty appliance)."
echo
echo " deploy : Deploy the application using Kamal to the server."
echo " Usage: $0 deploy [api|ui]"
echo
echo " stop : Stop the API and UI services."
echo " Usage: $0 stop [api|ui]"
echo
echo " clean : Clean up the server. WARNING: This removes all data, docker-compose files, and containers."
echo " Usage: $0 clean [-f]"
echo " -f, --force : Force clean the server without prompting for confirmation."
echo
echo " update : Pull and update the UI and API container versions to the latest versions."
echo " Usage: $0 update"
echo
echo " help : Show this help message."
echo " Usage: $0 help"
echo
echo "Additional notes:"
echo " - You can provide your own .env file to customize parameters:"
echo " Place the .env file in this directory and run '$0 start'."
}
source utils/ontoportal_logo.sh
setup
case "$1" in
"start")
shift
start "$@"
;;
"deploy")
deploy "$2"
;;
"stop")
stop "$2"
;;
"clean")
clean "$2"
;;
"update")
update "$2"
;;
"logs")
logs "$2"
;;
"help")
show_help
;;
*)
show_help
exit 1
;;
esac