wora 0.0.21

A framework for building applications (daemons, etc) that run in different environments (Linux, Kubernetes, etc).
Documentation
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
use std::env;
use std::path::{Path, PathBuf};

use async_trait::async_trait;
use directories::ProjectDirs;
#[cfg(target_os = "macos")]
use launchd::Launchd;
#[cfg(target_os = "macos")]
use launchd::sockets::{Socket, SocketFamily, SocketOptions, SocketType, Sockets};
#[cfg(target_os = "linux")]
use sd_notify::NotifyState;
#[cfg(target_os = "linux")]
use std::os::linux::net::SocketAddrExt;
#[cfg(target_os = "macos")]
use std::os::unix::io::RawFd;
#[cfg(all(target_family = "unix", target_os = "linux"))]
use std::os::unix::net::SocketAddr;
#[cfg(target_family = "unix")]
use std::os::unix::net::UnixDatagram;
#[cfg(target_os = "macos")]
use thiserror::Error;
use tokio::sync::mpsc::Receiver;
use tokio::sync::mpsc::Sender;
use tokio::task::JoinHandle;
use tracing::{debug, trace};

use crate::dirs::Dirs;
use crate::errors::{SetupFailure, VfsError};
use crate::events::{ControlEvent, Event};
use crate::exec::AsyncExecutor;
use crate::exec_unix::UnixLike;
use crate::{RuntimeSignal, SignalMapper, WFS, Wora};

fn first_env_path(var_name: &str) -> Option<PathBuf> {
    env::var_os(var_name).and_then(|value| value.to_string_lossy().split(':').find(|segment| !segment.is_empty()).map(PathBuf::from))
}

fn existing_path_or(path: impl AsRef<Path>, fallback: PathBuf) -> PathBuf {
    if path.as_ref().exists() { path.as_ref().to_path_buf() } else { fallback }
}

async fn create_executor_dirs(fs: impl WFS, dirs: &[PathBuf]) -> Result<(), SetupFailure> {
    for dir in dirs {
        trace!("exec:setup:io:create dir:{:?}: trying", dir);
        fs.create_dir(dir).await?;
        trace!("exec:setup:io:create dir:{:?}: success", dir);
    }
    Ok(())
}

#[cfg(target_family = "unix")]
fn send_unix_datagram(socket: &str, payload: &str) -> Result<(), SetupFailure> {
    let datagram = UnixDatagram::unbound()?;

    #[cfg(target_os = "linux")]
    if let Some(abstract_name) = socket.strip_prefix('@') {
        let addr = SocketAddr::from_abstract_name(abstract_name.as_bytes())?;
        datagram.connect_addr(&addr)?;
        let _sent = datagram.send(payload.as_bytes())?;
        return Ok(());
    }

    datagram.connect(socket)?;
    let _sent = datagram.send(payload.as_bytes())?;
    Ok(())
}

#[cfg(not(target_family = "unix"))]
fn send_unix_datagram(_socket: &str, _payload: &str) -> Result<(), SetupFailure> {
    Ok(())
}

