Skip to content

Commit

Permalink
cmd/run: Add job clean up method to exit routine
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
  • Loading branch information
nderjung committed Jan 7, 2021
1 parent 9bdbd74 commit 3685a4b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
DisableFlagsInUseLine: true,
}
runConfig = &RunConfig{}
activeJob *job.Job
)

func init() {
Expand Down Expand Up @@ -153,7 +154,7 @@ func doRunCmd(cmd *cobra.Command, args []string) {
os.MkdirAll(cacheDir, os.ModePerm)
}

j, err := job.NewJob(args[0], &job.RuntimeConfig{
activeJob, err := job.NewJob(args[0], &job.RuntimeConfig{
Cpus: cpus,
BridgeName: runConfig.BridgeName,
BridgeIface: runConfig.HostNetwork,
Expand All @@ -178,7 +179,7 @@ func doRunCmd(cmd *cobra.Command, args []string) {
}

// Start the job with its various tasks
err = j.Start()
err = activeJob.Start()
if err != nil {
log.Errorf("Could not start job: %s", err)
cleanup()
Expand Down Expand Up @@ -242,5 +243,12 @@ func setupInterruptHandler() {
// Preserve the host environment
func cleanup() {
log.Info("Running clean up...")

if activeJob != nil {
activeJob.Cleanup()
}

job.RevertEnvironment(runConfig.DryRun)

// TODO: Clean up bridge
}

0 comments on commit 3685a4b

Please sign in to comment.