2023-11-04 13:50:28 +00:00
|
|
|
const { LogType } = require("loguix")
|
|
|
|
const fs = require("fs")
|
|
|
|
const path = require("path")
|
|
|
|
const { __glob } = require("./global-variables")
|
|
|
|
const clog = new LogType("Services")
|
|
|
|
|
|
|
|
const http = require('http');
|
|
|
|
const https = require('https');
|
|
|
|
|
|
|
|
module.exports.getServiceStatus = function(service) {
|
|
|
|
const protocol = service.startsWith('https') ? https : http;
|
|
|
|
const url = new URL(service);
|
|
|
|
const options = {
|
|
|
|
method: 'HEAD',
|
|
|
|
host: url.hostname,
|
|
|
|
port: url.port,
|
|
|
|
path: url.pathname,
|
|
|
|
};
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const req = protocol.request(options, (res) => {
|
|
|
|
if(res.statusCode !== 502) {
|
|
|
|
resolve("ONLINE");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resolve("OFFLINE");
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
req.on('error', (err) => {
|
|
|
|
resolve("OFFLINE");
|
|
|
|
});
|
|
|
|
|
|
|
|
req.end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.stopService = function(service) {
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
const child_process = require('child_process');
|
2023-11-04 14:35:46 +00:00
|
|
|
if(service == `https://subsonics.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 stop "Subsonics"'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://git.raphix.fr` ) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl stop gitea`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://jenkins.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl stop jenkins `)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
|
|
|
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 stop "Website - Raphix"'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://cv.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 stop "CV - Raphael"'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `http://omega.raphix.fr:2333`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl stop lavalink `)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
|
|
|
} else {
|
|
|
|
resolve(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.startService = function(service) {
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
const child_process = require('child_process');
|
2023-11-04 14:35:46 +00:00
|
|
|
if(service == `https://subsonics.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 start /home/gitlab-ci/subsonic.config.js'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:19:37 +00:00
|
|
|
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://git.raphix.fr` ) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl start gitea`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://jenkins.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl start jenkins `)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
|
|
|
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 start /home/gitlab-ci/website.config.js'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://cv.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 start /home/gitlab-ci/cv.config.js'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `http://omega.raphix.fr:2333`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl start lavalink `)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
|
|
|
} else {
|
|
|
|
resolve(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.restartService = function(service) {
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
const child_process = require('child_process');
|
2023-11-04 14:35:46 +00:00
|
|
|
if(service == `https://subsonics.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 restart "Subsonics"'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://git.raphix.fr` ) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl restart gitea`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://jenkins.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl restart jenkins `)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
|
|
|
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 restart "Website - Raphix"'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `https://cv.raphix.fr`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@alpha.raphix.fr sudo -S -u gitlab-ci 'pm2 restart "CV - Raphael"'`)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
2023-11-04 14:35:46 +00:00
|
|
|
} else if(service == `http://omega.raphix.fr:2333`) {
|
|
|
|
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl restart lavalink `)
|
2023-11-04 13:50:28 +00:00
|
|
|
resolve("OK")
|
|
|
|
} else {
|
|
|
|
resolve(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|