/// launchd executor API error.
#[cfg(target_os = "macos")]
#[derive(Debug, Error)]
pub enum LaunchdExecutorError {
    #[error("launchd plist")]
    Plist(#[from] launchd::Error),
    #[error("launchd socket activation")]
    SocketActivation(#[from] raunch::Error),
}

/// Service-manager scope for systemd executors.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SystemdScope {
    /// System service managed by PID 1.
    System,
    /// Per-user service managed by the user service manager.
    User,
}

/// Executor for systemd-managed services.
///
/// This executor uses the standard `NOTIFY_SOCKET` transport for readiness and
/// stopping notifications and consumes directory environment variables such as
/// `STATE_DIRECTORY`, `CACHE_DIRECTORY`, and `RUNTIME_DIRECTORY` when they are
/// provided by systemd.
#[derive(Clone, Debug)]
pub struct SystemdExecutor {
    unix: UnixLike,
    scope: SystemdScope,
    notify_socket: Option<String>,
}

impl SystemdExecutor {
    /// Create a system-scoped systemd executor.
    pub async fn system(app_name: &str) -> Self {
        let runtime_dir = first_env_path("RUNTIME_DIRECTORY").unwrap_or_else(|| PathBuf::from(format!("/run/{app_name}")));
        let cache_dir = first_env_path("CACHE_DIRECTORY").unwrap_or_else(|| PathBuf::from(format!("/var/cache/{app_name}")));
        let data_dir = first_env_path("STATE_DIRECTORY").unwrap_or_else(|| PathBuf::from(format!("/var/lib/{app_name}")));
        let metadata_dir = first_env_path("CONFIGURATION_DIRECTORY").unwrap_or_else(|| PathBuf::from(format!("/etc/{app_name}")));
        let log_dir = first_env_path("LOGS_DIRECTORY").unwrap_or_else(|| PathBuf::from(format!("/var/log/{app_name}")));
        let secrets_dir = existing_path_or("/run/secrets", runtime_dir.join("secrets"));

        let mut unix = UnixLike::new(app_name).await;
        unix.dirs = Dirs {
            root_dir: PathBuf::from("/"),
            log_root_dir: log_dir,
            metadata_root_dir: metadata_dir,
            data_root_dir: data_dir,
            runtime_root_dir: runtime_dir,
            cache_root_dir: cache_dir,
            secrets_root_dir: secrets_dir,
        };

        Self {
            unix,
            scope: SystemdScope::System,
            notify_socket: env::var("NOTIFY_SOCKET").ok(),
        }
    }

    /// Create a user-scoped systemd executor.
    pub async fn user(app_name: &str) -> Result<Self, VfsError> {
        let proj_dirs = ProjectDirs::from("com", "wora", app_name).ok_or_else(|| VfsError::ProjectDirsUnavailable(app_name.to_string()))?;
        let runtime_dir = first_env_path("RUNTIME_DIRECTORY")
            .or_else(|| env::var_os("XDG_RUNTIME_DIR").map(PathBuf::from).map(|base| base.join(app_name)))
            .unwrap_or_else(|| proj_dirs.runtime_dir().unwrap_or(std::env::temp_dir().as_path()).join(app_name));
        let cache_dir = first_env_path("CACHE_DIRECTORY").unwrap_or_else(|| proj_dirs.cache_dir().to_path_buf());
        let data_dir = first_env_path("STATE_DIRECTORY").unwrap_or_else(|| proj_dirs.data_dir().to_path_buf());
        let metadata_dir = first_env_path("CONFIGURATION_DIRECTORY").unwrap_or_else(|| proj_dirs.config_dir().to_path_buf());
        let log_dir = first_env_path("LOGS_DIRECTORY").unwrap_or_else(|| proj_dirs.data_local_dir().to_path_buf());
        let secrets_dir = existing_path_or(runtime_dir.join("secrets"), cache_dir.join("secrets"));

        let mut unix = UnixLike::new(app_name).await;
        unix.dirs = Dirs {
            root_dir: PathBuf::from("/"),
            log_root_dir: log_dir,
            metadata_root_dir: metadata_dir,
            data_root_dir: data_dir,
            runtime_root_dir: runtime_dir,
            cache_root_dir: cache_dir,
            secrets_root_dir: secrets_dir,
        };

        Ok(Self {
            unix,
            scope: SystemdScope::User,
            notify_socket: env::var("NOTIFY_SOCKET").ok(),
        })
    }

    /// Override the notify socket path used by readiness/stopping hooks.
    pub fn with_notify_socket(mut self, notify_socket: impl Into<String>) -> Self {
        self.notify_socket = Some(notify_socket.into());
        self
    }

    /// Inject a control-event receiver for deterministic testing.
    pub fn with_control_event_receiver(mut self, receiver: Receiver<ControlEvent>) -> Self {
        self.unix = self.unix.clone().with_control_event_receiver(receiver);
        self
    }

