-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.sh
156 lines (122 loc) · 3.68 KB
/
model.sh
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
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' #no color
# Edit config.json and set parameters
update_json() {
key=$1
value=$2
CONFIG_FILE="config.json"
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo -e "${RED}WARNING jq is not installed. Please install jq to use this script.${NC}"
echo "using -> apt install jq OR brew install jq"
exit 1
fi
# Using jq to update the JSON file
jq ".$key = $value" "$CONFIG_FILE" > temp.json && mv temp.json "$CONFIG_FILE"
}
build_and_start_all() {
cp config.json nextjs_app/
docker-compose up -d
}
build_and_start_sat() {
echo "Building the SAT solver service..."
docker-compose up -d sat_solver_204
}
start_sat_solver_solo(){
docker exec $SAT_SOLVER_CONTAINER_ID python3 run.py
}
start_sat_solver() {
docker exec $SAT_SOLVER_CONTAINER_ID python3 run.py > /dev/null 2>&1
}
start_nextjs_app() {
get_web_app_port
docker exec $WEB_APP_CONTAINER_ID npm start -- -p $WEBPORT > /dev/null 2>&1
}
get_docker_containers() {
WEB_APP_CONTAINER_ID=$(docker-compose ps -q web_app_204)
SAT_SOLVER_CONTAINER_ID=$(docker-compose ps -q sat_solver_204)
}
is_web_app_running() {
docker ps -q -f name=web_app_204
}
is_sat_solver_running() {
docker ps -q -f name=sat_solver_204
}
get_web_app_port(){
WEBPORT=$(jq '.web_app_port' config.json)
}
# Clean up processes on exit
cleanup() {
get_docker_containers
echo 'Stopping all processes...'
if is_web_app_running; then
docker stop $WEB_APP_CONTAINER_ID 2> /dev/null &
fi
docker stop $SAT_SOLVER_CONTAINER_ID 2> /dev/null
exit
}
trap cleanup SIGINT SIGTERM
uninstall(){
echo -e "${RED}WARNING: Removing all associated Container, Volumes and Networks!${NC}"
docker-compose down --volumes --rmi all
}
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--build) build_flag=true; shift ;;
--start) start_flag=true; shift ;;
--console) console_flag=true; shift ;;
--run) run_flag=true; shift ;;
--shutdown) stop_flag=true; shift;;
--uninstall) uninstall_flag=true; shift;;
esac
done
if [[ $build_flag == true && $console_flag == true ]]; then
update_json "use_web_app" "false"
build_and_start_sat
#get_docker_containers
#docker exec -it $SAT_SOLVER_CONTAINER_ID python3 run.py
elif [[ $start_flag ]]; then
if [[ $console_flag ]]; then
update_json "use_web_app" "false"
build_and_start_sat
get_docker_containers
docker exec -it $SAT_SOLVER_CONTAINER_ID python3 run.py
else
build_and_start_all
fi
elif [[ $build_flag == true ]]; then
echo "Building the Python Sat Solver and the Nextjs Web App"
update_json "use_web_app" "true"
build_and_start_all
elif [[ $run_flag == true ]]; then
runmode=true
get_docker_containers
#SAT
if [[ $console_flag == true ]]; then
update_json "use_web_app" "false"
echo -e "${GREEN}Success!${NC}"
docker exec -it $SAT_SOLVER_CONTAINER_ID python3 run.py
#WEBAPP
else
update_json "use_web_app" "true"
start_sat_solver &
get_web_app_port
echo -e "${GREEN}Success!${NC}"
echo -e "${GREEN}The Web App is available: http://localhost:$WEBPORT/${NC}"
start_nextjs_app
if [ $? -eq 1 ]; then
echo -e "${RED}WARNING An Error has occured starting the Web App!${NC}"
fi
fi
elif [[ $stop_flag == true ]]; then
cleanup
elif [[ $uninstall_flag == true ]]; then
uninstall
else
echo "Invalid option: -$OPTARG" >&2
echo "Please specify a build or run option"
exit 1
fi