chiark / gitweb /
wip startup protocol
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 23 Dec 2020 18:21:21 +0000 (18:21 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 23 Dec 2020 18:21:21 +0000 (18:21 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/daemon-otter.rs
src/config.rs
wdriver.rs

index 20030eb84d0315a49b0791a329e6272b5d324dec..f44d625af552d611f4ca8ca16c6bfe860eb8eef1 100644 (file)
@@ -174,6 +174,23 @@ impl fairing::Fairing for ContentTypeFixup {
   }
 }
 
+#[derive(Debug,Copy,Clone)]
+struct ReportStartup;
+impl fairing::Fairing for ReportStartup {
+  fn info(&self) -> fairing::Info {
+    fairing::Info {
+      name: "ReportStartup",
+      kind: fairing::Kind::Launch,
+    }
+  }
+  fn on_launch(&self, _rocket: &Rocket) {
+    println!("{}", DAEMON_STARTUP_REPORT);
+    std::io::stdout().flush().unwrap_or_else(
+      |e| warn!("failed to report started: {:?}", &e)
+    );
+  }
+}
+
 #[throws(StartupError)]
 fn main() {
   // todo test suite for cli at least
@@ -182,6 +199,9 @@ fn main() {
   use structopt::StructOpt;
   #[derive(StructOpt)]
   struct Opts {
+    #[structopt(long)]
+    report_startup: bool,
+
     config_filename: Option<String>,
   }
 
@@ -249,7 +269,7 @@ fn main() {
 
   let rconfig = cbuilder.finalize()?;
 
-  let r = rocket::custom(rconfig)
+  let mut r = rocket::custom(rconfig)
     .attach(ContentTypeFixup)
     .attach(helmet)
     .attach(Template::fairing())
@@ -263,6 +283,10 @@ fn main() {
     .mount("/_/src", StaticFiles::from(&c.bundled_sources))
     ;
 
+  if opts.report_startup {
+    r = r.attach(ReportStartup);
+  }
+
   let r = otter::session::mount(r);
   let r = otter::api::mount(r);
 
index bb8bf4c947000d643ce9cc077008e94e8e2f4e20..f9069d10244e9fc31815153939b365df9f1c8624 100644 (file)
@@ -15,6 +15,8 @@ pub const DEFAULT_CONFIG_LEAFNAME : &str = "server.toml";
 
 pub const DEFAULT_SENDMAIL_PROGRAM : &str = "/usr/sbin/sendmail";
 
+pub const DAEMON_STARTUP_REPORT : &str = "otter-daemon started";
+
 #[derive(Deserialize,Debug,Clone)]
 pub struct ServerConfigSpec {
   pub base_dir: Option<String>,
index 61873e41b49b7cbcbe2812045d5a9c8926307c21..92e7ffc21b393ad275442e85037f233f196336b0 100644 (file)
@@ -374,7 +374,9 @@ _ = "error" # rocket
   let server_exe = ds.subst("@target@/debug/daemon-otter");
   (||{
     let mut cmd = Command::new(&server_exe);
-    cmd.arg(CONFIG);
+    cmd
+      .arg("--report-startup")
+      .arg(CONFIG);
     cln.arm_hook(&mut cmd)?;
     cmd
       .spawn().context("spawn")?;