-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-all.js
More file actions
103 lines (85 loc) · 2.7 KB
/
start-all.js
File metadata and controls
103 lines (85 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// start-all.js - Main startup script for Pterodactyl
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('🚀 DTEmpire Bots - Starting all services...');
console.log('📁 Current directory:', __dirname);
console.log('📦 Node version:', process.version);
// Load environment variables
if (fs.existsSync('.env')) {
require('dotenv').config();
console.log('✅ Loaded .env file');
}
// Function to start a bot
function startBot(botName, scriptPath) {
console.log(`\n▶️ Starting ${botName}...`);
const botProcess = spawn('node', [scriptPath], {
stdio: 'inherit',
cwd: __dirname,
env: { ...process.env }
});
botProcess.on('close', (code) => {
console.log(`❌ ${botName} exited with code ${code}`);
console.log(`🔄 Restarting ${botName} in 5 seconds...`);
setTimeout(() => {
startBot(botName, scriptPath);
}, 5000);
});
botProcess.on('error', (error) => {
console.error(`⚠️ ${botName} error:`, error.message);
});
return botProcess;
}
// Check if files exist
const files = ['server.js', 'tts-bot.js'];
let missingFiles = [];
files.forEach(file => {
if (!fs.existsSync(path.join(__dirname, file))) {
missingFiles.push(file);
console.log(`❌ Missing: ${file}`);
}
});
if (missingFiles.length > 0) {
console.log(`\n⚠️ Missing files: ${missingFiles.join(', ')}`);
console.log('📁 Available files:');
fs.readdirSync(__dirname).forEach(file => {
console.log(` - ${file}`);
});
// Try to run what's available
if (fs.existsSync('server.js')) {
console.log('\n✅ Found server.js, starting image bot only...');
startBot('Image Bot', 'server.js');
} else if (fs.existsSync('tts-bot.js')) {
console.log('\n✅ Found tts-bot.js, starting TTS bot only...');
startBot('TTS Bot', 'tts-bot.js');
} else {
console.log('\n❌ No bot files found!');
process.exit(1);
}
} else {
// Start both bots
console.log('✅ All bot files found! Starting both bots...');
const imageBot = startBot('Image Bot', 'server.js');
const ttsBot = startBot('TTS Bot', 'tts-bot.js');
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\n🛑 Received SIGINT, shutting down gracefully...');
imageBot.kill('SIGTERM');
ttsBot.kill('SIGTERM');
setTimeout(() => {
process.exit(0);
}, 3000);
});
process.on('SIGTERM', () => {
console.log('\n🛑 Received SIGTERM, shutting down gracefully...');
imageBot.kill('SIGTERM');
ttsBot.kill('SIGTERM');
setTimeout(() => {
process.exit(0);
}, 3000);
});
// Keep the main process alive
setInterval(() => {
// Just keep alive
}, 1000);
}