Skip to content

Commit ca38923

Browse files
authored
Merge pull request #312 from CESSProject/hotfix/handover
fix: make current release data directory failed
2 parents cfbc58f + 3b377ed commit ca38923

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

scripts/docker/ceseal/gramine/handover.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from "https://deno.land/std/path/mod.ts";
22
import { readStringDelim } from "https://deno.land/std/io/mod.ts";
33
import { copySync } from "https://deno.land/std/fs/copy.ts";
44
import { sortBy } from "https://deno.land/[email protected]/collections/sort_by.ts";
5-
import { ensureDir, exists } from "https://deno.land/[email protected]/fs/mod.ts";
5+
import { exists } from "https://deno.land/[email protected]/fs/mod.ts";
66
// import { sleep } from "https://deno.land/x/sleep/mod.ts";
77

88
const LOG_PREFIX = "[Handover🤝]"
@@ -88,16 +88,33 @@ async function killPreviousCeseal(version: number) {
8888
]);
8989

9090
if (code === 0) {
91-
const pid = new TextDecoder().decode(rawOutput);
92-
log(`the previous version ${version} ceseal pid: ${pid}`);
93-
const p = Deno.run({ cmd: ["bash", "-c", `kill -9 ${pid}`] });
94-
await p.status();
91+
const pid = parseInt(new TextDecoder().decode(rawOutput));
92+
log(`kill the previous version ${version} ceseal pid: ${pid}`);
93+
Deno.kill(pid, "SIGKILL");
9594
} else {
9695
const errorString = new TextDecoder().decode(rawError);
9796
log(errorString);
9897
}
9998
}
10099

100+
function ensureDataDir(dataDir: string) {
101+
try {
102+
const fileInfo = Deno.lstatSync(dataDir);
103+
if (fileInfo.isSymlink) {
104+
const target = Deno.readLinkSync(dataDir);
105+
Deno.mkdirSync(target, { recursive: true });
106+
}
107+
} catch (err) {
108+
if (err.name === "NotFound") {
109+
Deno.mkdirSync(dataDir, { recursive: true });
110+
} else {
111+
throw err;
112+
}
113+
}
114+
try { Deno.mkdirSync(path.join(dataDir, "protected_files"), { recursive: true }) } catch (err) { console.log(err) }
115+
try { Deno.mkdirSync(path.join(dataDir, "storage_files"), { recursive: true }) } catch (err) { console.log(err) }
116+
}
117+
101118
const currentPath = await Deno.realPath("/opt/ceseal/releases/current");
102119
const currentVersion = currentPath.split("/").pop();
103120
log(`Current ${currentPath}`)
@@ -128,8 +145,8 @@ const previousPath = `/opt/ceseal/backups/${previousVersion}`;
128145
log(`Previous ${previousPath}`);
129146

130147
const previousStoragePath = path.join(previousPath, "data/storage_files");
131-
const currentProtectedPath = path.join(currentPath, "data/protected_files");
132-
const currentStoragePath = path.join(currentPath, "data/storage_files");
148+
const currentDataDir = path.join(currentPath, "data");
149+
const currentStoragePath = path.join(currentDataDir, "storage_files");
133150

134151
log("starting");
135152
try { Deno.removeSync("/tmp/ceseal.log") } catch (_err) { }
@@ -146,16 +163,8 @@ try {
146163

147164
// Waiting old bin start, I'm thinking it's good to not get from api but just dump a file then pass to the new one?
148165
// await sleep(30)
149-
try {
150-
await ensureDir(currentProtectedPath);
151-
} catch (err) {
152-
console.error(err.message)
153-
}
154-
try {
155-
await ensureDir(currentStoragePath);
156-
} catch (err) {
157-
console.error(err.message)
158-
}
166+
167+
ensureDataDir(currentDataDir);
159168

160169
const command = new Deno.Command(`/opt/ceseal/releases/current/gramine-sgx`, {
161170
args: [

0 commit comments

Comments
 (0)