forked from meolu/walle-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.sh
executable file
·113 lines (105 loc) · 3.18 KB
/
admin.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
#########################################################################
# File APP: admin.sh
# Author: wushuiyong
# mail: [email protected]
# Created Time: 2018年11月03日 星期六 06时09分46秒
#########################################################################
#!/bin/bash
APP="waller.py"
function init() {
echo "init walle"
echo "----------------"
which pip
if [ $? != "0" ]; then
exit 1
fi
pip install virtualenv
if [ ! -d "venv" ]; then
virtualenv --no-site-packages venv # 注意:安装失败请指定python路径. mac 可能会有用anaconda的python. 请不要mac试用, 麻烦多多
fi
source ./venv/bin/activate
pip install -r ./requirements/prod.txt
echo "************************************************"
echo -e "\033[32m init walle success \033[0m"
echo -e "\033[32m welcome to walle 2.0 \033[0m"
}
function start() {
echo "start walle"
echo "----------------"
source ./venv/bin/activate
mkdir -p logs
nohup python $APP >> logs/runtime.log 2>&1 &
echo -e "Starting walle: [\033[32m ok \033[0m]"
echo -e "runtime: \033[32m logs/runtime.log \033[0m"
echo -e "error: \033[32m logs/error.log \033[0m"
}
function stop() {
echo "stop walle"
echo "----------------"
# 获取进程 PID
PID=$(ps -ef | grep $APP | grep -v grep | awk '{print $2}')
# 杀死进程
kill -9 $PID
}
function restart() {
echo "restart walle"
echo "----------------"
stop
start
}
function upgrade() {
echo "upgrade walle"
echo "----------------"
cd `dirname $0`
git pull
}
function migration() {
echo "migration walle"
echo "----------------"
source venv/bin/activate
export FLASK_APP=waller.py
flask db upgrade
if [ $? == "0" ]; then
echo -e "Migration: [\033[32m ok \033[0m]"
else
echo -e "Migration: [\033[31m fail \033[0m]"
fi
}
case "$1" in
init )
echo "************************************************"
init
echo "************************************************"
;;
start )
echo "************************************************"
start
echo "************************************************"
;;
stop )
echo "************************************************"
stop
echo "************************************************"
;;
restart )
echo "************************************************"
restart
echo "************************************************"
;;
upgrade )
echo "************************************************"
upgrade
migration
echo "************************************************"
;;
migration )
echo "************************************************"
migration
echo "************************************************"
;;
* )
echo "************************************************"
echo "Usage: sh admin {init|start|stop|restart|upgrade|migration}"
echo "************************************************"
;;
esac