-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresetServer.js
More file actions
49 lines (36 loc) · 1.61 KB
/
resetServer.js
File metadata and controls
49 lines (36 loc) · 1.61 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
39
40
41
42
43
44
45
46
47
48
49
const {globalDB, localDB} = require("./db.js");
const getFingerprint = require("./getFingerprint.js");
const {getServerDefinition, getServerGroup, hostFromServer, updateKnownHostsForServer} = require("./utils.js");
module.exports = async function(serverKey) {
const serverDef = getServerDefinition(serverKey);
const serverId = serverDef.uniqueId;
const serverGroup = getServerGroup(serverKey);
// Clear any global record of this host being initialised as a control server, so it will be re-initialised
let controlServerInitStatus = globalDB.get(`controlServerInitStatus`).value();
if (controlServerInitStatus && serverId in controlServerInitStatus) {
globalDB.set(`controlServerInitStatus.${serverId}`, false)
.write();
}
// Clear per-project record of the deployment control key being copied to this host, so will be re-copied
let controlKeyCopiedStatus = localDB.get(`controlKeyCopiedStatus`).value();
if (controlKeyCopiedStatus) {
for (const [target, serverIds] of Object.entries(controlKeyCopiedStatus)) {
if (serverId in serverIds) {
localDB.set(`controlKeyCopiedStatus.${target}.${serverId}`, false)
.write();
}
}
}
// Get a new fingerprint
console.log("Getting server fingerprint...");
let fingerprint = await getFingerprint(hostFromServer(serverDef));
// Update global server definition
globalDB.get(`servers.${serverGroup}`)
.find({uniqueId : serverId})
.assign({fingerprint : fingerprint})
.write();
console.log("Updating known_hosts");
// update with *new* fingerprint
updateKnownHostsForServer(serverDef, fingerprint);
console.log("Done resetting server.");
}