@@ -84,9 +84,11 @@ def trinity_status(self, command=None):
8484 if self .controller is False :
8585 self .exit_diagnosis ('Trinity Diagnosis is only Available from the Controller OR Luna2 Daemon is not present.' )
8686 response = ''
87+ status = True
8788 with subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True ) as process :
8889 output , error = process .communicate ()
8990 output = output .decode ("utf-8" ) if output else ''
91+ status = False if error else True
9092 error = error .decode ("utf-8" ) if error else ''
9193 response = output if output else error
9294 response = response .replace ('\n ' , '' )
@@ -102,7 +104,7 @@ def trinity_status(self, command=None):
102104 response = response .replace ('could not be found' , colored ('could not be found' , 'yellow' , attrs = ['bold' ]))
103105 response = response .strip ()
104106
105- return response
107+ return status , response
106108
107109
108110 def execute (self , command = None ):
@@ -136,6 +138,7 @@ def main():
136138 "Trinity OOD" : {}
137139 }
138140 debian = False
141+ status = True
139142 os_info = Diagnosis ().platform_info ()
140143 for _ , os_value in os_info .items ():
141144 if 'debian' in os_value .lower () or 'ubuntu' in os_value .lower ():
@@ -146,12 +149,17 @@ def main():
146149 response ["Trinity OOD" ]["httpd" ] = None
147150 for key , value in response .items ():
148151 for service , val in value .items ():
149- response [key ][service ] = Diagnosis ().trinity_status (f"systemctl status { service } .service | grep Active:" )
152+ ret , response [key ][service ] = Diagnosis ().trinity_status (f"systemctl status { service } .service | grep Active:" )
153+ if not ret :
154+ status = False
150155 for key , value in response .items ():
151156 print (colored (key , 'grey' , attrs = ['bold' ]))
152157 for service , val in value .items ():
153158 print (f'\t { service } : { val } ' )
154159 print ('\n ' )
160+ if status :
161+ exit (0 )
162+ exit (1 )
155163
156164
157165if __name__ == "__main__" :
0 commit comments