    /// Inject a runtime signal receiver for deterministic testing and custom signal mapping.
    pub fn with_signal_receiver(mut self, receiver: Receiver<RuntimeSignal>) -> Self {
        self.unix = self.unix.clone().with_signal_receiver(receiver);
        self
    }

    fn send_notify_message(&self, payload: String) -> Result<(), SetupFailure> {
        #[cfg(target_os = "linux")]
        {
            match &self.notify_socket {
                Some(socket) => {
                    debug!("systemd:notify socket:{} payload:{}", socket, payload.replace('\n', ";"));
                    send_unix_datagram(socket, &payload)
                }
                None => {
                    let mut states = Vec::new();
                    for line in payload.lines() {
                        if let Some(message) = line.strip_prefix("STATUS=") {
                            states.push(NotifyState::Status(message));
                        } else if line == "READY=1" {
                            states.push(NotifyState::Ready);
                        } else if line == "STOPPING=1" {
                            states.push(NotifyState::Stopping);
                        } else if let Some(pid) = line.strip_prefix("MAINPID=") {
                            states.push(NotifyState::MainPid(pid.parse()?));
                        } else {
                            states.push(NotifyState::Custom(line));
                        }
                    }
                    sd_notify::notify(&states).map_err(SetupFailure::IO)
                }
            }
        }

        #[cfg(not(target_os = "linux"))]
        {
            match &self.notify_socket {
                Some(socket) => {
                    debug!("systemd:notify socket:{} payload:{}", socket, payload.replace('\n', ";"));
                    send_unix_datagram(socket, &payload)
                }
                None => Ok(()),
            }
        }
    }
}

#[async_trait]
impl<AppEv: Send + Sync + 'static, AppMetric: Send + Sync> AsyncExecutor<AppEv, AppMetric> for SystemdExecutor {
    fn id(&self) -> &'static str {
        match self.scope {
            SystemdScope::System => "systemd-system",
            SystemdScope::User => "systemd-user",
        }
    }

    fn dirs(&self) -> &Dirs {
        &self.unix.dirs
    }

    async fn setup(&mut self, _wora: &Wora<AppEv, AppMetric>, fs: impl WFS) -> Result<(), SetupFailure> {
        self.unix.chdir_root()?;
        self.unix.create_directories(fs).await
    }

    async fn spawn_runtime_event_sources(&self, sender: Sender<Event<AppEv>>) -> Result<Vec<JoinHandle<()>>, SetupFailure> {
        self.unix.spawn_runtime_event_sources(sender).await
    }

    async fn spawn_runtime_event_sources_with_signal_mapper(
        &self,
        sender: Sender<Event<AppEv>>,
        signal_mapper: SignalMapper<AppEv>,
    ) -> Result<Vec<JoinHandle<()>>, SetupFailure> {
        self.unix.spawn_runtime_event_sources_with_signal_mapper(sender, signal_mapper).await
    }

    async fn on_runtime_ready(&self, app_name: &str, _dirs: &Dirs, _fs: impl WFS) -> Result<(), SetupFailure> {
        self.send_notify_message(format!(
            "READY=1\nSTATUS={} ready via {}\nMAINPID={}",
            app_name,
            match self.scope {
                SystemdScope::System => "systemd-system",
                SystemdScope::User => "systemd-user",
            },
            std::process::id()
        ))
    }

    async fn is_ready(&self, _wora: &Wora<AppEv, AppMetric>, _fs: impl WFS) -> bool {
        true
    }

    async fn on_runtime_draining(&self, app_name: &str, _dirs: &Dirs, _fs: impl WFS) -> Result<(), SetupFailure> {
        self.send_notify_message(format!("STATUS={} draining", app_name))
    }

    async fn on_runtime_stopping(&self, app_name: &str, _dirs: &Dirs, _fs: impl WFS) -> Result<(), SetupFailure> {
        self.send_notify_message(format!("STOPPING=1\nSTATUS={} stopping", app_name))
    }

    async fn end(&self, _wora: &Wora<AppEv, AppMetric>, _fs: impl WFS) {}
}

