Skip to content

Commit

Permalink
apiserver: use systemd-notify(1)
Browse files Browse the repository at this point in the history
This avoids use of the systemd and libsystemd-sys crates just for
sending the start-up completion message to systemd.
  • Loading branch information
iliana committed Jan 29, 2020
1 parent 6db26bc commit db50e0d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 82 deletions.
1 change: 0 additions & 1 deletion packages/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ path = "pkg.rs"

[build-dependencies]
glibc = { path = "../glibc" }
systemd = { path = "../systemd" }
1 change: 0 additions & 1 deletion packages/workspaces/workspaces.spec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Source200: migration-tmpfiles.conf
Source201: host-containers-tmpfiles.conf

BuildRequires: %{_cross_os}glibc-devel
BuildRequires: %{_cross_os}systemd-devel

%description
%{summary}.
Expand Down
55 changes: 0 additions & 55 deletions workspaces/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions workspaces/api/apiserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
simplelog = "0.7"
snafu = "0.6"
systemd = { version = "0.4.0", default-features = false, features = [], optional = true }
walkdir = "2.2"

[features]
default = ["sd_notify"]

sd_notify = ["systemd"]

[build-dependencies]
cargo-readme = "3.1"

Expand Down
36 changes: 18 additions & 18 deletions workspaces/api/apiserver/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ mod error;
pub use error::Error;

use actix_web::{error::ResponseError, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use snafu::{OptionExt, ResultExt};
use log::info;
use snafu::{ensure, OptionExt, ResultExt};
use std::collections::{HashMap, HashSet};
use std::env;
use std::path::Path;
use std::process::Command;
use std::sync;

use crate::datastore::{Committed, FilesystemDataStore, Key, Value};
Expand All @@ -23,20 +26,20 @@ use std::os::unix::fs::PermissionsExt;
// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=

// sd_notify helper
#[cfg(feature = "sd_notify")]
fn notify_unix_socket_ready() -> Result<()> {
use snafu::ensure;
use systemd::daemon;
let daemon_notify_success = daemon::notify(
true,
[
(daemon::STATE_READY, "1"),
(daemon::STATE_STATUS, "Thar API Server: socket ready"),
]
.into_iter(),
)
.context(error::SystemdNotify)?;
ensure!(daemon_notify_success, error::SystemdNotifyStatus);
if env::var_os("NOTIFY_SOCKET").is_some() {
ensure!(
Command::new("systemd-notify")
.arg("--ready")
.status()
.context(error::SystemdNotify)?
.success(),
error::SystemdNotifyStatus
);
env::remove_var("NOTIFY_SOCKET");
} else {
info!("NOTIFY_SOCKET not set, not calling systemd-notify");
}
Ok(())
}

Expand Down Expand Up @@ -103,10 +106,7 @@ where
set_permissions(socket_path.as_ref(), perms).context(error::SetPermissions { mode })?;

// Notify system manager the UNIX socket has been initialized, so other service units can proceed
#[cfg(feature = "sd_notify")]
{
notify_unix_socket_ready()?;
}
notify_unix_socket_ready()?;

http_server.run().context(error::ServerStart)
}
Expand Down

0 comments on commit db50e0d

Please sign in to comment.