forked from zutianbiao/baize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.sh
139 lines (134 loc) · 6.89 KB
/
manage.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
#!/bin/bash
# (c) 2016 , Tianbiao Zu <[email protected]>
#
# 该文件是Baize的一部分,Baize是一款通用的DevOps系统
#
# 该文件负责Baize基础软件环境的安装
##############################################################################
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH
. ./files/scripts/bash_lib_baize
case $1 in
update)
case $2 in
web|proxy|master|agent|demo)
LANG="zh_CN.UTF-8"
file_bakcup
python_install
virtualenv_install
env_install
pip_update
env_software_install
if [ "$2" == "proxy" ];then
influxdb_install
fi
dir_create
file_install $2
scripts_install
nginx_install
file_recover
local_ip=$(/usr/local/baize/env/bin/ansible localhost -m setup -a "filter=ansible_all_ipv4_addresses"|tail -n 6|head -n 1|awk -F '"' '{print $2}')
systemctl daemon-reload > /dev/null 2>&1
sed -i '/baize/d' /var/spool/cron/root >> ${PATH_DEBUG_LOG} 2>&1
chmod 755 /usr/local/baize/files/scripts/baize
if [ "$2" == "proxy" ];then
/etc/init.d/influxdb restart
sh /usr/local/baize/files/scripts/baize -s baize_auto_worker_proxy_restart
echo "* * * * * sh /usr/local/baize/files/scripts/baize -s auto_restart_check_auto_worker_proxy > /dev/null 2>&1" >> /var/spool/cron/root
fi
if [ "$2" == "agent" ];then
sed -i "s#127.0.0.1:8101#${local_ip}:8101#g" /usr/local/baize/APP/APP_agent/config.py >> ${PATH_DEBUG_LOG} 2>&1
fact_install
sh /usr/local/baize/files/scripts/baize -s baize_auto_worker_agent_restart
echo "* * * * * sh /usr/local/baize/files/scripts/baize -s auto_restart_check_auto_worker_agent > /dev/null 2>&1" >> /var/spool/cron/root
fi
if [ "$2" == "web" ];then
sh /usr/local/baize/files/scripts/baize -s baize_auto_worker_web_restart
echo "* * * * * sh /usr/local/baize/files/scripts/baize -s auto_restart_check_auto_worker_web > /dev/null 2>&1" >> /var/spool/cron/root
fi
sh /usr/local/baize/files/scripts/baize restart
cron_install
if [ "$2" == "web" ];then
# 第一次安装web环境时由于缺少编译环境需要先执行install web
# 然后执行make脚本
# 再重新执行install web
echo "0 2 */1 * * sh /usr/local/baize/API/API_web/scripts/db_backup.sh > /dev/null 2>&1" >> /var/spool/cron/root
# /usr/local/baize/env/bin/python /usr/local/baize/files/geo/init_geodb.py
fi
;;
*)
echo "请指定安装角色"
;;
esac
;;
install)
case $2 in
web|proxy|master|agent|demo)
yum -y install gcc libcurl-devel zlib-devel openssl-devel sqlite-devel bc >> ${PATH_DEBUG_LOG} 2>&1
sed -i '/net.core.somaxconn/d' /etc/sysctl.conf >> ${PATH_DEBUG_LOG} 2>&1
echo "net.core.somaxconn = 60000" >> /etc/sysctl.conf
sysctl -p >> ${PATH_DEBUG_LOG} 2>&1
LANG="zh_CN.UTF-8"
python_install
virtualenv_install
env_install
pip_update
env_software_install
if [ "$2" == "proxy" ];then
influxdb_install
fi
dir_create
file_install $2
scripts_install
nginx_install
local_ip=$(/usr/local/baize/env/bin/ansible localhost -m setup -a "filter=ansible_all_ipv4_addresses"|tail -n 6|head -n 1|awk -F '"' '{print $2}')
systemctl daemon-reload > /dev/null 2>&1
chmod 755 /usr/local/baize/files/scripts/baize
sed -i '/baize/d' /var/spool/cron/root >> ${PATH_DEBUG_LOG} 2>&1
/usr/local/baize/env/bin/python /usr/local/baize/manage.py migrate >> ${PATH_DEBUG_LOG} 2>&1
if [ "$2" == "proxy" ];then
/etc/init.d/influxdb restart
/usr/local/baize/env/bin/python /usr/local/baize/manage.py migrate --database=proxy >> ${PATH_DEBUG_LOG} 2>&1
sh /usr/local/baize/files/scripts/baize -s baize_auto_worker_proxy_restart
echo "* * * * * sh /usr/local/baize/files/scripts/baize -s auto_restart_check_auto_worker_proxy > /dev/null 2>&1" >> /var/spool/cron/root
fi
if [ "$2" == "agent" ];then
sed -i "s#127.0.0.1:8101#${local_ip}:8101#g" /usr/local/baize/APP/APP_agent/config.py >> ${PATH_DEBUG_LOG} 2>&1
fact_install
/usr/local/baize/env/bin/python /usr/local/baize/manage.py migrate --database=agent >> ${PATH_DEBUG_LOG} 2>&1
sh /usr/local/baize/files/scripts/baize -s baize_auto_worker_agent_restart
echo "* * * * * sh /usr/local/baize/files/scripts/baize -s auto_restart_check_auto_worker_agent > /dev/null 2>&1" >> /var/spool/cron/root
fi
if [ "$2" == "web" ];then
/usr/local/baize/env/bin/python /usr/local/baize/manage.py migrate --database=web >> ${PATH_DEBUG_LOG} 2>&1
sh /usr/local/baize/files/scripts/baize -s baize_auto_worker_web_restart
echo "* * * * * sh /usr/local/baize/files/scripts/baize -s auto_restart_check_auto_worker_web > /dev/null 2>&1" >> /var/spool/cron/root
fi
sh /usr/local/baize/files/scripts/baize restart
cron_install
if [ "$2" == "web" ];then
echo "0 2 */1 * * sh /usr/local/baize/API/API_web/scripts/db_backup.sh > /dev/null 2>&1" >> /var/spool/cron/root
# /usr/local/baize/env/bin/python /usr/local/baize/files/geo/init_geodb.py
fi
;;
*)
echo "请指定安装角色"
;;
esac
;;
uninstall)
sh /usr/local/baize/files/scripts/baize stop
rm -fr /usr/local/baize/
sed -i '/baize/d' /var/spool/cron/root
/etc/init.d/baize -s baize_auto_worker_proxy_stop
/etc/init.d/influxdb stop
/etc/init.d/baize -s baize_auto_worker_agent_stop
rm -f sh /etc/init.d/baize
rm -fr /root/.ansible/ansible_plugins/callback_plugins/*baize*
rm -fr /tmp/baize*
echo "卸载完毕"
;;
*)
echo "Usage: sh manage.sh [install|update|uninstall] [web|proxy|master|agent]"
;;
esac