/// Service-manager scope for launchd executors.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LaunchdScope {
    /// A per-user LaunchAgent.
    Agent,
    /// A system-wide LaunchDaemon.
    Daemon,
}

/// Executor for macOS launchd-managed workloads.
///
/// launchd does not provide a readiness protocol comparable to `sd_notify`, so
/// this executor focuses on native directory layout and signal translation.
#[derive(Clone, Debug)]
pub struct LaunchdExecutor {
    unix: UnixLike,
    scope: LaunchdScope,
    socket_names: Vec<String>,
}

impl LaunchdExecutor {
    /// Create a LaunchAgent-style executor.
    pub async fn agent(app_name: &str) -> Result<Self, VfsError> {
        let proj_dirs = ProjectDirs::from("com", "wora", app_name).ok_or_else(|| VfsError::ProjectDirsUnavailable(app_name.to_string()))?;
        let mut unix = UnixLike::new(app_name).await;
        unix.dirs = Dirs {
            root_dir: PathBuf::from("/"),
            log_root_dir: proj_dirs.data_local_dir().to_path_buf(),
            metadata_root_dir: proj_dirs.preference_dir().to_path_buf(),
            data_root_dir: proj_dirs.data_dir().to_path_buf(),
            runtime_root_dir: env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir).join(app_name),
            cache_root_dir: proj_dirs.cache_dir().to_path_buf(),
            secrets_root_dir: proj_dirs.cache_dir().join("secrets"),
        };
        Ok(Self {
            unix,
            scope: LaunchdScope::Agent,
            socket_names: vec![],
        })
    }

    /// Create a LaunchDaemon-style executor.
    pub async fn daemon(app_name: &str) -> Self {
        let mut unix = UnixLike::new(app_name).await;
        unix.dirs = Dirs {
            root_dir: PathBuf::from("/"),
            log_root_dir: PathBuf::from(format!("/Library/Logs/{app_name}")),
            metadata_root_dir: PathBuf::from(format!("/Library/Preferences/{app_name}")),
            data_root_dir: PathBuf::from(format!("/Library/Application Support/{app_name}")),
            runtime_root_dir: existing_path_or("/var/run", PathBuf::from("/tmp")).join(app_name),
            cache_root_dir: PathBuf::from(format!("/Library/Caches/{app_name}")),
            secrets_root_dir: existing_path_or("/var/db", PathBuf::from("/tmp")).join(app_name).join("secrets"),
        };
        Self {
            unix,
            scope: LaunchdScope::Daemon,
            socket_names: vec![],
        }
    }

    /// Register a launchd socket activation name for generated plist output.
    pub fn with_socket_name(mut self, socket_name: impl Into<String>) -> Self {
        self.socket_names.push(socket_name.into());
        self
    }

    /// Return the configured launchd socket activation names.
    pub fn socket_names(&self) -> &[String] {
        &self.socket_names
    }

    /// Inject a control-event receiver for deterministic testing.
    pub fn with_control_event_receiver(mut self, receiver: Receiver<ControlEvent>) -> Self {
        self.unix = self.unix.clone().with_control_event_receiver(receiver);
        self
    }

    /// Inject a runtime signal receiver for deterministic testing and custom signal mapping.
    pub fn with_signal_receiver(mut self, receiver: Receiver<RuntimeSignal>) -> Self {
        self.unix = self.unix.clone().with_signal_receiver(receiver);
        self
    }

    /// Build a launchd plist job description for this executor.
    #[cfg(target_os = "macos")]
    pub fn launchd_job<P: AsRef<Path>>(&self, label: &str, program: P, program_arguments: Vec<String>) -> Result<Launchd, LaunchdExecutorError> {
        let mut job = Launchd::new(label, program)?
            .with_program_arguments(program_arguments)
            .with_working_directory(&self.unix.dirs.data_root_dir)?
            .with_standard_out_path(self.unix.dirs.log_root_dir.join("stdout.log"))?
            .with_standard_error_path(self.unix.dirs.log_root_dir.join("stderr.log"))?
            .with_environment_variables(std::collections::HashMap::from([(
                "WORA_EXECUTOR".to_string(),
                match self.scope {
                    LaunchdScope::Agent => "launchd-agent".to_string(),
                    LaunchdScope::Daemon => "launchd-daemon".to_string(),
                },
            )]))
            .run_at_load();

        for socket_name in &self.socket_names {
            let socket = Socket::new(socket_name, SocketOptions::new().with_type(SocketType::Stream).with_family(SocketFamily::Unix));
            job = job.with_socket(Sockets::from(socket));
        }

        Ok(job)
    }

    /// Activate a launchd-managed socket by name.
    #[cfg(target_os = "macos")]
    pub fn activate_socket(&self, socket_name: &str) -> Result<Vec<RawFd>, LaunchdExecutorError> {
        Ok(raunch::activate_socket(socket_name)?)
    }
}

