package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6

doc/src/miaou-core.core/service_lifecycle.ml.html

Source file service_lifecycle.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)
(* (c) 2025 Nomadic Labs <contact@nomadic-labs.com> *)

[@@@warning "-32-34-37-69"]

[@@@warning "-32-34-37-69"]

type status = Running | Stopped | Failed of string

type t = {
  start : role:string -> service:string -> (unit, string) result;
  stop : role:string -> service:string -> (unit, string) result;
  restart : role:string -> service:string -> (unit, string) result;
  get_status : role:string -> service:string -> (status, string) result;
  install_unit :
    role:string ->
    app_bin_dir:string option ->
    user:string ->
    (unit, string) result;
  write_dropin_node :
    inst:string ->
    data_dir:string ->
    app_bin_dir:string option ->
    (unit, string) result;
  enable_start : role:string -> inst:string -> (unit, string) result;
  enable : role:string -> inst:string -> (unit, string) result;
  disable : role:string -> inst:string -> (unit, string) result;
  remove_instance_files :
    role:string -> inst:string -> remove_data:bool -> (unit, string) result;
}

module Capability = Miaou_interfaces.Capability

(* Use the same capability key instance as the interface so registration by the
   Systemd-backed implementation (which registers the interface key) is visible
   here. Coerce the interface key to this module's type with Obj.magic. *)
let key : t Capability.key =
  Obj.magic
    Miaou_interfaces.Service_lifecycle.key
  [@allow_forbidden "coerce interface key to local type"]

let set v = Capability.set key v

let get () =
  match Capability.get key with
  | Some v -> Some v
  | None -> (
      (* If another module registered the interface-level capability under
         the interface's key, consult it and coerce to our type. This covers
         registration ordering races where the interface registration may
         be visible via the interface module but not via this module's
         local key instance. *)
      match Miaou_interfaces.Service_lifecycle.get () with
      | Some v ->
          Some
            (Obj.magic
               v [@allow_forbidden "coerce interface type to local type"])
      | None -> None)

let require () =
  match get () with
  | Some v -> v
  | None ->
      (* Register a fallback stub that returns Errors. *)
      let start ~role:_ ~service:_ = Error "service lifecycle not available" in
      let stop ~role:_ ~service:_ = Error "service lifecycle not available" in
      let restart ~role:_ ~service:_ =
        Error "service lifecycle not available"
      in
      let get_status ~role:_ ~service:_ =
        Error "service lifecycle not available"
      in
      let install_unit ~role:_ ~app_bin_dir:_ ~user:_ =
        Error "service lifecycle not available"
      in
      let write_dropin_node ~inst:_ ~data_dir:_ ~app_bin_dir:_ =
        Error "service lifecycle not available"
      in
      let enable_start ~role:_ ~inst:_ =
        Error "service lifecycle not available"
      in
      let enable ~role:_ ~inst:_ = Error "service lifecycle not available" in
      let disable ~role:_ ~inst:_ = Error "service lifecycle not available" in
      let remove_instance_files ~role:_ ~inst:_ ~remove_data:_ =
        Error "service lifecycle not available"
      in
      let stub =
        {
          start;
          stop;
          restart;
          get_status;
          install_unit;
          write_dropin_node;
          enable_start;
          enable;
          disable;
          remove_instance_files;
        }
      in
      (* Do NOT persistently register the stub; return it transiently so a
         later real registration (e.g., Systemd_service_lifecycle.register)
         can still override and be observed via the interface key. *)
      stub

let install_unit v ~role ~app_bin_dir ~user =
  v.install_unit ~role ~app_bin_dir ~user

let write_dropin_node v ~inst ~data_dir ~app_bin_dir =
  v.write_dropin_node ~inst ~data_dir ~app_bin_dir

let enable_start v ~role ~inst = v.enable_start ~role ~inst

let enable v ~role ~inst = v.enable ~role ~inst

let disable v ~role ~inst = v.disable ~role ~inst

let start v ~role ~service = v.start ~role ~service

let stop v ~role ~service = v.stop ~role ~service

let restart v ~role ~service = v.restart ~role ~service

let get_status v ~role ~service = v.get_status ~role ~service

let remove_instance_files v ~role ~inst ~remove_data =
  v.remove_instance_files ~role ~inst ~remove_data