A migrations/20230420053341_add_status_to_servers_table.ts => migrations/20230420053341_add_status_to_servers_table.ts +17 -0
@@ 0,0 1,17 @@
+import { Knex } from "knex";
+
+import {SCHEMA_NAME} from "../src/environment";
+
+
+export async function up(knex: Readonly<Knex>): Promise<void> {
+ await knex.schema.withSchema(SCHEMA_NAME).table('servers', (table) => {
+ table
+ .boolean('started')
+ .notNullable()
+ .comment('Used to determine if a server is to be restarted automatically when it is detected offline');
+ });
+}
+
+export function down(): void {
+ return;
+}
M src/types/dbTypes.ts => src/types/dbTypes.ts +1 -0
@@ 10,6 10,7 @@ export interface ServersTable {
comment: string,
container_id: string,
image_id: string,
+ started: boolean,
}
export enum userLevels {
A src/utils/dMonUtils.ts => src/utils/dMonUtils.ts +22 -0
@@ 0,0 1,22 @@
+import {ServersTable} from "../types/dbTypes";
+
+import {dbConn} from "./dbUtils";
+import {checkIfOnline, restartSingleServer} from "./dockerUtils";
+import {generateLogger} from "./loggerUtils";
+
+const log = generateLogger('dMonUtils.ts');
+
+export const runDMon = async (): Promise<void> => {
+ const db = dbConn();
+
+ const servers = await db<ServersTable>('servers').select('*').where('started', true);
+ servers.forEach(server => {
+ checkIfOnline(server.container_id).then(res => {
+ if (!res) {
+ restartSingleServer(server.container_id);
+ }
+ }).catch(e => {
+ log.error(e);
+ });
+ });
+}<
\ No newline at end of file