#[async_trait]
impl<AppEv: Send + Sync + 'static, AppMetric: Send + Sync> AsyncExecutor<AppEv, AppMetric> for LaunchdExecutor {
    fn id(&self) -> &'static str {
        match self.scope {
            LaunchdScope::Agent => "launchd-agent",
            LaunchdScope::Daemon => "launchd-daemon",
        }
    }

    fn dirs(&self) -> &Dirs {
        &self.unix.dirs
    }

    async fn setup(&mut self, _wora: &Wora<AppEv, AppMetric>, fs: impl WFS) -> Result<(), SetupFailure> {
        self.unix.chdir_root()?;
        self.unix.create_directories(fs).await
    }

    async fn spawn_runtime_event_sources(&self, sender: Sender<Event<AppEv>>) -> Result<Vec<JoinHandle<()>>, SetupFailure> {
        self.unix.spawn_runtime_event_sources(sender).await
    }

    async fn spawn_runtime_event_sources_with_signal_mapper(
        &self,
        sender: Sender<Event<AppEv>>,
        signal_mapper: SignalMapper<AppEv>,
    ) -> Result<Vec<JoinHandle<()>>, SetupFailure> {
        self.unix.spawn_runtime_event_sources_with_signal_mapper(sender, signal_mapper).await
    }

    async fn is_ready(&self, _wora: &Wora<AppEv, AppMetric>, _fs: impl WFS) -> bool {
        true
    }

    async fn end(&self, _wora: &Wora<AppEv, AppMetric>, _fs: impl WFS) {}
}

/// Executor for generic container or Kubernetes-style deployments.
///
/// This executor assumes the orchestrator owns config and secret mounts while
/// the workload owns writable runtime, cache, data, and optional readiness
/// files.
#[derive(Clone, Debug)]
pub struct ContainerExecutor {
    unix: UnixLike,
    readiness_file: Option<PathBuf>,
    termination_log: Option<PathBuf>,
}

impl ContainerExecutor {
    /// Create a container-oriented executor with Kubernetes-friendly defaults.
    pub async fn new(app_name: &str) -> Self {
        let writable_root = std::env::temp_dir().join(app_name);
        let runtime_root = writable_root.join("run");
        let metadata_root = if Path::new("/etc/config").exists() {
            PathBuf::from("/etc/config")
        } else {
            writable_root.join("config")
        };
        let secrets_root = if Path::new("/var/run/secrets/kubernetes.io/serviceaccount").exists() {
            PathBuf::from("/var/run/secrets/kubernetes.io/serviceaccount")
        } else if Path::new("/var/run/secrets").exists() {
            PathBuf::from("/var/run/secrets")
        } else {
            writable_root.join("secrets")
        };

        let mut unix = UnixLike::new(app_name).await;
        unix.dirs = Dirs {
            root_dir: PathBuf::from("/"),
            log_root_dir: writable_root.join("logs"),
            metadata_root_dir: metadata_root,
            data_root_dir: existing_path_or("/data", writable_root.join("data")),
            runtime_root_dir: runtime_root.clone(),
            cache_root_dir: writable_root.join("cache"),
            secrets_root_dir: secrets_root,
        };

        Self {
            unix,
            readiness_file: None,
            termination_log: None,
        }
    }

