tangled
alpha
login
or
join now
althaea.zone
/
wire
ALPHA: wire is a tool to deploy nixos systems
wire.althaea.zone/
2
fork
atom
overview
issues
pulls
pipelines
refactor activate step a bit
marshmallow
2 months ago
e13c3c6e
e5da6579
+83
-81
1 changed file
expand all
collapse all
unified
split
wire
lib
src
hive
steps
activate.rs
+83
-81
wire/lib/src/hive/steps/activate.rs
···
8
8
use crate::{
9
9
HiveLibError,
10
10
commands::{CommandArguments, WireCommandChip, run_command},
11
11
-
errors::{ActivationError, NetworkError},
11
11
+
errors::{ActivationError, CommandError, NetworkError},
12
12
hive::node::{Context, ExecuteStep, Goal, SwitchToConfigurationGoal},
13
13
};
14
14
···
69
69
info!("Set system profile");
70
70
71
71
Ok(())
72
72
+
}
73
73
+
74
74
+
async fn reboot(ctx: &Context<'_>) -> Result<(), HiveLibError> {
75
75
+
if !ctx.reboot {
76
76
+
return Ok(());
77
77
+
}
78
78
+
79
79
+
if ctx.should_apply_locally {
80
80
+
error!("Refusing to reboot local machine!");
81
81
+
82
82
+
return Ok(());
83
83
+
}
84
84
+
85
85
+
warn!("Rebooting {name}!", name = ctx.name);
86
86
+
87
87
+
let reboot = run_command(
88
88
+
&CommandArguments::new("reboot now", ctx.modifiers)
89
89
+
.log_stdout()
90
90
+
.on_target(Some(&ctx.node.target))
91
91
+
.elevated(ctx.node),
92
92
+
)
93
93
+
.await?;
94
94
+
95
95
+
// consume result, impossible to know if the machine failed to reboot or we
96
96
+
// simply disconnected
97
97
+
let _ = reboot
98
98
+
.wait_till_success()
99
99
+
.await
100
100
+
.map_err(HiveLibError::CommandError)?;
101
101
+
102
102
+
info!("Rebooted {name}, waiting to reconnect...", name = ctx.name);
103
103
+
104
104
+
if wait_for_ping(ctx).await.is_ok() {
105
105
+
return Ok(());
106
106
+
}
107
107
+
108
108
+
error!(
109
109
+
"Failed to get regain connection to {name} via {host} after reboot.",
110
110
+
name = ctx.name,
111
111
+
host = ctx.node.target.get_preferred_host()?
112
112
+
);
113
113
+
114
114
+
return Err(HiveLibError::NetworkError(
115
115
+
NetworkError::HostUnreachableAfterReboot(ctx.node.target.get_preferred_host()?.to_string()),
116
116
+
));
117
117
+
}
118
118
+
119
119
+
async fn reconnect(
120
120
+
ctx: &Context<'_>,
121
121
+
goal: &SwitchToConfigurationGoal,
122
122
+
error: CommandError,
123
123
+
) -> Result<(), HiveLibError> {
124
124
+
warn!(
125
125
+
"Activation command for {name} exited unsuccessfully.",
126
126
+
name = ctx.name
127
127
+
);
128
128
+
129
129
+
// Bail if the command couldn't of broken the system
130
130
+
// and don't try to regain connection to localhost
131
131
+
if matches!(goal, SwitchToConfigurationGoal::DryActivate) || ctx.should_apply_locally {
132
132
+
return Err(HiveLibError::ActivationError(
133
133
+
ActivationError::SwitchToConfigurationError(*goal, ctx.name.clone(), error),
134
134
+
));
135
135
+
}
136
136
+
137
137
+
if wait_for_ping(ctx).await.is_ok() {
138
138
+
return Err(HiveLibError::ActivationError(
139
139
+
ActivationError::SwitchToConfigurationError(*goal, ctx.name.clone(), error),
140
140
+
));
141
141
+
}
142
142
+
143
143
+
error!(
144
144
+
"Failed to get regain connection to {name} via {host} after {goal} activation.",
145
145
+
name = ctx.name,
146
146
+
host = ctx.node.target.get_preferred_host()?
147
147
+
);
148
148
+
149
149
+
return Err(HiveLibError::NetworkError(
150
150
+
NetworkError::HostUnreachableAfterReboot(ctx.node.target.get_preferred_host()?.to_string()),
151
151
+
));
72
152
}
73
153
74
154
impl ExecuteStep for SwitchToConfiguration {
···
120
200
let result = child.wait_till_success().await;
121
201
122
202
match result {
123
123
-
Ok(_) => {
124
124
-
if !ctx.reboot {
125
125
-
return Ok(());
126
126
-
}
127
127
-
128
128
-
if ctx.should_apply_locally {
129
129
-
error!("Refusing to reboot local machine!");
130
130
-
131
131
-
return Ok(());
132
132
-
}
133
133
-
134
134
-
warn!("Rebooting {name}!", name = ctx.name);
135
135
-
136
136
-
let reboot = run_command(
137
137
-
&CommandArguments::new("reboot now", ctx.modifiers)
138
138
-
.log_stdout()
139
139
-
.on_target(Some(&ctx.node.target))
140
140
-
.elevated(ctx.node),
141
141
-
)
142
142
-
.await?;
143
143
-
144
144
-
// consume result, impossible to know if the machine failed to reboot or we
145
145
-
// simply disconnected
146
146
-
let _ = reboot
147
147
-
.wait_till_success()
148
148
-
.await
149
149
-
.map_err(HiveLibError::CommandError)?;
150
150
-
151
151
-
info!("Rebooted {name}, waiting to reconnect...", name = ctx.name);
152
152
-
153
153
-
if wait_for_ping(ctx).await.is_ok() {
154
154
-
return Ok(());
155
155
-
}
156
156
-
157
157
-
error!(
158
158
-
"Failed to get regain connection to {name} via {host} after reboot.",
159
159
-
name = ctx.name,
160
160
-
host = ctx.node.target.get_preferred_host()?
161
161
-
);
162
162
-
163
163
-
return Err(HiveLibError::NetworkError(
164
164
-
NetworkError::HostUnreachableAfterReboot(
165
165
-
ctx.node.target.get_preferred_host()?.to_string(),
166
166
-
),
167
167
-
));
168
168
-
}
169
169
-
Err(error) => {
170
170
-
warn!(
171
171
-
"Activation command for {name} exited unsuccessfully.",
172
172
-
name = ctx.name
173
173
-
);
174
174
-
175
175
-
// Bail if the command couldn't of broken the system
176
176
-
// and don't try to regain connection to localhost
177
177
-
if matches!(goal, SwitchToConfigurationGoal::DryActivate)
178
178
-
|| ctx.should_apply_locally
179
179
-
{
180
180
-
return Err(HiveLibError::ActivationError(
181
181
-
ActivationError::SwitchToConfigurationError(*goal, ctx.name.clone(), error),
182
182
-
));
183
183
-
}
184
184
-
185
185
-
if wait_for_ping(ctx).await.is_ok() {
186
186
-
return Err(HiveLibError::ActivationError(
187
187
-
ActivationError::SwitchToConfigurationError(*goal, ctx.name.clone(), error),
188
188
-
));
189
189
-
}
190
190
-
191
191
-
error!(
192
192
-
"Failed to get regain connection to {name} via {host} after {goal} activation.",
193
193
-
name = ctx.name,
194
194
-
host = ctx.node.target.get_preferred_host()?
195
195
-
);
196
196
-
197
197
-
return Err(HiveLibError::NetworkError(
198
198
-
NetworkError::HostUnreachableAfterReboot(
199
199
-
ctx.node.target.get_preferred_host()?.to_string(),
200
200
-
),
201
201
-
));
202
202
-
}
203
203
+
Ok(_) => reboot(ctx).await,
204
204
+
Err(error) => reconnect(ctx, goal, error).await,
203
205
}
204
206
}
205
207
}