@@ -919,15 +919,32 @@ def _restart_service(self, service_config: Dict) -> bool:
919919 subprocess .run (pre_hook , shell = True , timeout = 30 )
920920
921921 # Restart the service
922- logger .info (f"Executing restart command for { service_name } : { resolved_command } " )
923922 if isinstance (resolved_command , list ):
924- result = subprocess .run (
923+ for command in resolved_command :
924+ logger .info (
925+ "Executing restart command for %s: %s" ,
926+ service_name ,
927+ command ,
928+ )
929+ result = subprocess .run (
930+ command ,
931+ shell = True ,
932+ capture_output = True ,
933+ text = True ,
934+ timeout = 60 ,
935+ )
936+ if result .returncode != 0 :
937+ logger .warning (
938+ "Restart command returned non-zero for %s: %s" ,
939+ service_name ,
940+ (result .stderr or result .stdout or "" ).strip (),
941+ )
942+ else :
943+ logger .info (
944+ "Executing restart command for %s: %s" ,
945+ service_name ,
925946 resolved_command ,
926- capture_output = True ,
927- text = True ,
928- timeout = 60 ,
929947 )
930- else :
931948 result = subprocess .run (
932949 resolved_command ,
933950 shell = True ,
@@ -957,28 +974,53 @@ def _restart_service(self, service_config: Dict) -> bool:
957974 logger .error (f"Error restarting service { service_name } : { str (e )} " , exc_info = True )
958975 return False
959976
960- def _resolve_restart_command (self , restart_command : Optional [str ], service_config : Dict ) -> Optional [Any ]:
977+ def _resolve_restart_command (self , restart_command : Optional [Any ], service_config : Dict ) -> Optional [Any ]:
961978 """Resolve restart command based on available service manager.
962979
963980 Args:
964981 restart_command: Explicit restart command from configuration.
965982 service_config: Service configuration dictionary.
966983
967984 Returns:
968- Command string or list, or None if not resolvable.
985+ Command string, list of commands , or None if not resolvable.
969986 """
970987 service_name = service_config .get ("service_name" ) or service_config .get ("name" )
971988 if not restart_command :
972989 if service_name :
973990 return self .service_manager .build_restart_command (service_name )
974991 return None
975992
976- command_value = restart_command .strip ()
977- if command_value .startswith ("systemctl" ) and not self .service_manager .is_systemd :
978- if service_name :
979- return self .service_manager .build_restart_command (service_name )
993+ if isinstance (restart_command , list ):
994+ normalized_commands = [
995+ str (command ).strip ()
996+ for command in restart_command
997+ if str (command ).strip ()
998+ ]
999+ if not normalized_commands :
1000+ if service_name :
1001+ return self .service_manager .build_restart_command (service_name )
1002+ return None
1003+ return normalized_commands
9801004
981- return restart_command
1005+ if isinstance (restart_command , str ):
1006+ command_value = restart_command .strip ()
1007+ if not command_value :
1008+ if service_name :
1009+ return self .service_manager .build_restart_command (service_name )
1010+ return None
1011+ if command_value .startswith ("systemctl" ) and not self .service_manager .is_systemd :
1012+ if service_name :
1013+ return self .service_manager .build_restart_command (service_name )
1014+ return command_value
1015+
1016+ logger .warning (
1017+ "Unsupported restart_command type for %s: %s" ,
1018+ service_name ,
1019+ type (restart_command ).__name__ ,
1020+ )
1021+ if service_name :
1022+ return self .service_manager .build_restart_command (service_name )
1023+ return None
9821024
9831025 def reset_restart_history (self ) -> None :
9841026 """Reset all restart history and cooldown trackers."""
0 commit comments