-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (54 loc) · 1.58 KB
/
index.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
64
65
66
67
68
69
import ora from "ora";
import mongoose from "mongoose";
import Deployment from "./lib/models/deployment.js";
let running = true;
mongoose.Promise = global.Promise;
export default async function (cli, spinner) {
try {
spinner.text = "Starting up deploy.sh server";
spinner.text = "Connecting to mongo";
await mongoose.connect(cli.mongo);
spinner.text = "Starting existing applications";
const deployments = await Deployment.start({});
spinner.succeed(
`Started ${
deployments ? deployments.length : 0
} deployment(s) successfully`
);
const { default: importServerCommand } = await import("./lib/server.js");
return importServerCommand;
} catch (ex) {
if (
ex.message.indexOf("HTTP code 304") > -1 ||
ex.message.indexOf("(HTTP code 404) no such container") > -1
) {
spinner.warn(`Services already started`);
const { default: importServerCommand } = await import("./lib/server.js");
return importServerCommand;
}
throw new Error(ex);
}
}
async function shutdown() {
if (!running) return;
running = false;
const spinner = ora("Shutting down up deploy.sh server").start();
try {
spinner.text = "Stopping deployments";
const deployments = await Deployment.stop({});
spinner.succeed(
`Shutdown ${
deployments ? deployments.length : 0
} deployment(s) successfully`
);
process.exit(0);
} catch (ex) {
spinner.fail(`
Error on shutdown:
${ex}
`);
process.exit(1);
}
}
process.on("SIGTERM", shutdown);
process.on("SIGINT", shutdown);