fas_openvpn进程守护
PHP

fas_openvpn进程守护

蓝科迪梦
2024-10-22 / 0 评论 / 24 阅读 / 正在检测是否收录...
/var/www/html/目录下新建monitor.php,开启755权限

原来的守护脚本for循环里加一句:cd /var/www/html/;php monitor.php &>/dev/null



monitor.php如下:

<?php

require('system.php');

$overtime = 10;

$time = time();

$path_log = R.'/monitor.txt';



//log大于3MB则清空

if(filesize($path_log) > 1024*1024*3){

    file_put_contents($path_log, "");

}

if(strstr(end(file($path_log)), date('Y-m-d H:i:s')) != false){

    exit('已经监控过啦');

}



$files[0]["file"] = "openvpn_api/online_1194.txt";

$files[0]["telnet"] =  "systemctl stop openvpn@server1194;systemctl start openvpn@server1194";



$files[1]["file"] = "openvpn_api/online_1195.txt";

$files[1]["telnet"] =  "systemctl stop openvpn@server1195;systemctl start openvpn@server1195";



$files[2]["file"] = "openvpn_api/online_1196.txt";

$files[2]["telnet"] =  "systemctl stop openvpn@server1196;systemctl start openvpn@server1196";



$files[3]["file"] = "openvpn_api/online_1197.txt";

$files[3]["telnet"] =  "systemctl stop openvpn@server1197;systemctl start openvpn@server1197";



$files[4]["file"] = "openvpn_api/user-status-udp.txt";

$files[4]["telnet"] = "systemctl stop openvpn@server-udp;systemctl start openvpn@server-udp";



$msg = '';

foreach ($files as $k => $v){

    $arr = [

        'file'    => $v['file'],

        'uptime'  => date("Y-m-d H:i:s",filemtime($v['file'])),

        'nowtime' => date("Y-m-d H:i:s",time()),

    ];

//    var_export($arr);

    if((filemtime($v['file'])+$overtime) < $time){

        $msg .= $v['file'];

        systemi("{$v['telnet']}");

        file_put_contents($path_log,date('Y-m-d H:i:s').' 异常重启项:'.json_encode($arr)."\r\n",FILE_APPEND);

    }

}



if($msg == '') {

    echo "暂无异常";

    file_put_contents($path_log,date('Y-m-d H:i:s').' 暂无异常。'."\r\n",FILE_APPEND);



}else{

    echo "异常项已重启:{$msg}";

}

0

评论

博主关闭了所有页面的评论