-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathstart-bots.js
63 lines (51 loc) · 2.06 KB
/
start-bots.js
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
const exec = require('child_process').exec;
const bots = require('./bots.json');
const recreate = () => {
console.log(`🐳 Checking existing volumes...`);
exec(`docker volume ls -q`, (err, stdout, stderr) => {
const volumes = stdout.split('\n');
bots.forEach((bot) => {
console.log(`🐋 Starting ${bot.name}...`);
const start = () => {
exec(`BOT=${bot.name} VINTED_BOT_ADMIN_IDS=${bot.adminIDs} VINTED_BOT_TOKEN=${bot.token} docker-compose -f docker-compose.yaml -p bot-${bot.name} up -d`, (err, stdout, stderr) => {
if (err) {
console.error(`🐋 ${bot.name} failed to start.`);
console.error(err);
return;
}
console.log(stderr);
});
}
if (volumes.includes(`bot-${bot.name}`)) {
console.log(`📦 ${bot.name} database has been recovered!`);
start();
} else {
exec(`docker volume create bot-${bot.name}`, (err, stdout, stderr) => {
if (!err) {
console.log(`📦 ${bot.name} database has been created!`);
start();
} else console.error(err);
});
}
});
});
};
const restart = process.argv.includes('-restart');
if (restart) {
console.log('👋 Shutting down all bots...');
bots.forEach((bot) => {
exec(`docker-compose -p bot-${bot.name} stop`, (err, stdout, stderr) => {
if (!err) {
exec(`docker-compose -p bot-${bot.name} rm -f`, (err, stdout, stderr) => {
if (!err) {
console.log(`👋 Bot ${bot.name} has been shut down and removed.`);
} else {
console.log(`👎 Failed to remove containers for bot ${bot.name}`);
}
});
}
});
});
} else {
recreate();
}