Skip to content

Commit 5af29df

Browse files
committed
Fix detecting local time logic error
1 parent 4101bda commit 5af29df

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ docker logs -f mtproxy
9898

9999
## 使用方式
100100

101+
配置文件 `mtp_config`,如果你想手动修改密钥或者参数请注意格式。
102+
103+
101104
运行服务
102105

103106
```bash
@@ -122,6 +125,12 @@ bash mtproxy.sh stop
122125
bash mtproxy.sh restart
123126
```
124127

128+
重新安装/重新配置
129+
130+
```bash
131+
bash mtproxy.sh reinstall
132+
```
133+
125134
## 卸载安装
126135

127136
因为是绿色版卸载极其简单,直接删除所在目录即可。
@@ -142,6 +151,26 @@ rm -rf /home/mtproxy
142151
cd /home/mtproxy && bash mtproxy.sh start > /dev/null 2>&1 &
143152
```
144153

154+
155+
## 计划任务守护
156+
157+
因为默认官方的 mtproxy 程序存在BUG,pid 大于 65535 时处理存在问题。进程容易坏死和异常退出。
158+
159+
建议通过计划任务去守护进程,编辑方式 `crontab -e`
160+
161+
每分钟检测进程并启动
162+
163+
```bash
164+
* * * * * cd /home/mtproxy && bash mtproxy.sh start > /dev/null 2>&1 &
165+
```
166+
167+
## MTProxy Admin Bot
168+
169+
https://t.me/MTProxybot
170+
> Sorry, an error has occurred during your request. Please try again later.(Code xxxxxx)
171+
172+
如果你在申请绑定代理推广时遇到了此类错误,官方没有给出明确的原因,根据网友反馈,此类问题多出现于账号注册不足与 2~3 年,**建议使用 3 年以上的账号以及未被 banned 的账号。**
173+
145174
## 引用项目
146175

147176
- https://github.com/TelegramMessenger/MTProxy

mtproxy.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ check_sys() {
4848
fi
4949
}
5050

51+
function abs() {
52+
echo ${1#-};
53+
}
54+
5155
function get_ip_public() {
5256
public_ip=$(curl -s https://api.ip.sb/ip -A Mozilla --ipv4)
5357
[ -z "$public_ip" ] && public_ip=$(curl -s ipinfo.io/ip -A Mozilla --ipv4)
@@ -282,9 +286,11 @@ do_kill_process() {
282286
}
283287

284288
do_check_system_datetime_and_update() {
285-
offset=$(ntpdate -q time.google.com | grep -oP 'offset \K[\d]+' | tail -n 1)
289+
dateFromLocal=$(date +%s)
290+
dateFromServer=$(date -d "$(curl -v --silent ip.sb 2>&1 | grep Date | sed -e 's/< Date: //')" +%s)
291+
offset=$(abs $(( "$dateFromServer" - "$dateFromLocal")))
286292
tolerance=60
287-
if [ "$offset" -gt "$tolerance" ] || [ "$offset" -lt "-$tolerance" ];then
293+
if [ "$offset" -gt "$tolerance" ];then
288294
echo "检测到系统时间不同步于世界时间, 即将更新"
289295
ntpdate -u time.google.com
290296
fi

0 commit comments

Comments
 (0)