forked from lix-project/lix-installer
Attempt to minimize steam deck display manager restart risk (#237)
* Attempt to minimize steam deck display manager restart risk * Fiddle a bit more * Prod CI * Be much more specific with services we restart
This commit is contained in:
parent
4884588339
commit
28db9f2953
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -915,7 +915,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nix-installer"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1-unreleased"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"atty",
|
||||
|
|
|
@ -12,14 +12,19 @@ Start a given systemd unit
|
|||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||
pub struct StartSystemdUnit {
|
||||
unit: String,
|
||||
enable: bool,
|
||||
}
|
||||
|
||||
impl StartSystemdUnit {
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
pub async fn plan(unit: impl AsRef<str>) -> Result<StatefulAction<Self>, ActionError> {
|
||||
pub async fn plan(
|
||||
unit: impl AsRef<str>,
|
||||
enable: bool,
|
||||
) -> Result<StatefulAction<Self>, ActionError> {
|
||||
Ok(StatefulAction {
|
||||
action: Self {
|
||||
unit: unit.as_ref().to_string(),
|
||||
enable,
|
||||
},
|
||||
state: ActionState::Uncompleted,
|
||||
})
|
||||
|
@ -47,8 +52,10 @@ impl Action for StartSystemdUnit {
|
|||
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
async fn execute(&mut self) -> Result<(), ActionError> {
|
||||
let Self { unit, .. } = self;
|
||||
let Self { unit, enable } = self;
|
||||
|
||||
match enable {
|
||||
true => {
|
||||
// TODO(@Hoverbear): Handle proxy vars
|
||||
execute_command(
|
||||
Command::new("systemctl")
|
||||
|
@ -60,6 +67,20 @@ impl Action for StartSystemdUnit {
|
|||
)
|
||||
.await
|
||||
.map_err(|e| ActionError::Custom(Box::new(StartSystemdUnitError::Command(e))))?;
|
||||
},
|
||||
false => {
|
||||
// TODO(@Hoverbear): Handle proxy vars
|
||||
execute_command(
|
||||
Command::new("systemctl")
|
||||
.process_group(0)
|
||||
.arg("start")
|
||||
.arg(format!("{unit}"))
|
||||
.stdin(std::process::Stdio::null()),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| ActionError::Custom(Box::new(StartSystemdUnitError::Command(e))))?;
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -73,8 +94,9 @@ impl Action for StartSystemdUnit {
|
|||
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
async fn revert(&mut self) -> Result<(), ActionError> {
|
||||
let Self { unit, .. } = self;
|
||||
let Self { unit, enable } = self;
|
||||
|
||||
if *enable {
|
||||
execute_command(
|
||||
Command::new("systemctl")
|
||||
.process_group(0)
|
||||
|
@ -84,6 +106,7 @@ impl Action for StartSystemdUnit {
|
|||
)
|
||||
.await
|
||||
.map_err(|e| ActionError::Custom(Box::new(StartSystemdUnitError::Command(e))))?;
|
||||
};
|
||||
|
||||
// We do both to avoid an error doing `disable --now` if the user did stop it already somehow.
|
||||
execute_command(
|
||||
|
|
|
@ -152,6 +152,8 @@ impl Planner for SteamDeck {
|
|||
Requires=nix-directory.service\n\
|
||||
ConditionPathIsDirectory=/nix\n\
|
||||
DefaultDependencies=no\n\
|
||||
RequiredBy=nix-daemon.service\n\
|
||||
RequiredBy=nix-daemon.socket\n\
|
||||
\n\
|
||||
[Mount]\n\
|
||||
What={persistence}\n\
|
||||
|
@ -180,15 +182,13 @@ impl Planner for SteamDeck {
|
|||
After=nix.mount\n\
|
||||
Requires=nix-directory.service\n\
|
||||
Requires=nix.mount\n\
|
||||
PropagatesStopTo=nix-directory.service\n\
|
||||
PropagatesStopTo=nix.mount\n\
|
||||
DefaultDependencies=no\n\
|
||||
\n\
|
||||
[Service]\n\
|
||||
Type=oneshot\n\
|
||||
RemainAfterExit=yes\n\
|
||||
ExecStart=/usr/bin/systemctl daemon-reload\n\
|
||||
ExecStart=/usr/bin/systemctl restart --no-block sockets.target timers.target multi-user.target\n\
|
||||
ExecStart=/usr/bin/systemctl restart --no-block nix-daemon.socket\n\
|
||||
\n\
|
||||
[Install]\n\
|
||||
WantedBy=sysinit.target\n\
|
||||
|
@ -213,7 +213,7 @@ impl Planner for SteamDeck {
|
|||
nix_directory_unit.boxed(),
|
||||
create_bind_mount_unit.boxed(),
|
||||
ensure_symlinked_units_resolve_unit.boxed(),
|
||||
StartSystemdUnit::plan("ensure-symlinked-units-resolve.service".to_string())
|
||||
StartSystemdUnit::plan("nix.mount".to_string(), false)
|
||||
.await
|
||||
.map_err(PlannerError::Action)?
|
||||
.boxed(),
|
||||
|
@ -230,6 +230,10 @@ impl Planner for SteamDeck {
|
|||
.await
|
||||
.map_err(PlannerError::Action)?
|
||||
.boxed(),
|
||||
StartSystemdUnit::plan("ensure-symlinked-units-resolve.service".to_string(), true)
|
||||
.await
|
||||
.map_err(PlannerError::Action)?
|
||||
.boxed(),
|
||||
])
|
||||
}
|
||||
|
||||
|
|
3
tests/fixtures/linux/steam-deck.json
vendored
3
tests/fixtures/linux/steam-deck.json
vendored
|
@ -51,7 +51,8 @@
|
|||
{
|
||||
"action": {
|
||||
"action": "start_systemd_unit",
|
||||
"unit": "ensure-symlinked-units-resolve.service"
|
||||
"unit": "ensure-symlinked-units-resolve.service",
|
||||
"enable": true
|
||||
},
|
||||
"state": "Uncompleted"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue