|
7 | 7 | use crate::common::instance::{
|
8 | 8 | Action as InstanceAction, InstanceStates, PROPOLIS_PORT,
|
9 | 9 | };
|
10 |
| -use crate::illumos::running_zone::{InstalledZone, RunningZone}; |
| 10 | +use crate::illumos::running_zone::{ |
| 11 | + InstalledZone, RunCommandError, RunningZone, |
| 12 | +}; |
11 | 13 | use crate::illumos::svc::wait_for_service;
|
12 | 14 | use crate::illumos::vnic::VnicAllocator;
|
13 | 15 | use crate::illumos::zone::{AddressRequest, PROPOLIS_ZONE_PREFIX};
|
@@ -516,37 +518,79 @@ impl Instance {
|
516 | 518 | info!(inner.log, "Created address {} for zone: {}", network, zname);
|
517 | 519 |
|
518 | 520 | // Run Propolis in the Zone.
|
| 521 | + let smf_service_name = "svc:/system/illumos/propolis-server"; |
| 522 | + let instance_name = format!("vm-{}", inner.propolis_id()); |
| 523 | + let smf_instance_name = |
| 524 | + format!("{}:{}", smf_service_name, instance_name); |
519 | 525 | let server_addr = SocketAddr::new(inner.propolis_ip, PROPOLIS_PORT);
|
| 526 | + |
| 527 | + // We intentionally do not import the service - it is placed under |
| 528 | + // `/var/svc/manifest`, and should automatically be imported by |
| 529 | + // configd. |
| 530 | + // |
| 531 | + // Insteady, we re-try adding the instance until it succeeds. |
| 532 | + // This implies that the service was added successfully. |
| 533 | + info!( |
| 534 | + inner.log, "Adding service"; "smf_name" => &smf_instance_name |
| 535 | + ); |
| 536 | + backoff::retry_notify( |
| 537 | + backoff::internal_service_policy(), |
| 538 | + || async { |
| 539 | + running_zone |
| 540 | + .run_cmd(&[ |
| 541 | + crate::illumos::zone::SVCCFG, |
| 542 | + "-s", |
| 543 | + smf_service_name, |
| 544 | + "add", |
| 545 | + &instance_name, |
| 546 | + ]) |
| 547 | + .map_err(|e| backoff::BackoffError::transient(e)) |
| 548 | + }, |
| 549 | + |err: RunCommandError, delay| { |
| 550 | + warn!( |
| 551 | + inner.log, |
| 552 | + "Failed to add {} as a service (retrying in {:?}): {}", |
| 553 | + instance_name, |
| 554 | + delay, |
| 555 | + err.to_string() |
| 556 | + ); |
| 557 | + }, |
| 558 | + ) |
| 559 | + .await?; |
| 560 | + |
| 561 | + info!(inner.log, "Adding service property group 'config'"); |
520 | 562 | running_zone.run_cmd(&[
|
521 | 563 | crate::illumos::zone::SVCCFG,
|
522 |
| - "import", |
523 |
| - "/var/svc/manifest/site/propolis-server/manifest.xml", |
| 564 | + "-s", |
| 565 | + &smf_instance_name, |
| 566 | + "addpg", |
| 567 | + "config", |
| 568 | + "astring", |
524 | 569 | ])?;
|
525 | 570 |
|
| 571 | + info!(inner.log, "Setting server address property"; "address" => &server_addr); |
526 | 572 | running_zone.run_cmd(&[
|
527 | 573 | crate::illumos::zone::SVCCFG,
|
528 | 574 | "-s",
|
529 |
| - "system/illumos/propolis-server", |
| 575 | + &smf_instance_name, |
530 | 576 | "setprop",
|
531 | 577 | &format!("config/server_addr={}", server_addr),
|
532 | 578 | ])?;
|
533 | 579 |
|
| 580 | + info!(inner.log, "Refreshing instance"); |
534 | 581 | running_zone.run_cmd(&[
|
535 | 582 | crate::illumos::zone::SVCCFG,
|
536 | 583 | "-s",
|
537 |
| - "svc:/system/illumos/propolis-server", |
538 |
| - "add", |
539 |
| - &format!("vm-{}", inner.propolis_id()), |
| 584 | + &smf_instance_name, |
| 585 | + "refresh", |
540 | 586 | ])?;
|
541 | 587 |
|
| 588 | + info!(inner.log, "Enabling instance"); |
542 | 589 | running_zone.run_cmd(&[
|
543 | 590 | crate::illumos::zone::SVCADM,
|
544 | 591 | "enable",
|
545 | 592 | "-t",
|
546 |
| - &format!( |
547 |
| - "svc:/system/illumos/propolis-server:vm-{}", |
548 |
| - inner.propolis_id() |
549 |
| - ), |
| 593 | + &smf_instance_name, |
550 | 594 | ])?;
|
551 | 595 |
|
552 | 596 | info!(inner.log, "Started propolis in zone: {}", zname);
|
|
0 commit comments