-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage
executable file
·101 lines (89 loc) · 2.33 KB
/
manage
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
#! /bin/bash
function print_help {
echo "usage:"
echo " ./manage [makemigrations|migrate|clean|rebuild|run|debug|stop]"
}
[[ $# -ne 1 ]] && print_help && exit
cmd=$1
mode="release"
apps=("account" "announcement" "conf" "contest" "options" "problem" "submission")
supervisor_grep="supervisord -c ./deploy/supervisord"
supervisor_cmd="supervisord -c ./deploy/supervisord.conf"
supervisor_debug_cmd="supervisord -c ./deploy/supervisord-debug.conf"
function clean {
rm -rf ./data/zips
rm -rf ./data/problems
rm -rf ./data/submissions
find . -type d -name 'migrations' -not -path './venv/*' | xargs rm -r;
rm onl.db
docker rm -f oj-redis-dev
}
function migrate {
for app in "${apps[@]}"; do
python3 manage.py makemigrations $app
done
python3 manage.py migrate
python3 manage.py inituser --username=root --password=rootroot --action=create_super_admin
}
function run_onl {
[[ ! -d data/log ]] && mkdir -p data/log && echo 'mkdir data/log'
[[ -z $FRONTEND ]] && echo "environment variable FRONTEND is not set" && return 1
if ! command which python3 | grep venv > /dev/null; then
source venv/bin/activate
fi
export TARGET=http://127.0.0.1:7890
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm use v8.12.0
workdir=$(pwd)
process_num=$(nproc)
echo "starting ${process_num} procs"
# run onl
if ! command pgrep -f "$supervisor_grep" > /dev/null; then
echo "running onl controller ..."
if [[ "$mode" == "debug" ]]; then
FRONTEND=$FRONTEND WORKDIR=$workdir MAX_WORKER_NUM=$process_num $supervisor_debug_cmd > /dev/null &
else
FRONTEND=$FRONTEND WORKDIR=$workdir MAX_WORKER_NUM=$process_num $supervisor_cmd > /dev/null &
fi
[[ $? -ne 0 ]] && echo "Error: fail to run onl"
else
echo "onl is already running"
fi
return 0
}
function stop_onl {
pkill -f "$supervisor_grep"
[[ $? -eq 0 ]] && echo "stop supervisord"
}
case $cmd in
"make" | "makemigrations" )
for app in "${apps[@]}"; do
python3 manage.py makemigrations $app
done
;;
"migrate" )
migrate
;;
"clean" )
clean
;;
"rebuild" )
clean
migrate
;;
"run" )
run_onl
;;
"debug" )
mode="debug"
run_onl
;;
"stop" )
stop_onl
;;
* )
echo "unknown commmand: $cmd"
print_help
;;
esac