@@ -83,6 +83,7 @@ def __init__(self):
8383 self .args = None
8484 self .setvalues = None
8585 self .display = False
86+ self ._runtime = None
8687
8788 def get_atomic_config_item (self , config_item ):
8889 """
@@ -455,7 +456,7 @@ def _generate_default_oci_configuration(self, destination):
455456 conf .write ('{}' )
456457 return
457458
458- args = [util . RUNC_PATH , 'spec' ]
459+ args = [self . _get_oci_runtime () , 'spec' ]
459460 util .subp (args , cwd = destination )
460461 with open (conf_path , 'r' ) as conf :
461462 configuration = json .loads (conf .read ())
@@ -466,43 +467,29 @@ def _generate_default_oci_configuration(self, destination):
466467 with open (conf_path , 'w' ) as conf :
467468 conf .write (json .dumps (configuration , indent = 4 ))
468469
469- def _generate_systemd_startstop_directives (self , name , pidfile = None , unit_file_support_pidfile = False ):
470+ def _get_oci_runtime (self ):
471+ if self ._runtime :
472+ return self ._runtime
473+
470474 if self .user :
471- return self ._generate_user_systemd_startstop_directives (name , pidfile , unit_file_support_pidfile )
472- else :
473- return self ._generate_system_systemd_startstop_directives (name , pidfile , unit_file_support_pidfile )
475+ return util .BWRAP_OCI_PATH
476+ return util .RUNC_PATH
474477
475- # --user case
476- def _generate_user_systemd_startstop_directives (self , name , pidfile = None , unit_file_support_pidfile = False ):
477- if unit_file_support_pidfile :
478- has_pidfile_option = False
479- try :
480- has_pidfile_option = "--pid-file" in str (util .check_output ([util .BWRAP_OCI_PATH , "--help" ], stderr = DEVNULL ))
481- except util .FileNotFound :
482- pass
483- if has_pidfile_option :
484- start = "{} --pid-file='{}' --detach run {}" .format (util .BWRAP_OCI_PATH , pidfile , name )
485- stoppost = "{} delete '{}'" .format (util .BWRAP_OCI_PATH , name )
486- return [start , "" , "" , stoppost ]
487- return ["{}" .format (util .BWRAP_OCI_PATH ), "" , "" , "" ]
488-
489- # --system case
490- def _generate_system_systemd_startstop_directives (self , name , pidfile = None , unit_file_support_pidfile = False ):
491- try :
492- version = str (util .check_output ([util .RUNC_PATH , "--version" ], stderr = DEVNULL ))
493- except util .FileNotFound :
494- version = ""
478+ def _generate_systemd_startstop_directives (self , name , pidfile = None , unit_file_support_pidfile = False ):
479+ runtime = self ._get_oci_runtime ()
480+ return self ._generate_systemd_runtime_startstop_directives (name , runtime , pidfile = pidfile , unit_file_support_pidfile = unit_file_support_pidfile )
495481
496- if "version 0" in version :
497- raise ValueError ("The version of runC is too old." )
482+ def _generate_systemd_runtime_startstop_directives (self , name , runtime , pidfile = None , unit_file_support_pidfile = False ):
483+ runtime_has_pidfile = "--pid-file" in str (util .check_output ([runtime , "run" , "--help" ], stderr = DEVNULL ))
484+ systemd_cgroup = " --systemd-cgroup" if "--systemd-cgroup" in str (util .check_output ([runtime , "--help" ], stderr = DEVNULL )) else ""
498485
499- if unit_file_support_pidfile :
500- start = "{} --systemd-cgroup run -d --pid-file {} '{}'" .format (util . RUNC_PATH , pidfile , name )
501- stoppost = "{} delete '{}'" .format (util . RUNC_PATH , name )
486+ if unit_file_support_pidfile and runtime_has_pidfile :
487+ start = "{} {} run -d --pid-file {} '{}'" .format (runtime , systemd_cgroup , pidfile , name )
488+ stoppost = "{} delete '{}'" .format (runtime , name )
502489 return [start , "" , "" , stoppost ]
503490 else :
504491 runc_commands = ["run" , "kill" ]
505- return ["{} --systemd-cgroup {} '{}'" .format (util . RUNC_PATH , command , name ) for command in runc_commands ] + ["" , "" ]
492+ return ["{}{} {} '{}'" .format (runtime , systemd_cgroup , command , name ) for command in runc_commands ] + ["" , "" ]
506493
507494 def _get_systemd_destination_files (self , name , prefix = None ):
508495 if self .user :
@@ -903,7 +890,8 @@ def _do_checkout(self, repo, name, img, upgrade, deployment, values, destination
903890 "rename-installed-files" : rename_files ,
904891 "rpm-installed" : rpm_installed ,
905892 "system-package" : system_package ,
906- "remote" : remote }
893+ "remote" : remote ,
894+ "runtime" : self ._get_oci_runtime ()}
907895 info_file .write (json .dumps (info , indent = 4 ))
908896 info_file .write ("\n " )
909897 except (NameError , AttributeError , OSError ) as e :
@@ -1079,6 +1067,7 @@ def update_container(self, name, setvalues=None, rebase=None):
10791067 installed_files = info ["installed-files" ] if "installed-files" in info else None
10801068 rpm_installed = info ["rpm-installed" ] if "rpm-installed" in info else None
10811069 system_package = info ["system-package" ] if "system-package" in info else None
1070+ runtime = info ["runtime" ] if "runtime" in info else None
10821071
10831072 # Check if the image id or the configuration for the container has
10841073 # changed before upgrading it.
@@ -1104,6 +1093,8 @@ def update_container(self, name, setvalues=None, rebase=None):
11041093 util .write_out ("Latest version already installed." )
11051094 return
11061095
1096+ if runtime is not None :
1097+ self ._runtime = runtime
11071098 if system_package is None :
11081099 system_package = 'yes' if rpm_installed else 'no'
11091100 self ._checkout (repo , name , image , next_deployment , True , values , remote = self .args .remote , installed_files = installed_files , system_package = system_package )
@@ -1225,11 +1216,13 @@ def _get_containers_at(self, checkouts, are_preinstalled, containers=None):
12251216 if fullpath .endswith (".0" ) or fullpath .endswith (".1" ):
12261217 continue
12271218
1219+ runtime = "bwrap-oci" if self .user else "runc"
12281220 with open (os .path .join (fullpath , "info" ), "r" ) as info_file :
12291221 info = json .load (info_file )
12301222 revision = info ["revision" ] if "revision" in info else ""
12311223 created = info ["created" ] if "created" in info else 0
12321224 image = info ["image" ] if "image" in info else ""
1225+ runtime = info ["runtime" ] if "runtime" in info else ""
12331226
12341227 command = ""
12351228 config_json = os .path .join (fullpath , "config.json" )
@@ -1238,7 +1231,6 @@ def _get_containers_at(self, checkouts, are_preinstalled, containers=None):
12381231 config = json .load (config_file )
12391232 command = u' ' .join (config ["process" ]["args" ])
12401233
1241- runtime = "bwrap-oci" if self .user else "runc"
12421234 container = {'Image' : image , 'ImageID' : revision , 'Id' : x , 'Created' : created , 'Names' : [x ],
12431235 'Command' : command , 'Type' : 'system' , 'Runtime' : runtime , "Preinstalled" : are_preinstalled }
12441236 ret .append (container )
0 commit comments