利用crontab每个一个小时检查一次frpc监控状态[修复错误部分]

利用crontab每个一个小时检查一次frpc监控状态

我们在lede下使用frp的插件客户端的时候,发现有时候路由器重启或者更新插件的情况frpc没办法重新启动.那么我们需要写个脚本让frpc每隔1个小时检查一下,发现没启动就会自动启动!

首先我们要了解插件目录那哪里?

插件目录:/koolshare/frpc/

脚本自启目录:/etc/init.d

插件脚本:

1
vim /etc/init.d/frpgl

Bash

Copy

脚本代码:

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
#!/bin/sh /etc/rc.common
#
#
START=200
STOP=150

start() {
frpc_count=`ps | grep /koolshare/frpc/frpc | grep -v "grep" | wc -l`
if [ $frpc_count -eq 0 ]; then
echo 没有运行,正在启动...
/koolshare/frpc/frpc -c /koolshare/frpc/frpc.ini &
sleep 1
echo 已启动FRPC

else
echo 已运行,无需启动
fi
}

stop() {
frpc_count=`ps | grep /koolshare/frpc/frpc | grep -v "grep" | wc -l`
if [ $frpc_count -eq 0 ]; then
echo 没有运行,无需停止
else
echo 已运行,正在停止...
kill -9 $(pidof frpc)
sleep 1
echo 已停止FRPC
fi
}

Bash

Copy

赋予脚本权限

1
chmod -R 0777 frpc

Bash

Copy

添加计划任务:

1
2
crontab
*/1 * * * * /etc/init.d/frpgl start 2>/dev/null

Bash

Copy

赋予frpgl脚本权限

1
chmod +x /etc/init.d/frpgl

Bash

Copy

这样就成功了!

下面常用的一些命令!

1
2
3
4
5
6
7
8
/etc/init.d/frpgl start  #启动服务
/etc/init.d/frpgl enable #启用服务自动启动
/etc/init.d/frpgl start #启动服务
/etc/init.d/frpgl stop #停止服务
/etc/init.d/frpgl restart #重启服务
/etc/init.d/frpgl reload #重新加载配置文件(如果失败则重新启动)
/etc/init.d/frpgl enable #启用服务自动启动
/etc/init.d/frpgl disable #禁用服务自动启动

Bash

Copy

2.不用安装插件办法:

进入frp官方下载
按照你的CPU属性下载,Sandy是J1900那么就下载frp_0.20.0_linux_amd64.tar.gz
请对应frps服务器版本下载