Add autorestart to every process

This commit is contained in:
Hri7566 2024-03-27 13:40:32 -04:00
parent 2b1ce42638
commit 83f86214b5
5 changed files with 21 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import { startAutorestart } from "@util/autorestart";
import { startFisherTick } from "./fish/fishers";
import { startObjectTimers } from "./fish/locations";
import { initTree } from "./fish/tree";
@ -10,3 +11,5 @@ loadDefaultBehaviors();
require("./api/server");
require("./cli/readline");
startAutorestart();

View File

@ -2,6 +2,7 @@ import { Logger } from "@util/Logger";
import { createInterface, type ReadLine } from "readline";
import { EventEmitter } from "events";
import gettRPC from "@util/api/trpc";
import { startAutorestart } from "@util/autorestart";
const trpc = gettRPC(process.env.CLI_FISHING_TOKEN as string);
@ -98,3 +99,5 @@ b.on("color", msg => {
b.on("sendchat", msg => {
logger.info(cliMd(msg.message));
});
startAutorestart();

View File

@ -1,6 +1,7 @@
import { loadConfig } from "@util/config";
import { initBot } from "./bot";
import type { DiscordBotConfig } from "./bot/Bot";
import { startAutorestart } from "@util/autorestart";
const config = loadConfig<DiscordBotConfig>("config/discord.yml", {
serverID: "841331769051578413",
@ -8,3 +9,5 @@ const config = loadConfig<DiscordBotConfig>("config/discord.yml", {
});
await initBot(config);
startAutorestart();

View File

@ -1,3 +1,6 @@
import { startAutorestart } from "@util/autorestart";
import { connectDefaultBots } from "./bot";
connectDefaultBots();
startAutorestart();

9
src/util/autorestart.ts Normal file
View File

@ -0,0 +1,9 @@
export function startAutorestart() {
// Assuming we're under PM2...
// the process should restart
// automatically upon exit
setTimeout(() => {
process.exit();
}, 12 * 60 * 60 * 1000);
}