OPEN-ISP v0.5 (pickle-lime) — rilis open-source perdana
Aplikasi billing & manajemen ISP (fiber optic) — PWA pelanggan, portal teknisi & kolektor, admin panel lengkap, multi-vendor OLT, RADIUS, WhatsApp/Telegram, pembayaran QRIS. Kredit & lisensi (ISC): - Base kode & repo: alijayanet/billing-rtrw oleh Alijaya Net — terima kasih banyak atas base kode dan repo yang bermanfaat. - Add-on: GoWA, LibreSpeed/OpenSpeedTest, Uptime Kuma, notification-forwarder. - Dikembangkan menjadi OPEN-ISP oleh oxpoe — https://github.com/oxpoe/open-isp
This commit is contained in:
commit
eaf05f2811
280 files changed
+123975
No files matched your search
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Script untuk restart otomatis aplikasi jika terjadi error
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const APP_SCRIPT = 'app-whatsapp-only.js';
|
||||
const LOG_FILE = 'logs/restart.log';
|
||||
const MAX_RESTARTS = 5;
|
||||
const RESTART_DELAY = 10000; // 10 detik
|
||||
|
||||
let restartCount = 0;
|
||||
let isRestarting = false;
|
||||
|
||||
// Fungsi untuk menulis log
|
||||
function writeLog(message) {
|
||||
const timestamp = new Date().toISOString();
|
||||
const logEntry = `[${timestamp}] ${message}\n`;
|
||||
|
||||
// Pastikan direktori logs ada
|
||||
const logDir = path.dirname(LOG_FILE);
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, { recursive: true });
|
||||
}
|
||||
|
||||
fs.appendFileSync(LOG_FILE, logEntry);
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// Fungsi untuk start aplikasi
|
||||
function startApp() {
|
||||
if (isRestarting) {
|
||||
writeLog('App is already restarting, skipping...');
|
||||
return;
|
||||
}
|
||||
|
||||
writeLog(`Starting application (attempt ${restartCount + 1}/${MAX_RESTARTS})`);
|
||||
|
||||
const app = spawn('node', [APP_SCRIPT], {
|
||||
stdio: ['inherit', 'inherit', 'inherit'],
|
||||
detached: false
|
||||
});
|
||||
|
||||
app.on('error', (error) => {
|
||||
writeLog(`Error starting app: ${error.message}`);
|
||||
handleAppError();
|
||||
});
|
||||
|
||||
app.on('exit', (code, signal) => {
|
||||
writeLog(`App exited with code ${code} and signal ${signal}`);
|
||||
|
||||
if (code !== 0 && restartCount < MAX_RESTARTS) {
|
||||
handleAppError();
|
||||
} else if (restartCount >= MAX_RESTARTS) {
|
||||
writeLog(`Maximum restart attempts (${MAX_RESTARTS}) reached. Stopping restart attempts.`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle process termination
|
||||
process.on('SIGINT', () => {
|
||||
writeLog('Received SIGINT, terminating app...');
|
||||
app.kill('SIGINT');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
writeLog('Received SIGTERM, terminating app...');
|
||||
app.kill('SIGTERM');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
// Fungsi untuk handle error aplikasi
|
||||
function handleAppError() {
|
||||
if (isRestarting) return;
|
||||
|
||||
isRestarting = true;
|
||||
restartCount++;
|
||||
|
||||
writeLog(`App crashed, restarting in ${RESTART_DELAY/1000} seconds...`);
|
||||
|
||||
setTimeout(() => {
|
||||
isRestarting = false;
|
||||
startApp();
|
||||
}, RESTART_DELAY);
|
||||
}
|
||||
|
||||
// Main execution
|
||||
writeLog('Starting application with auto-restart enabled');
|
||||
startApp();
|
||||
Reference in new issue
Block a user