mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
wait up to 30s for ip address
This commit is contained in:
1
Makefile
1
Makefile
@@ -148,6 +148,7 @@ update-overlay: $(ALL_TARGETS)
|
|||||||
$(call ssh,"sudo systemctl start startd")
|
$(call ssh,"sudo systemctl start startd")
|
||||||
|
|
||||||
wormhole: core/target/$(ARCH)-unknown-linux-musl/release/startbox
|
wormhole: core/target/$(ARCH)-unknown-linux-musl/release/startbox
|
||||||
|
@echo "Paste the following command into the shell of your start-os server:"
|
||||||
@wormhole send core/target/$(ARCH)-unknown-linux-musl/release/startbox 2>&1 | awk -Winteractive '/wormhole receive/ { printf "sudo /usr/lib/startos/scripts/chroot-and-upgrade \"cd /usr/bin && rm startbox && wormhole receive --accept-file %s && chmod +x startbox\"\n", $$3 }'
|
@wormhole send core/target/$(ARCH)-unknown-linux-musl/release/startbox 2>&1 | awk -Winteractive '/wormhole receive/ { printf "sudo /usr/lib/startos/scripts/chroot-and-upgrade \"cd /usr/bin && rm startbox && wormhole receive --accept-file %s && chmod +x startbox\"\n", $$3 }'
|
||||||
|
|
||||||
update: $(ALL_TARGETS)
|
update: $(ALL_TARGETS)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ const LXC_CONTAINER_DIR: &str = "/var/lib/lxc";
|
|||||||
const RPC_DIR: &str = "media/startos/rpc"; // must not be absolute path
|
const RPC_DIR: &str = "media/startos/rpc"; // must not be absolute path
|
||||||
pub const CONTAINER_RPC_SERVER_SOCKET: &str = "service.sock"; // must not be absolute path
|
pub const CONTAINER_RPC_SERVER_SOCKET: &str = "service.sock"; // must not be absolute path
|
||||||
pub const HOST_RPC_SERVER_SOCKET: &str = "host.sock"; // must not be absolute path
|
pub const HOST_RPC_SERVER_SOCKET: &str = "host.sock"; // must not be absolute path
|
||||||
|
const CONTAINER_DHCP_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
pub struct LxcManager {
|
pub struct LxcManager {
|
||||||
containers: Mutex<Vec<Weak<InternedString>>>,
|
containers: Mutex<Vec<Weak<InternedString>>>,
|
||||||
@@ -110,7 +111,6 @@ impl LxcManager {
|
|||||||
pub struct LxcContainer {
|
pub struct LxcContainer {
|
||||||
manager: Weak<LxcManager>,
|
manager: Weak<LxcManager>,
|
||||||
rootfs: OverlayGuard,
|
rootfs: OverlayGuard,
|
||||||
ip: Ipv4Addr,
|
|
||||||
guid: Arc<InternedString>,
|
guid: Arc<InternedString>,
|
||||||
rpc_bind: TmpMountGuard,
|
rpc_bind: TmpMountGuard,
|
||||||
config: LxcConfig,
|
config: LxcConfig,
|
||||||
@@ -171,20 +171,9 @@ impl LxcContainer {
|
|||||||
.arg(&*guid)
|
.arg(&*guid)
|
||||||
.invoke(ErrorKind::Lxc)
|
.invoke(ErrorKind::Lxc)
|
||||||
.await?;
|
.await?;
|
||||||
let ip = String::from_utf8(
|
|
||||||
Command::new("lxc-info")
|
|
||||||
.arg("--name")
|
|
||||||
.arg(&*guid)
|
|
||||||
.arg("-iH")
|
|
||||||
.invoke(ErrorKind::Docker)
|
|
||||||
.await?,
|
|
||||||
)?
|
|
||||||
.trim()
|
|
||||||
.parse()?;
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
manager: Arc::downgrade(manager),
|
manager: Arc::downgrade(manager),
|
||||||
rootfs,
|
rootfs,
|
||||||
ip,
|
|
||||||
guid: Arc::new(guid),
|
guid: Arc::new(guid),
|
||||||
rpc_bind,
|
rpc_bind,
|
||||||
config,
|
config,
|
||||||
@@ -196,8 +185,29 @@ impl LxcContainer {
|
|||||||
self.rootfs.path()
|
self.rootfs.path()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ip(&self) -> Ipv4Addr {
|
pub async fn ip(&self) -> Result<Ipv4Addr, Error> {
|
||||||
self.ip
|
let start = Instant::now();
|
||||||
|
loop {
|
||||||
|
let output = String::from_utf8(
|
||||||
|
Command::new("lxc-info")
|
||||||
|
.arg("--name")
|
||||||
|
.arg(&*self.guid)
|
||||||
|
.arg("-iH")
|
||||||
|
.invoke(ErrorKind::Docker)
|
||||||
|
.await?,
|
||||||
|
)?;
|
||||||
|
let out_str = output.trim();
|
||||||
|
if !out_str.is_empty() {
|
||||||
|
return Ok(out_str.parse()?);
|
||||||
|
}
|
||||||
|
if start.elapsed() > CONTAINER_DHCP_TIMEOUT {
|
||||||
|
return Err(Error::new(
|
||||||
|
eyre!("Timed out waiting for container to acquire DHCP lease"),
|
||||||
|
ErrorKind::Timeout,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rpc_dir(&self) -> &Path {
|
pub fn rpc_dir(&self) -> &Path {
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ impl PersistentContainer {
|
|||||||
}
|
}
|
||||||
let net_service = ctx
|
let net_service = ctx
|
||||||
.net_controller
|
.net_controller
|
||||||
.create_service(s9pk.as_manifest().id.clone(), lxc_container.ip())
|
.create_service(s9pk.as_manifest().id.clone(), lxc_container.ip().await?)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
s9pk,
|
s9pk,
|
||||||
|
|||||||
Reference in New Issue
Block a user