Skip to content

Commit c752682

Browse files
authored
[sled-agent] Avoid races on service import, properties on instances, explicit refresh (#1124)
1 parent 8fa3d3c commit c752682

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

sled-agent/src/instance.rs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use crate::common::instance::{
88
Action as InstanceAction, InstanceStates, PROPOLIS_PORT,
99
};
10-
use crate::illumos::running_zone::{InstalledZone, RunningZone};
10+
use crate::illumos::running_zone::{
11+
InstalledZone, RunCommandError, RunningZone,
12+
};
1113
use crate::illumos::svc::wait_for_service;
1214
use crate::illumos::vnic::VnicAllocator;
1315
use crate::illumos::zone::{AddressRequest, PROPOLIS_ZONE_PREFIX};
@@ -516,37 +518,79 @@ impl Instance {
516518
info!(inner.log, "Created address {} for zone: {}", network, zname);
517519

518520
// 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);
519525
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'");
520562
running_zone.run_cmd(&[
521563
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",
524569
])?;
525570

571+
info!(inner.log, "Setting server address property"; "address" => &server_addr);
526572
running_zone.run_cmd(&[
527573
crate::illumos::zone::SVCCFG,
528574
"-s",
529-
"system/illumos/propolis-server",
575+
&smf_instance_name,
530576
"setprop",
531577
&format!("config/server_addr={}", server_addr),
532578
])?;
533579

580+
info!(inner.log, "Refreshing instance");
534581
running_zone.run_cmd(&[
535582
crate::illumos::zone::SVCCFG,
536583
"-s",
537-
"svc:/system/illumos/propolis-server",
538-
"add",
539-
&format!("vm-{}", inner.propolis_id()),
584+
&smf_instance_name,
585+
"refresh",
540586
])?;
541587

588+
info!(inner.log, "Enabling instance");
542589
running_zone.run_cmd(&[
543590
crate::illumos::zone::SVCADM,
544591
"enable",
545592
"-t",
546-
&format!(
547-
"svc:/system/illumos/propolis-server:vm-{}",
548-
inner.propolis_id()
549-
),
593+
&smf_instance_name,
550594
])?;
551595

552596
info!(inner.log, "Started propolis in zone: {}", zname);

0 commit comments

Comments
 (0)