Skip to content

Commit

Permalink
control interface now reports when a units cannot be started because …
Browse files Browse the repository at this point in the history
…some dependencies need to be started first
  • Loading branch information
KillingSpark committed Apr 21, 2020
1 parent 5f01f57 commit 1dd011c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
13 changes: 12 additions & 1 deletion src/control/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,18 @@ pub fn execute_command(
x
};

crate::units::reactivate_unit(id, run_info).map_err(|e| format!("{}", e))?;
match crate::units::reactivate_unit(id, run_info).map_err(|e| format!("{}", e)) {
Err(e) => return Err(e),
Ok(StartResult::WaitForDependencies(deps)) => {
return Err(format!(
"Cannot start unit. It depends on these to be started first {:?}",
deps
))
}
Ok(StartResult::Started(_)) => {
// Happy
}
};
}
Command::Remove(unit_name) => {
let run_info = &mut *run_info.write().unwrap();
Expand Down
27 changes: 4 additions & 23 deletions src/units/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn activate_units_recursive(
};
tpool_copy.execute(next_services_job);
}
Ok(StartResult::WaitForDependencies) => {
Ok(StartResult::WaitForDependencies(_)) => {
// Thats ok. The unit is waiting for more dependencies and will be
// activated again when another dependency has finished starting
}
Expand All @@ -119,7 +119,7 @@ fn activate_units_recursive(
#[derive(Debug)]
pub enum StartResult {
Started(Vec<UnitId>),
WaitForDependencies,
WaitForDependencies(Vec<UnitId>),
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn activate_unit(
};

if !ready {
acc.push(elem);
acc.push(elem.clone());
}
acc
});
Expand All @@ -187,28 +187,9 @@ pub fn activate_unit(
unit.id.name,
unstarted_deps,
);
return Ok(StartResult::WaitForDependencies);
return Ok(StartResult::WaitForDependencies(unstarted_deps));
}

// Check if the unit is needs to be activated
{
// if status is already on Started then allow ignore must be false. This happens when socket activation is happening
// TODO make this relation less weird. Maybe add a separate code path for socket activation
let status_locked = unit.common.status.read().unwrap();
let wait_for_socket_act = *status_locked
== UnitStatus::Started(StatusStarted::WaitingForSocket)
&& !source.is_socket_activation();
let needs_intial_run =
*status_locked == UnitStatus::NeverStarted || status_locked.is_stopped();
if wait_for_socket_act && !needs_intial_run {
trace!(
"Don't activate Unit: {:?}. Has status: {:?}",
unit.id.name,
*status_locked
);
return Ok(StartResult::WaitForDependencies);
}
}
let next_services_ids = unit.common.dependencies.before.clone();

unit.activate(run_info.clone(), source)
Expand Down
3 changes: 1 addition & 2 deletions src/units/deactivate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ pub fn deactivate_units(
pub fn reactivate_unit(
id_to_restart: UnitId,
run_info: &RuntimeInfo,
) -> std::result::Result<(), UnitOperationError> {
) -> std::result::Result<StartResult, UnitOperationError> {
trace!("Reactivation of unit: {:?}. Deactivate", id_to_restart);
deactivate_unit(id_to_restart.clone(), run_info.clone())?;
trace!(
"Reactivation of unit: {:?}. Deactivation ran. Activate again",
id_to_restart
);
crate::units::activate_unit(id_to_restart.clone(), run_info, ActivationSource::Regular)
.map(|_| ())
}

0 comments on commit 1dd011c

Please sign in to comment.