@@ -9,6 +9,7 @@ use clap::{Parser, Subcommand};
9
9
use futures:: stream:: { self , StreamExt , TryStreamExt } ;
10
10
use indicatif:: { MultiProgress , ProgressBar , ProgressStyle } ;
11
11
use omicron_package:: { parse, BuildCommand , DeployCommand } ;
12
+ use omicron_sled_agent:: cleanup_networking_resources;
12
13
use omicron_sled_agent:: zone;
13
14
use omicron_zone_package:: config:: Config ;
14
15
use omicron_zone_package:: config:: ExternalPackage ;
@@ -17,6 +18,10 @@ use omicron_zone_package::package::Package;
17
18
use omicron_zone_package:: package:: Progress ;
18
19
use rayon:: prelude:: * ;
19
20
use ring:: digest:: { Context as DigestContext , Digest , SHA256 } ;
21
+ use slog:: info;
22
+ use slog:: o;
23
+ use slog:: Drain ;
24
+ use slog:: Logger ;
20
25
use std:: env;
21
26
use std:: fs:: create_dir_all;
22
27
use std:: path:: { Path , PathBuf } ;
@@ -298,6 +303,7 @@ fn do_install(
298
303
config : & Config ,
299
304
artifact_dir : & Path ,
300
305
install_dir : & Path ,
306
+ log : & Logger ,
301
307
) -> Result < ( ) > {
302
308
create_dir_all ( & install_dir) . map_err ( |err| {
303
309
anyhow ! ( "Cannot create installation directory: {}" , err)
@@ -323,10 +329,11 @@ fn do_install(
323
329
324
330
let src = tarfile. as_path ( ) ;
325
331
let dst = install_dir. join ( src. strip_prefix ( artifact_dir) ?) ;
326
- println ! (
327
- "Installing Service: {} -> {}" ,
328
- src. to_string_lossy( ) ,
329
- dst. to_string_lossy( )
332
+ info ! (
333
+ log,
334
+ "Installing service" ;
335
+ "src" => %src. to_string_lossy( ) ,
336
+ "dst" => %dst. to_string_lossy( ) ,
330
337
) ;
331
338
std:: fs:: copy ( & src, & dst) ?;
332
339
Ok ( ( ) )
@@ -346,10 +353,11 @@ fn do_install(
346
353
for service_name in global_zone_service_names {
347
354
let tar_path = install_dir. join ( format ! ( "{}.tar" , service_name) ) ;
348
355
let service_path = install_dir. join ( service_name) ;
349
- println ! (
350
- "Unpacking {} to {}" ,
351
- tar_path. to_string_lossy( ) ,
352
- service_path. to_string_lossy( )
356
+ info ! (
357
+ log,
358
+ "Unpacking service tarball" ;
359
+ "tar_path" => %tar_path. to_string_lossy( ) ,
360
+ "service_path" => %service_path. to_string_lossy( ) ,
353
361
) ;
354
362
355
363
let tar_file = std:: fs:: File :: open ( & tar_path) ?;
@@ -366,8 +374,9 @@ fn do_install(
366
374
. join ( & package. service_name )
367
375
. join ( "pkg" )
368
376
. join ( "manifest.xml" ) ;
369
- println ! (
370
- "Installing bootstrap service from {}" ,
377
+ info ! (
378
+ log,
379
+ "Installing boostrap service from {}" ,
371
380
manifest_path. to_string_lossy( )
372
381
) ;
373
382
smf:: Config :: import ( ) . run ( & manifest_path) ?;
@@ -425,7 +434,11 @@ fn remove_all_unless_already_removed<P: AsRef<Path>>(path: P) -> Result<()> {
425
434
Ok ( ( ) )
426
435
}
427
436
428
- fn remove_all_except < P : AsRef < Path > > ( path : P , to_keep : & [ & str ] ) -> Result < ( ) > {
437
+ fn remove_all_except < P : AsRef < Path > > (
438
+ path : P ,
439
+ to_keep : & [ & str ] ,
440
+ log : & Logger ,
441
+ ) -> Result < ( ) > {
429
442
let dir = match path. as_ref ( ) . read_dir ( ) {
430
443
Ok ( dir) => dir,
431
444
Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => return Ok ( ( ) ) ,
@@ -434,9 +447,9 @@ fn remove_all_except<P: AsRef<Path>>(path: P, to_keep: &[&str]) -> Result<()> {
434
447
for entry in dir {
435
448
let entry = entry?;
436
449
if to_keep. contains ( & & * ( entry. file_name ( ) . to_string_lossy ( ) ) ) {
437
- println ! ( " Keeping: '{}'", entry. path( ) . to_string_lossy( ) ) ;
450
+ info ! ( log , " Keeping: '{}'", entry. path( ) . to_string_lossy( ) ) ;
438
451
} else {
439
- println ! ( " Removing: '{}'", entry. path( ) . to_string_lossy( ) ) ;
452
+ info ! ( log , " Removing: '{}'", entry. path( ) . to_string_lossy( ) ) ;
440
453
if entry. metadata ( ) ?. is_dir ( ) {
441
454
remove_all_unless_already_removed ( entry. path ( ) ) ?;
442
455
} else {
@@ -447,27 +460,32 @@ fn remove_all_except<P: AsRef<Path>>(path: P, to_keep: &[&str]) -> Result<()> {
447
460
Ok ( ( ) )
448
461
}
449
462
450
- fn do_uninstall (
463
+ async fn do_uninstall (
451
464
config : & Config ,
452
465
artifact_dir : & Path ,
453
466
install_dir : & Path ,
467
+ log : & Logger ,
454
468
) -> Result < ( ) > {
455
- println ! ( "Removing all Omicron zones" ) ;
469
+ info ! ( log , "Removing all Omicron zones" ) ;
456
470
uninstall_all_omicron_zones ( ) ?;
457
- println ! ( "Uninstalling all packages" ) ;
471
+ info ! ( log , "Uninstalling all packages" ) ;
458
472
uninstall_all_packages ( config) ;
459
- println ! ( "Removing artifacts in: {}" , artifact_dir. to_string_lossy( ) ) ;
473
+ info ! ( log , "Removing artifacts in: {}" , artifact_dir. to_string_lossy( ) ) ;
460
474
461
475
const ARTIFACTS_TO_KEEP : & [ & str ] =
462
476
& [ "clickhouse" , "cockroachdb" , "xde" , "console-assets" , "downloads" ] ;
463
- remove_all_except ( artifact_dir, ARTIFACTS_TO_KEEP ) ?;
477
+ remove_all_except ( artifact_dir, ARTIFACTS_TO_KEEP , log ) ?;
464
478
465
- println ! (
479
+ info ! (
480
+ log,
466
481
"Removing installed objects in: {}" ,
467
482
install_dir. to_string_lossy( )
468
483
) ;
469
484
const INSTALLED_OBJECTS_TO_KEEP : & [ & str ] = & [ "opte" ] ;
470
- remove_all_except ( install_dir, INSTALLED_OBJECTS_TO_KEEP ) ?;
485
+ remove_all_except ( install_dir, INSTALLED_OBJECTS_TO_KEEP , log) ?;
486
+
487
+ cleanup_networking_resources ( log) . await ?;
488
+
471
489
Ok ( ( ) )
472
490
}
473
491
@@ -545,6 +563,11 @@ async fn main() -> Result<()> {
545
563
let args = Args :: try_parse ( ) ?;
546
564
let config = parse :: < _ , Config > ( & args. manifest ) ?;
547
565
566
+ let decorator = slog_term:: TermDecorator :: new ( ) . build ( ) ;
567
+ let drain = slog_term:: CompactFormat :: new ( decorator) . build ( ) . fuse ( ) ;
568
+ let drain = slog_async:: Async :: new ( drain) . build ( ) . fuse ( ) ;
569
+ let log = slog:: Logger :: root ( drain, o ! ( ) ) ;
570
+
548
571
// Use a CWD that is the root of the Omicron repository.
549
572
if let Ok ( manifest) = env:: var ( "CARGO_MANIFEST_DIR" ) {
550
573
let manifest_dir = PathBuf :: from ( manifest) ;
@@ -561,13 +584,13 @@ async fn main() -> Result<()> {
561
584
artifact_dir,
562
585
install_dir,
563
586
} ) => {
564
- do_install ( & config, & artifact_dir, & install_dir) ?;
587
+ do_install ( & config, & artifact_dir, & install_dir, & log ) ?;
565
588
}
566
589
SubCommand :: Deploy ( DeployCommand :: Uninstall {
567
590
artifact_dir,
568
591
install_dir,
569
592
} ) => {
570
- do_uninstall ( & config, & artifact_dir, & install_dir) ?;
593
+ do_uninstall ( & config, & artifact_dir, & install_dir, & log ) . await ?;
571
594
}
572
595
}
573
596
0 commit comments