-
Notifications
You must be signed in to change notification settings - Fork 0
/
noc
98 lines (92 loc) · 2.43 KB
/
noc
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
#!/bin/bash -e
noc_help() {
cat << HELP
PKU PHY SU NOC Helper Script
b u: backend update uWSGI will reload
b r: backend reload start if not running
b s: backend stop
b f: backend flask <command>
b ?: backend running?
f u: frontend update
# d u: dev backend update
# d r: dev backend reload
# d s: dev backend stop
# d f: dev backend flask <command>
# d ?: dev backend running?
# dev backend is not availble now
HELP
exit
}
uwsgi_running() {
ps -p $(cat "/tmp/$UWSGI_NAME.pid") > /dev/null 2>&1
# 这里的> /dev/null 2>&1是重定向(来自菜鸡的注释)
# see: https://www.runoob.com/linux/linux-shell-io-redirections.html
}
reload_uwsgi() {
if uwsgi_running; then
echo 'Reloading uWSGI.'
poetry run uwsgi --reload "/tmp/$UWSGI_NAME.pid"
else
poetry run uwsgi -d --ini uwsgi.ini
fi
}
if [[ $# -lt 2 ]]; then
noc_help
fi
if [[ $1 == 'b' ]]; then
cd /root/project/bookB116-backend
export FLASK_ENV=production
export UWSGI_NAME=b116
elif [[ $1 == 'd' ]]; then
noc_help
# cd /home/$USER/devphy
# export FLASK_ENV=development
# export UWSGI_NAME=devphy
# export UWSGI_DEV=1
fi
if [[ $1 == 'b' ]] || [[ $1 == 'd' ]]; then
export VIRTUAL_ENV="$(poetry env info -p)/"
if [[ $2 == 'u' ]]; then
echo 'Pulling Git repo, may take some time...'
cd /root/project/bookB116-backend
git pull
poetry install --no-root --no-dev -E uwsgi -E ws
reload_uwsgi
elif [[ $2 == 'r' ]]; then
reload_uwsgi
elif [[ $2 == 's' ]]; then
if uwsgi_running; then
poetry run uwsgi --stop "/tmp/$UWSGI_NAME.pid"
echo 'Stopped uWSGI.'
else
echo 'Not running.'
fi
elif [[ $2 == 'f' ]]; then
poetry run flask "${@:3}"
elif [[ $2 == '?' ]]; then
if uwsgi_running; then
echo 'Running'
else
echo 'Not Running'
fi
else
noc_help
fi
elif [[ $1 == 'f' ]]; then
if [[ $2 == 'u' ]]; then
cd /root/project/bookB116-frontend
echo 'Pulling Git repo, may take some time...'
git pull
export VUE_APP_API_ROOT="https://bookb116.phy.pku.edu.cn/"
npm ci
# 如果在 subpath,则需 PUB_PATH=/physu/
npm run build
# rm -rf /home/$USER/html/vue
# cp -r dist /home/$USER/html/vue
# 不明白意义
else
noc_help
fi
else
noc_help
fi