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

init

parent 648edd5f
const express = require('express') const express = require('express')
const app = express() const app = express()
const port = 3000
const shell = require('shelljs') const shell = require('shelljs')
const cron = require('node-cron'); const cron = require('node-cron');
const cronOne = require('node-cron'); const cronOne = require('node-cron');
...@@ -9,6 +8,8 @@ const cronSpeed = require('node-cron'); ...@@ -9,6 +8,8 @@ const cronSpeed = require('node-cron');
const shellExec = require('shell-exec') const shellExec = require('shell-exec')
var decimalPointRegex = /\-?\d+\.\d+/g; var decimalPointRegex = /\-?\d+\.\d+/g;
let port=22
let countReboot = 4 let countReboot = 4
let tryFail = 0 let tryFail = 0
...@@ -57,12 +58,13 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`)) ...@@ -57,12 +58,13 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`))
async function run() { 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') console.log('Reset Proxy')
} }
async function checkProcessWork() { 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')) { if (a.includes('succeeded')) {
tryFail = 0 tryFail = 0
return true return true
...@@ -77,6 +79,10 @@ async function checkProcessWork() { ...@@ -77,6 +79,10 @@ async function checkProcessWork() {
run() run()
} }
function randomInt(low, high) {
return Math.floor(Math.random() * (high - low) + low)
}
cron.schedule('*/10 * * * * *', () => { cron.schedule('*/10 * * * * *', () => {
checkProcessWork() checkProcessWork()
...@@ -114,7 +120,7 @@ async function calculateSpeed() { ...@@ -114,7 +120,7 @@ async function calculateSpeed() {
function sendRate(rx, tx) { function sendRate(rx, tx) {
const request = require('request'); 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) { return new Promise(function (resolve, reject) {
request(url, {timeout: 6000}, function (error, res, body) { request(url, {timeout: 6000}, function (error, res, body) {
resolve(true) 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