forked from FxPool/FXMinerProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_install2.sh
More file actions
275 lines (235 loc) · 6.82 KB
/
new_install2.sh
File metadata and controls
275 lines (235 loc) · 6.82 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 变量定义
SERVICE_NAME="fxminerproxy"
INSTALL_DIR="/opt/fxminerproxy"
BIN_NAME="fxminerproxyv3"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
DOWNLOAD_URL="https://github.com/FxPool/FXMinerProxy/archive/refs/tags/13.4.0.tar.gz"
TEMP_DIR="/tmp/fxminerproxy_install"
# 检查是否root用户
check_root() {
if [ "$(id -u)" != "0" ]; then
echo -e "${RED}错误: 此脚本必须以root用户身份运行!${NC}"
exit 1
fi
}
# 检查服务是否已安装
is_installed() {
if [ -f "$SERVICE_FILE" ] || [ -d "$INSTALL_DIR" ]; then
return 0
else
return 1
fi
}
# 检查服务是否已卸载
is_uninstalled() {
if [ ! -f "$SERVICE_FILE" ] && [ ! -d "$INSTALL_DIR" ]; then
return 0
else
return 1
fi
}
# 检查服务是否正在运行
is_running() {
if systemctl is-active --quiet "$SERVICE_NAME"; then
return 0
else
return 1
fi
}
# 设置socket连接上限
set_socket_limit() {
echo -e "${YELLOW}正在设置系统socket连接上限...${NC}"
local current_limit=$(ulimit -n)
local target_limit=1048576
if [ "$current_limit" -lt "$target_limit" ]; then
echo "* soft nofile 1048576" >> /etc/security/limits.conf
echo "* hard nofile 1048576" >> /etc/security/limits.conf
echo "fs.file-max = 1048576" >> /etc/sysctl.conf
sysctl -p > /dev/null
ulimit -n 1048576
echo -e "${GREEN}系统socket连接上限已设置为1048576${NC}"
else
echo -e "${BLUE}系统socket连接上限已经足够高 (当前: $current_limit)${NC}"
fi
}
# 下载并解压FXMinerProxy
download_and_extract() {
echo -e "${YELLOW}正在下载FXMinerProxy...${NC}"
mkdir -p "$TEMP_DIR"
wget -q "$DOWNLOAD_URL" -O "$TEMP_DIR/fxminerproxy.tar.gz"
if [ $? -ne 0 ]; then
echo -e "${RED}下载失败! 请检查网络连接或URL是否正确.${NC}"
exit 1
fi
echo -e "${YELLOW}正在解压文件...${NC}"
tar -xzf "$TEMP_DIR/fxminerproxy.tar.gz" -C "$TEMP_DIR"
# 查找内部压缩包和解压
inner_tar=$(find "$TEMP_DIR" -name "fxminerproxyv3linux.tar.gz")
if [ -z "$inner_tar" ]; then
echo -e "${RED}错误: 未找到内部压缩包fxminerproxyv3linux.tar.gz${NC}"
exit 1
fi
tar -xzf "$inner_tar" -C "$TEMP_DIR"
# 查找二进制文件
BIN_PATH=$(find "$TEMP_DIR" -name "$BIN_NAME" -type f)
if [ -z "$BIN_PATH" ]; then
echo -e "${RED}错误: 未找到可执行文件 $BIN_NAME${NC}"
exit 1
fi
chmod +x "$BIN_PATH"
}
# 安装服务
install_service() {
if is_installed; then
echo -e "${RED}错误: FXMinerProxy服务已经安装!${NC}"
echo -e "请先卸载或使用重启/停止功能"
return 1
fi
echo -e "${YELLOW}正在安装FXMinerProxy服务...${NC}"
# 创建安装目录
mkdir -p "$INSTALL_DIR"
# 移动文件到安装目录
cp "$BIN_PATH" "$INSTALL_DIR/"
# 创建服务文件
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=FXMinerProxy Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$INSTALL_DIR
ExecStart=$INSTALL_DIR/$BIN_NAME
Restart=always
RestartSec=5s
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
EOF
# 重载systemd
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
systemctl start "$SERVICE_NAME"
echo -e "${GREEN}FXMinerProxy服务安装完成!${NC}"
echo -e "安装目录: ${BLUE}$INSTALL_DIR${NC}"
echo -e "服务状态: ${BLUE}systemctl status $SERVICE_NAME${NC}"
}
# 卸载服务
uninstall_service() {
if is_uninstalled; then
echo -e "${RED}错误: FXMinerProxy服务未安装,无需卸载!${NC}"
return 1
fi
echo -e "${YELLOW}正在卸载FXMinerProxy服务...${NC}"
if is_running; then
systemctl stop "$SERVICE_NAME"
fi
if systemctl is-enabled --quiet "$SERVICE_NAME"; then
systemctl disable "$SERVICE_NAME"
fi
if [ -f "$SERVICE_FILE" ]; then
rm -f "$SERVICE_FILE"
systemctl daemon-reload
fi
if [ -d "$INSTALL_DIR" ]; then
rm -rf "$INSTALL_DIR"
fi
echo -e "${GREEN}FXMinerProxy服务已卸载!${NC}"
}
# 启动服务
start_service() {
if is_running; then
echo -e "${YELLOW}服务已经在运行中!${NC}"
return
fi
systemctl start "$SERVICE_NAME"
echo -e "${GREEN}服务已启动!${NC}"
}
# 停止服务
stop_service() {
if ! is_running; then
echo -e "${YELLOW}服务已经停止!${NC}"
return
fi
systemctl stop "$SERVICE_NAME"
echo -e "${GREEN}服务已停止!${NC}"
}
# 重启服务
restart_service() {
systemctl restart "$SERVICE_NAME"
echo -e "${GREEN}服务已重启!${NC}"
echo -e "服务状态: ${BLUE}systemctl status $SERVICE_NAME${NC}"
}
# 查看服务状态
status_service() {
systemctl status "$SERVICE_NAME"
}
# 显示菜单
show_menu() {
clear
echo -e "${GREEN}================================${NC}"
echo -e "${GREEN} FXMinerProxy 服务管理脚本 ${NC}"
echo -e "${GREEN}================================${NC}"
echo -e "1. 安装 FXMinerProxy 服务"
echo -e "2. 启动 FXMinerProxy 服务"
echo -e "3. 停止 FXMinerProxy 服务"
echo -e "4. 重启 FXMinerProxy 服务"
echo -e "5. 查看服务状态"
echo -e "6. 卸载 FXMinerProxy 服务"
echo -e "0. 退出"
echo -e "${GREEN}================================${NC}"
read -p "请输入选项 [0-6]: " option
}
# 主函数
main() {
check_root
while true; do
show_menu
case $option in
1)
set_socket_limit
download_and_extract
install_service
rm -rf "$TEMP_DIR"
read -p "按任意键继续..."
;;
2)
start_service
read -p "按任意键继续..."
;;
3)
stop_service
read -p "按任意键继续..."
;;
4)
restart_service
read -p "按任意键继续..."
;;
5)
status_service
read -p "按任意键继续..."
;;
6)
uninstall_service
read -p "按任意键继续..."
;;
0)
echo -e "${GREEN}退出脚本.${NC}"
exit 0
;;
*)
echo -e "${RED}无效选项,请重新输入!${NC}"
read -p "按任意键继续..."
;;
esac
done
}
# 执行主函数
main