Commit 9bebf2df authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 63199ca0
...@@ -8,7 +8,7 @@ const cronSpeed = require('node-cron'); ...@@ -8,7 +8,7 @@ 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=5 let port = 5
let countReboot = 4 let countReboot = 4
...@@ -58,13 +58,17 @@ app.listen(3000, () => console.log(`Example app listening on port 3000!`)) ...@@ -58,13 +58,17 @@ app.listen(3000, () => console.log(`Example app listening on port 3000!`))
async function run() { async function run() {
port =randomInt(4000,60000) let portRes = await getPort()
let a = await shell.exec('cd .. && cd mt && sudo ./server1.sh '+port, {silent: true}).stdout; if (portRes === '0' || portRes === '443')
port = randomInt(4000, 60000)
else
port=parseInt(portRes)
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 '+port).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
...@@ -131,6 +135,19 @@ function sendRate(rx, tx) { ...@@ -131,6 +135,19 @@ function sendRate(rx, tx) {
} }
function getPort() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/getPort'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
cronSpeed.schedule(' */5 * * * * *', () => { cronSpeed.schedule(' */5 * * * * *', () => {
return calculateSpeed() return calculateSpeed()
......
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