From e82a91cbc3523400038cf91af8101c46c9702b5c Mon Sep 17 00:00:00 2001 From: "Bill.W" <0xbillw@gmail.com> Date: Wed, 21 Feb 2024 16:08:22 +0000 Subject: [PATCH 1/2] fix: make current release data directory failed --- scripts/docker/ceseal/gramine/handover.ts | 36 +++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/scripts/docker/ceseal/gramine/handover.ts b/scripts/docker/ceseal/gramine/handover.ts index 17c74e0c..5b025e49 100644 --- a/scripts/docker/ceseal/gramine/handover.ts +++ b/scripts/docker/ceseal/gramine/handover.ts @@ -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/std@0.214.0/collections/sort_by.ts"; -import { ensureDir, exists } from "https://deno.land/std@0.214.0/fs/mod.ts"; +import { exists } from "https://deno.land/std@0.214.0/fs/mod.ts"; // import { sleep } from "https://deno.land/x/sleep/mod.ts"; const LOG_PREFIX = "[HandoveršŸ¤]" @@ -98,6 +98,24 @@ async function killPreviousCeseal(version: number) { } } +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}`) @@ -128,8 +146,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) { } @@ -146,16 +164,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: [ From 3b377edd3e72cc1433ee3536884af7409e8b4f91 Mon Sep 17 00:00:00 2001 From: "Bill.W" <0xbillw@gmail.com> Date: Wed, 21 Feb 2024 16:09:40 +0000 Subject: [PATCH 2/2] refactor: use Deno build-in kill function --- scripts/docker/ceseal/gramine/handover.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/docker/ceseal/gramine/handover.ts b/scripts/docker/ceseal/gramine/handover.ts index 5b025e49..ee8cb32c 100644 --- a/scripts/docker/ceseal/gramine/handover.ts +++ b/scripts/docker/ceseal/gramine/handover.ts @@ -88,10 +88,9 @@ 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);