File tree 2 files changed +26
-0
lines changed
buck2_client_ctx/src/daemon/client
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,9 @@ impl<'a> BuckdLifecycle<'a> {
396
396
ParentSlice :: Root ( slice_name. clone ( ) ) ,
397
397
) ) ?;
398
398
let mut cmd = if let Some ( systemd_runner) = & systemd_runner {
399
+ systemd_runner
400
+ . ensure_scope_stopped ( & format ! ( "{}.scope" , & slice_name) )
401
+ . await ?;
399
402
systemd_runner
400
403
. background_command_linux ( daemon_exe, & slice_name, & project_dir. root ( ) )
401
404
. into ( )
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use std::sync::OnceLock;
15
15
16
16
use buck2_core:: fs:: paths:: abs_norm_path:: AbsNormPath ;
17
17
use buck2_util:: process;
18
+ use tracing:: warn;
18
19
19
20
use crate :: init:: ResourceControlConfig ;
20
21
use crate :: init:: ResourceControlStatus ;
@@ -219,6 +220,28 @@ impl SystemdRunner {
219
220
}
220
221
Ok ( ( ) )
221
222
}
223
+
224
+ pub async fn ensure_scope_stopped ( & self , scope : & str ) -> buck2_error:: Result < ( ) > {
225
+ let mut cmd = process:: async_background_command ( "systemctl" ) ;
226
+ cmd. arg ( "is-active" ) . arg ( "--quiet" ) . arg ( "--user" ) . arg ( scope) ;
227
+ // systemctl returns no error if scope is active
228
+ let is_active = cmd. status ( ) . await ?. success ( ) ;
229
+ if is_active {
230
+ warn ! (
231
+ "Transient scope unit {} is already active. Stopping before start a new one." ,
232
+ scope
233
+ ) ;
234
+ self . stop_scope ( scope) . await ?;
235
+ }
236
+ Ok ( ( ) )
237
+ }
238
+
239
+ async fn stop_scope ( & self , scope : & str ) -> buck2_error:: Result < ( ) > {
240
+ let mut cmd = process:: async_background_command ( "systemctl" ) ;
241
+ cmd. arg ( "stop" ) . arg ( "--user" ) . arg ( scope) ;
242
+ cmd. spawn ( ) ?. wait ( ) . await ?;
243
+ Ok ( ( ) )
244
+ }
222
245
}
223
246
224
247
// Helper function to replace a special characters in a cgroup unit name
You can’t perform that action at this time.
0 commit comments