@@ -2,7 +2,7 @@ import * as path from "https://deno.land/std/path/mod.ts";
22import { readStringDelim } from "https://deno.land/std/io/mod.ts" ;
33import { copySync } from "https://deno.land/std/fs/copy.ts" ;
44import { 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
88const 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+
101118const currentPath = await Deno . realPath ( "/opt/ceseal/releases/current" ) ;
102119const currentVersion = currentPath . split ( "/" ) . pop ( ) ;
103120log ( `Current ${ currentPath } ` )
@@ -128,8 +145,8 @@ const previousPath = `/opt/ceseal/backups/${previousVersion}`;
128145log ( `Previous ${ previousPath } ` ) ;
129146
130147const 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
134151log ( "starting" ) ;
135152try { 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