Commit 0549a047 authored by Ahmad's avatar Ahmad

init

parents
Pipeline #193 canceled with stages
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
const axios = require('axios');
const fs = require('fs').promises;
const { exec } = require('child_process');
const util = require('util');
const execPromise = util.promisify(exec);
const BASE_URL = "http://78.46.244.55:2020";
const CONFIG_PATH = '/etc/haproxy/haproxy.cfg';
async function run() {
try {
const data = await getTunnel();
const config = data.config;
await processConfig(config);
} catch (error) {
console.error(error);
}
}
async function processConfig(newConfig) {
try {
const currentConfig = await fs.readFile(CONFIG_PATH, 'utf8');
if (currentConfig !== newConfig) {
await fs.writeFile(CONFIG_PATH, newConfig);
await reloadHAProxy();
}
} catch (error) {
throw error;
}
}
async function reloadHAProxy() {
try {
const { stdout, stderr } = await execPromise('sudo systemctl reload haproxy');
console.log('HAProxy reloaded successfully:', stdout);
if (stderr) {
console.error('Reload error:', stderr);
}
} catch (error) {
throw error;
}
}
async function getTunnel() {
try {
const response = await axios.get(`${BASE_URL}/getTunnel`, { timeout: 3000 });
return response.data;
} catch (error) {
throw 'Error fetching tunnel configuration';
}
}
run();
{
"name": "ha",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.6.8"
}
}
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