@@ -3278,6 +3278,18 @@ def start_gc(session, sr_uuid):
32783278 subprocess .run ([__file__ , '-b' , '-u' , sr_uuid , '-g' ],
32793279 stdout = subprocess .PIPE , stderr = subprocess .PIPE , close_fds = True )
32803280
3281+ def _gc_service_cmd (sr_uuid , action , extra_args = None ):
3282+ """
3283+ Build and run the systemctl command for the GC service using util.doexec.
3284+ """
3285+ sr_uuid_esc = sr_uuid .replace ("-" , "\\ x2d" )
3286+ cmd = ["/usr/bin/systemctl" , "--quiet" ]
3287+ if extra_args :
3288+ cmd .extend (extra_args )
3289+ cmd += [action , f"SMGC@{ sr_uuid_esc } " ]
3290+ return util .doexec (cmd )
3291+
3292+
32813293def start_gc_service (sr_uuid , wait = False ):
32823294 """
32833295 This starts the templated systemd service which runs GC on the given SR UUID.
@@ -3288,13 +3300,18 @@ def start_gc_service(sr_uuid, wait=False):
32883300 run has finished. This is used to force a run of the GC instead of just kicking it
32893301 in the background.
32903302 """
3291- sr_uuid_esc = sr_uuid .replace ("-" , "\\ x2d" )
32923303 util .SMlog (f"Kicking SMGC@{ sr_uuid } ..." )
3293- cmd = [ "/usr/bin/systemctl" , "--quiet" ]
3294- if not wait :
3295- cmd .append ("--no-block" )
3296- cmd += ["start" , f"SMGC@{ sr_uuid_esc } " ]
3297- subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , close_fds = True )
3304+ _gc_service_cmd (sr_uuid , "start" , extra_args = None if wait else ["--no-block" ])
3305+
3306+
3307+ def stop_gc_service (sr_uuid ):
3308+ """
3309+ Stops the templated systemd service which runs GC on the given SR UUID.
3310+ """
3311+ util .SMlog (f"Stopping SMGC@{ sr_uuid } ..." )
3312+ (rc , _stdout , stderr ) = _gc_service_cmd (sr_uuid , "stop" )
3313+ if rc != 0 :
3314+ util .SMlog (f"Failed to stop gc service `SMGC@{ sr_uuid } `: `{ stderr } `" )
32983315
32993316
33003317def gc_force (session , srUuid , force = False , dryRun = False , lockSR = False ):
0 commit comments