From: Ian Jackson Date: Wed, 23 Dec 2020 18:21:21 +0000 (+0000) Subject: wip startup protocol X-Git-Tag: otter-0.2.0~141 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c390f9af8302ab513df1bac5f92b5b1ff066434a;p=otter.git wip startup protocol Signed-off-by: Ian Jackson --- diff --git a/src/bin/daemon-otter.rs b/src/bin/daemon-otter.rs index 20030eb8..f44d625a 100644 --- a/src/bin/daemon-otter.rs +++ b/src/bin/daemon-otter.rs @@ -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, } @@ -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); diff --git a/src/config.rs b/src/config.rs index bb8bf4c9..f9069d10 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, diff --git a/wdriver.rs b/wdriver.rs index 61873e41..92e7ffc2 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -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")?;