Skip to content

Commit 49aab77

Browse files
hannesmreynir
authored andcommitted
albatrossd: on startup, back up state file, fixes #203
1 parent 26dd65f commit 49aab77

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Diff for: daemon/albatrossd.ml

+5
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ let jump _ systemd influx tmpdir dbdir =
178178
match Vmm_vmmd.restore_state () with
179179
| Error (`Msg msg) -> Logs.err (fun m -> m "bailing out: %s" msg)
180180
| Ok (old_unikernels, policies) ->
181+
let file = "state.started" in
182+
(match Vmm_unix.backup file with
183+
| Ok () -> Logs.info (fun m -> m "backing up state to %s" file)
184+
| Error `Msg msg -> Logs.err (fun m -> m "backing up state failed: %s" msg)
185+
| Error `NoFile -> Logs.err (fun m -> m "backing up state failed - no file"));
181186
let policies, old_p = Vmm_trie.insert Name.root root_policy policies in
182187
Option.iter (fun p ->
183188
if not (Policy.equal p root_policy) then

Diff for: src/vmm_unix.ml

+10-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let close_no_err fd = try close fd with _ -> ()
108108
(* own code starts here
109109
(c) 2017, 2018 Hannes Mehnert, all rights reserved *)
110110

111-
let dump, restore =
111+
let dump, restore, backup =
112112
let state_file ?(name = "state") () =
113113
if Fpath.is_seg name then
114114
Fpath.(!dbdir / name)
@@ -130,6 +130,15 @@ let dump, restore =
130130
let* exists = Bos.OS.File.exists state_file in
131131
if exists then
132132
Bos.OS.File.read state_file
133+
else Error `NoFile),
134+
(fun ?name backup ->
135+
let state_file = state_file ?name ()
136+
and backup = state_file ~name:backup ()
137+
in
138+
let* exists = Bos.OS.File.exists state_file in
139+
if exists then
140+
let cmd = Bos.Cmd.(v "cp" % p state_file % p backup) in
141+
Bos.OS.Cmd.(run_out cmd |> out_null |> success)
133142
else Error `NoFile)
134143

135144
let block_sub = "block"

Diff for: src/vmm_unix.mli

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ val dump : ?name:string -> string -> (unit, [> `Msg of string ]) result
3838

3939
val restore : ?name:string -> unit -> (string, [> `Msg of string | `NoFile ]) result
4040

41+
val backup : ?name:string -> string -> (unit, [> `Msg of string | `NoFile ]) result
42+
4143
val unikernel_device : Unikernel.t -> (string, [> `Msg of string ]) result
4244

4345
val manifest_devices_match : bridges:(string * string option * Macaddr.t option) list ->

0 commit comments

Comments
 (0)