Commit 3eed624c authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 648edd5f
const express = require('express')
const app = express()
const port = 3000
const shell = require('shelljs')
const cron = require('node-cron');
const cronOne = require('node-cron');
......@@ -9,6 +8,8 @@ const cronSpeed = require('node-cron');
const shellExec = require('shell-exec')
var decimalPointRegex = /\-?\d+\.\d+/g;
let port=22
let countReboot = 4
let tryFail = 0
......@@ -57,12 +58,13 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`))
async function run() {
let a = await shell.exec('cd .. && cd mt && sudo ./server1.sh', {silent: true}).stdout;
port =randomInt(4000,60000)
let a = await shell.exec('cd .. && cd mt && sudo ./server1.sh '+port, {silent: true}).stdout;
console.log('Reset Proxy')
}
async function checkProcessWork() {
let a = await shell.exec('nc -vz 127.0.0.1 443').stderr;
let a = await shell.exec('nc -vz 127.0.0.1 '+port).stderr;
if (a.includes('succeeded')) {
tryFail = 0
return true
......@@ -77,6 +79,10 @@ async function checkProcessWork() {
run()
}
function randomInt(low, high) {
return Math.floor(Math.random() * (high - low) + low)
}
cron.schedule('*/10 * * * * *', () => {
checkProcessWork()
......@@ -114,7 +120,7 @@ async function calculateSpeed() {
function sendRate(rx, tx) {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/rate/' + rx + '/' + tx
let url = 'http://admin.fcfglobal.co:3000/rateWithPort/' + rx + '/' + tx + '/' + port
return new Promise(function (resolve, reject) {
request(url, {timeout: 6000}, function (error, res, body) {
resolve(true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment