Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
38 lines (34 loc) · 1.69 KB
/
Copy pathmain.js
File metadata and controls
38 lines (34 loc) · 1.69 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
import 'dotenv/config';
import database from './database/index.js';
import app from './app/index.js';
import notifications from './app/services/notifications.js';
import db from './app/utils/db.js';
import { createShutdownScheduler, createWakeScheduler } from './app/services/shutdown-schedules.js';
import { dispatchScheduledShutdown } from './app/services/scheduled-shutdown.js';
import { dispatchScheduledWake } from './app/services/wake-schedules.js';
import writeLogo from './app/utils/writeLogo.js';
import { encryptLegacySshKeys } from './app/utils/ssh-key-vault.js';
(async () => {
writeLogo();
await database.runMigrations();
await encryptLegacySshKeys(db);
createShutdownScheduler({
db, dispatch: dispatchScheduledShutdown,
warn: (instanceId, { minutes, dueAt, time, timezone }) => notifications.forMachine(instanceId, {
type: 'shutdown_warning', title: 'Scheduled shutdown soon',
message: `Scheduled to shut down in ${minutes} minute${minutes === 1 ? '' : 's'}, at ${time} (${timezone}).`,
expiresAt: dueAt.getTime(), phone: true
}),
onResult: (instanceId, result) => notifications.forMachine(instanceId, {
type: 'scheduled_shutdown', title: 'Scheduled shutdown result', message: result
})
}).start();
createWakeScheduler({
db, dispatch: dispatchScheduledWake,
onResult: (instanceId, result) => notifications.forMachine(instanceId, {
type: 'scheduled_wake', title: 'Scheduled wake result', message: result
})
}).start();
const port = process.env.WAKE_HTTP_PORT || 3000;
app.listen(port, () => console.log(`Web server is running on port ${port}`));
})();