@@ -986,12 +986,25 @@ def _get_disabled_services_list(config_db):
986986 return disabled_services_list
987987
988988
989+ def _monit_service_exists (service ):
990+ """Return True if monit knows about the given service."""
991+ try :
992+ subprocess .check_call (
993+ ['sudo' , 'monit' , 'status' , service ],
994+ stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL
995+ )
996+ return True
997+ except subprocess .CalledProcessError :
998+ return False
999+
1000+
9891001def _stop_services ():
9901002 try :
9911003 subprocess .check_call (['sudo' , 'monit' , 'status' ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
9921004 click .echo ("Disabling container and routeCheck monitoring ..." )
9931005 clicommon .run_command (['sudo' , 'monit' , 'unmonitor' , 'container_checker' ])
994- clicommon .run_command (['sudo' , 'monit' , 'unmonitor' , 'routeCheck' ])
1006+ if _monit_service_exists ('routeCheck' ):
1007+ clicommon .run_command (['sudo' , 'monit' , 'unmonitor' , 'routeCheck' ])
9951008 except subprocess .CalledProcessError as err :
9961009 pass
9971010
@@ -1080,10 +1093,13 @@ def _restart_services():
10801093 try :
10811094 subprocess .check_call (['sudo' , 'monit' , 'status' ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
10821095 click .echo ("Enabling container and routeCheck monitoring ..." )
1083- clicommon .run_command (['sudo' , 'monit' , 'monitor' , 'routeCheck' ])
1096+ has_route_check = _monit_service_exists ('routeCheck' )
1097+ if has_route_check :
1098+ clicommon .run_command (['sudo' , 'monit' , 'monitor' , 'routeCheck' ])
10841099 clicommon .run_command (['sudo' , 'monit' , 'monitor' , 'container_checker' ])
10851100 log .log_notice ("Waiting for monit monitor actions to complete ..." )
1086- _wait_for_monit_service_monitored ('routeCheck' )
1101+ if has_route_check :
1102+ _wait_for_monit_service_monitored ('routeCheck' )
10871103 _wait_for_monit_service_monitored ('container_checker' )
10881104 except subprocess .CalledProcessError as err :
10891105 pass
0 commit comments