@@ -409,6 +409,14 @@ def _abort_if_false(ctx, param, value):
409
409
if not value :
410
410
ctx .abort ()
411
411
412
+ def _get_optional_services ():
413
+ config_db = ConfigDBConnector ()
414
+ config_db .connect ()
415
+ optional_services_dict = config_db .get_table ('FEATURE' )
416
+ if not optional_services_dict :
417
+ return None
418
+ return optional_services_dict .keys ()
419
+
412
420
def _stop_services ():
413
421
# on Mellanox platform pmon is stopped by syncd
414
422
services_to_stop = [
@@ -439,6 +447,17 @@ def _stop_services():
439
447
log_error ("Stopping {} failed with error {}" .format (service , e ))
440
448
raise
441
449
450
+ # For optional services they don't start by default
451
+ for service in _get_optional_services ():
452
+ (out , err ) = run_command ("systemctl status {}" .format (service ), return_output = True )
453
+ if not err and 'Active: active (running)' in out :
454
+ try :
455
+ click .echo ("Stopping service {} ..." .format (service ))
456
+ run_command ("systemctl stop {}" .format (service ))
457
+ except SystemExit as e :
458
+ log_error ("Stopping {} failed with error {}" .format (service , e ))
459
+ raise
460
+
442
461
def _reset_failed_services ():
443
462
services_to_reset = [
444
463
'bgp' ,
@@ -474,6 +493,17 @@ def _reset_failed_services():
474
493
log_error ("Failed to reset failed status for service {}" .format (service ))
475
494
raise
476
495
496
+ # For optional services they don't start by default
497
+ for service in _get_optional_services ():
498
+ (out , err ) = run_command ("systemctl is-enabled {}" .format (service ), return_output = True )
499
+ if not err and 'enabled' in out :
500
+ try :
501
+ click .echo ("Resetting failed status for service {} ..." .format (service ))
502
+ run_command ("systemctl reset-failed {}" .format (service ))
503
+ except SystemExit as e :
504
+ log_error ("Failed to reset failed status for service {}" .format (service ))
505
+ raise
506
+
477
507
def _restart_services ():
478
508
# on Mellanox platform pmon is started by syncd
479
509
services_to_restart = [
@@ -508,6 +538,17 @@ def _restart_services():
508
538
log_error ("Restart {} failed with error {}" .format (service , e ))
509
539
raise
510
540
541
+ # For optional services they don't start by default
542
+ for service in _get_optional_services ():
543
+ (out , err ) = run_command ("systemctl is-enabled {}" .format (service ), return_output = True )
544
+ if not err and 'enabled' in out :
545
+ try :
546
+ click .echo ("Restarting service {} ..." .format (service ))
547
+ run_command ("systemctl restart {}" .format (service ))
548
+ except SystemExit as e :
549
+ log_error ("Restart {} failed with error {}" .format (service , e ))
550
+ raise
551
+
511
552
def is_ipaddress (val ):
512
553
""" Validate if an entry is a valid IP """
513
554
if not val :
0 commit comments