    /// Configure a file to create when the runtime is ready.
    pub fn with_readiness_file(mut self, path: impl Into<PathBuf>) -> Self {
        self.readiness_file = Some(path.into());
        self
    }

    /// Configure a termination log file written during shutdown.
    pub fn with_termination_log(mut self, path: impl Into<PathBuf>) -> Self {
        self.termination_log = Some(path.into());
        self
    }

    /// Inject a control-event receiver for deterministic testing.
    pub fn with_control_event_receiver(mut self, receiver: Receiver<ControlEvent>) -> Self {
        self.unix = self.unix.clone().with_control_event_receiver(receiver);
        self
    }

    /// Inject a runtime signal receiver for deterministic testing and custom signal mapping.
    pub fn with_signal_receiver(mut self, receiver: Receiver<RuntimeSignal>) -> Self {
        self.unix = self.unix.clone().with_signal_receiver(receiver);
        self
    }
}

#[async_trait]
impl<AppEv: Send + Sync + 'static, AppMetric: Send + Sync> AsyncExecutor<AppEv, AppMetric> for ContainerExecutor {
    fn id(&self) -> &'static str {
        "container"
    }

    fn dirs(&self) -> &Dirs {
        &self.unix.dirs
    }

    async fn setup(&mut self, _wora: &Wora<AppEv, AppMetric>, fs: impl WFS) -> Result<(), SetupFailure> {
        self.unix.chdir_root()?;
        create_executor_dirs(
            fs,
            &[
                self.unix.dirs.log_root_dir.clone(),
                self.unix.dirs.metadata_root_dir.clone(),
                self.unix.dirs.data_root_dir.clone(),
                self.unix.dirs.runtime_root_dir.clone(),
                self.unix.dirs.cache_root_dir.clone(),
                self.unix.dirs.secrets_root_dir.clone(),
            ],
        )
        .await
    }

    async fn spawn_runtime_event_sources(&self, sender: Sender<Event<AppEv>>) -> Result<Vec<JoinHandle<()>>, SetupFailure> {
        self.unix.spawn_runtime_event_sources(sender).await
    }

    async fn spawn_runtime_event_sources_with_signal_mapper(
        &self,
        sender: Sender<Event<AppEv>>,
        signal_mapper: SignalMapper<AppEv>,
    ) -> Result<Vec<JoinHandle<()>>, SetupFailure> {
        self.unix.spawn_runtime_event_sources_with_signal_mapper(sender, signal_mapper).await
    }

    async fn on_runtime_ready(&self, app_name: &str, _dirs: &Dirs, fs: impl WFS) -> Result<(), SetupFailure> {
        if let Some(path) = &self.readiness_file {
            if let Some(parent) = path.parent() {
                fs.create_dir(parent).await?;
            }
            fs.write(path, format!("ready:{}\n", app_name).as_bytes()).await?;
        }
        Ok(())
    }

    async fn is_ready(&self, _wora: &Wora<AppEv, AppMetric>, _fs: impl WFS) -> bool {
        true
    }

    async fn on_runtime_draining(&self, _app_name: &str, _dirs: &Dirs, fs: impl WFS) -> Result<(), SetupFailure> {
        if let Some(path) = &self.readiness_file {
            match fs.remove_file(path).await {
                Ok(_) => {}
                Err(VfsError::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {}
                Err(err) => return Err(SetupFailure::Vfs(err)),
            }
        }

        Ok(())
    }

    async fn on_runtime_stopping(&self, app_name: &str, _dirs: &Dirs, fs: impl WFS) -> Result<(), SetupFailure> {
        if let Some(path) = &self.termination_log {
            if let Some(parent) = path.parent() {
                fs.create_dir(parent).await?;
            }
            fs.write(path, format!("stopping:{}\n", app_name).as_bytes()).await?;
        }

        Ok(())
    }

    async fn end(&self, _wora: &Wora<AppEv, AppMetric>, _fs: impl WFS) {}
}