-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
220 lines (174 loc) · 5.45 KB
/
install.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
# 设置下载文件的URL
JAR_URL='https://it-service-cos.kujiale.com/xiaoku/portal.jar'
ZIP_URL='https://it-service-cos.kujiale.com/xiaoku/portal-frontend.zip'
# 设置目标目录
BASE_DIR="/portal"
FRONTEND_DIR=$BASE_DIR/frontend
# 创建目标目录
mkdir -p $BASE_DIR $FRONTEND_DIR
# 删除老文件
rm -rf $BASE_DIR/portal.jar
rm -rf $BASE_DIR/portal-frontend.zip
# 下载文件
curl -o $BASE_DIR/portal.jar $JAR_URL
curl -o $BASE_DIR/portal-frontend.zip $ZIP_URL
echo '==========检查依赖包=========='
# 检查 unzip 是否安装
if ! command -v unzip &> /dev/null; then
echo "unzip 未安装,尝试安装..."
# 使用 apt-get 安装 unzip,需要 sudo 权限
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y unzip
else
echo "无法确定系统类型,无法安装 unzip。请手动安装后重新运行脚本。"
exit 1
fi
# 再次检查是否安装成功
if ! command -v unzip &> /dev/null; then
echo "unzip 安装失败,请手动安装后重新运行脚本。"
exit 1
fi
fi
echo '==========检查 nginx 部署=========='
# 检查 nginx 是否安装
if ! command -v nginx &> /dev/null; then
echo "Nginx 未安装,尝试安装..."
# 使用 apt-get 安装 nginx,需要 sudo 权限
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y nginx
elif command -v yum &> /dev/null; then
sudo yum install -y nginx
else
echo "无法确定系统类型,无法安装 Nginx。请手动安装后重新运行脚本。"
exit 1
fi
# 再次检查是否安装成功
if ! command -v nginx &> /dev/null; then
echo "Nginx 安装失败,请手动安装后重新运行脚本。"
exit 1
fi
fi
NGINX_CONF_PATH="/etc/nginx/conf.d/portal.conf"
# 输出配置到文件
echo "server {
listen 80;
server_name it-portal.qunhequnhe.com;
root /portal/frontend;
index index.html index.htm;
location / {
try_files \$uri \$uri/ /index.html;
}
# 添加其他配置,如需要反向代理或者其他功能时
# location /api/ {
# proxy_pass http://backend_server;
# ...
# }
# 错误页面配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# 日志配置
access_log /var/log/nginx/your_domain_access.log;
error_log /var/log/nginx/your_domain_error.log;
}" | sudo tee "$NGINX_CONF_PATH"
# 重启 Nginx 以应用配置
sudo systemctl restart nginx
# 检查重启是否成功
if [ $? -ne 0 ]; then
echo "Nginx 启动失败,脚本结束。"
exit 1
fi
echo "Nginx 配置已写入 $NGINX_CONF_PATH,并已重启 Nginx。"
# 解压前端文件到指定目录
rm -rf $FRONTEND_DIR
unzip -q $BASE_DIR/portal-frontend.zip -d $FRONTEND_DIR
# 清理下载的 zip 文件
rm -rf $BASE_DIR/portal-frontend.zip
echo '==========依赖包下载完成=========='
# Portal service script
SERVICE_SCRIPT="#!/bin/bash
SERVICE_NAME='portal-service'
JAR_PATH='/portal/portal.jar'
CONFIG_LOCATION='--spring.config.location=/portal/application.properties'
LOG_PATH='/portal/logs'
PID_FILE='/var/run/\${SERVICE_NAME}.pid'
start() {
echo 'Starting \$SERVICE_NAME...'
if [ -f '\$PID_FILE' ] && kill -0 \"\$(cat '\$PID_FILE')\"; then
echo '\$SERVICE_NAME is already running.'
exit 1
fi
nohup /usr/bin/java -jar \$JAR_PATH \$CONFIG_LOCATION > \$LOG_PATH/service.log 2>&1 &
echo \$! > '\$PID_FILE'
echo '\$SERVICE_NAME started successfully.'
}
stop() {
echo 'Stopping \$SERVICE_NAME...'
if [ ! -f '\$PID_FILE' ] || ! kill -0 \"\$(cat '\$PID_FILE')\"; then
echo '\$SERVICE_NAME is not running.'
exit 1
fi
kill -15 \"\$(cat '\$PID_FILE')\" && rm -f '\$PID_FILE'
echo '\$SERVICE_NAME stopped successfully.'
}
restart() {
stop
sleep 2
start
}
case \"\$1\" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo 'Usage: \$0 {start|stop|restart}'
exit 1
;;
esac
exit 0
"
# Save scripts to files
echo "$SERVICE_SCRIPT" > /portal/portal-service.sh
echo "## 企业微信配置
wxwork.agentId=1000494
wxwork.secret=zO_GIKzxHT9wHau7MlpoVMxSh_cimKpKHPQ4jPaPY5I
wxwork.corpId=wxe838eaf3a3855809
## 数据库配置
spring.datasource.master.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.master.jdbc-url=jdbc:mysql://10.101.2.81:32610/it_portal
spring.datasource.master.username=dbuser
spring.datasource.master.password=EFyx5M3za2^W
mybatis.configuration.map-underscore-to-camel-case=true
## Radius 配置
radius.secret=qunhequnhe
## NAS 配置
nas.ip=10.10.200.55
nas.port=2000
## SMS 配置
sms.type=url
sms.url=xxxxxx
## 日志文件配置
logging.config=classpath:log4j2.xml
log.file.path=logs
## SSE 超时时间
spring.mvc.async.request-timeout=-1" | sudo tee "$BASE_DIR"
# Set execute permissions
chmod +x /portal/portal-service.sh
IP_ADDRESS=$(hostname -I | cut -d' ' -f1)
echo '==========程序安装完成=========='
echo "=== Radius 地址:$IP_ADDRESS:1812"
echo "=== Radius 计费地址:$IP_ADDRESS:1813"
echo "=== 认证地址:http://$IP_ADDRESS"
#echo '==========启动程序=========='
#/portal/portal-service.sh start
#echo '==========启动完成=========='