-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·67 lines (52 loc) · 1.59 KB
/
deploy.sh
File metadata and controls
executable file
·67 lines (52 loc) · 1.59 KB
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
#!/bin/bash
# 获取当前脚本所在的目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 检查 mosquitto 是否已安装
if ! command -v mosquitto >/dev/null 2>&1; then
echo "📦 Mosquitto 未检测到,开始离线安装..."
# 执行 install_mosquitto.sh
if [ -x "$SCRIPT_DIR/mosquitto-offline/install_mosquitto.sh" ]; then
cd "$SCRIPT_DIR/mosquitto-offline"
./install_mosquitto.sh
else
echo "❌ 找不到 install_mosquitto.sh 或没有执行权限"
exit 1
fi
else
echo "✅ Mosquitto 已安装,跳过安装步骤。"
fi
# 停止并禁用旧服务
systemctl stop SophonSystem.service >/dev/null 2>&1
systemctl disable SophonSystem.service >/dev/null 2>&1
systemctl stop nginx >/dev/null 2>&1
systemctl disable nginx >/dev/null 2>&1
SOURCE_DIR="$SCRIPT_DIR"
TARGET_DIR="/opt/ai_box"
echo "📂 Installing AI Box via symlink..."
# 删除旧目录
sudo rm -rf "$TARGET_DIR"
# 建立软连接
sudo ln -s "$SOURCE_DIR" "$TARGET_DIR"
echo "🛠️ Creating systemd service..."
# 写 systemd 服务文件
sudo tee /etc/systemd/system/ai_box.service > /dev/null <<EOF
[Unit]
Description=AI Box Service
After=network.target
[Service]
Type=forking
ExecStart=$TARGET_DIR/run_all.sh
ExecStop=$TARGET_DIR/stop_all.sh
Restart=always
User=root
WorkingDirectory=$TARGET_DIR
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable ai_box
echo "✅ Installation complete!"
echo "You can now use:"
echo " sudo systemctl start ai_box"
echo " sudo systemctl stop ai_box"
echo " sudo systemctl restart ai_box"