Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make current release data directory failed #312

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions scripts/docker/ceseal/gramine/handover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "https://deno.land/std/path/mod.ts";
import { readStringDelim } from "https://deno.land/std/io/mod.ts";
import { copySync } from "https://deno.land/std/fs/copy.ts";
import { sortBy } from "https://deno.land/[email protected]/collections/sort_by.ts";
import { ensureDir, exists } from "https://deno.land/[email protected]/fs/mod.ts";
import { exists } from "https://deno.land/[email protected]/fs/mod.ts";
// import { sleep } from "https://deno.land/x/sleep/mod.ts";

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

if (code === 0) {
const pid = new TextDecoder().decode(rawOutput);
log(`the previous version ${version} ceseal pid: ${pid}`);
const p = Deno.run({ cmd: ["bash", "-c", `kill -9 ${pid}`] });
await p.status();
const pid = parseInt(new TextDecoder().decode(rawOutput));
log(`kill the previous version ${version} ceseal pid: ${pid}`);
Deno.kill(pid, "SIGKILL");
} else {
const errorString = new TextDecoder().decode(rawError);
log(errorString);
}
}

function ensureDataDir(dataDir: string) {
try {
const fileInfo = Deno.lstatSync(dataDir);
if (fileInfo.isSymlink) {
const target = Deno.readLinkSync(dataDir);
Deno.mkdirSync(target, { recursive: true });
}
} catch (err) {
if (err.name === "NotFound") {
Deno.mkdirSync(dataDir, { recursive: true });
} else {
throw err;
}
}
try { Deno.mkdirSync(path.join(dataDir, "protected_files"), { recursive: true }) } catch (err) { console.log(err) }
try { Deno.mkdirSync(path.join(dataDir, "storage_files"), { recursive: true }) } catch (err) { console.log(err) }
}

const currentPath = await Deno.realPath("/opt/ceseal/releases/current");
const currentVersion = currentPath.split("/").pop();
log(`Current ${currentPath}`)
Expand Down Expand Up @@ -128,8 +145,8 @@ const previousPath = `/opt/ceseal/backups/${previousVersion}`;
log(`Previous ${previousPath}`);

const previousStoragePath = path.join(previousPath, "data/storage_files");
const currentProtectedPath = path.join(currentPath, "data/protected_files");
const currentStoragePath = path.join(currentPath, "data/storage_files");
const currentDataDir = path.join(currentPath, "data");
const currentStoragePath = path.join(currentDataDir, "storage_files");

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

// 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?
// await sleep(30)
try {
await ensureDir(currentProtectedPath);
} catch (err) {
console.error(err.message)
}
try {
await ensureDir(currentStoragePath);
} catch (err) {
console.error(err.message)
}

ensureDataDir(currentDataDir);

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