forked from zhedh/cloudtop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
60 lines (42 loc) · 1.53 KB
/
start.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
#!/bin/bash
set -e
# 同步环境变量
CLOUDTOP_ENV=.env
CLOUDTOP_MONITOR_ENV=cloudtop_monitor/.env
CLOUDTOP_MONITOR_SERVER_ENV=cloudtop_monitor_server/.env
CLOUDTOP_SERVER_ENV=cloudtop_server/.env
if [ -n "$1" ]; then
CLOUDTOP_ENV="$CLOUDTOP_ENV.$1"
fi
echo "CLOUDTOP_ENV: "
echo $CLOUDTOP_ENV
# 将环境变量配置写入各个项目的环境变量
#
while IFS='=' read -r key value; do
# 注意这里我们忽略以井号(#)开头的注释行
[[ $key =~ ^#.* ]] && continue
if grep -q "^$key=" $CLOUDTOP_MONITOR_ENV; then
# 如果存在,使用 sed 命令替换 value
sed -i "" "s|^$key=.*|$key=$value|" $CLOUDTOP_MONITOR_ENV
echo "Key '$key' has been updated with the new value in $CLOUDTOP_MONITOR_ENV"
fi
if grep -q "^$key=" $CLOUDTOP_MONITOR_SERVER_ENV; then
sed -i "" "s|^$key=.*|$key=$value|" $CLOUDTOP_MONITOR_SERVER_ENV
echo "Key '$key' has been updated with the new value in $CLOUDTOP_MONITOR_SERVER_ENV"
fi
if grep -q "^$key=" $CLOUDTOP_SERVER_ENV; then
sed -i "" "s|^$key=.*|$key=$value|" $CLOUDTOP_SERVER_ENV
echo "Key '$key' has been updated with the new value in $CLOUDTOP_SERVER_ENV"
fi
done < $CLOUDTOP_ENV
# 停止正在运行的项目
pm2_list=$(pm2 list)
if [[ $pm2_list == *"online"* ]]; then
pm2 stop all
fi
# 启动 cloudtop_server 项目
cd cloudtop_server && npm run start && cd ../ &&
# 启动 cloudtop_monitor_server 项目
cd cloudtop_monitor_server && npm run start && cd ../ &&
# 启动 cloudtop_monitor 项目
cd cloudtop_monitor && npm run start && cd ../