functions

The Fool guy's FAAS
git clone git://git.lair.cx/functions
Log | Files | Refs | README

run.go (648B)


      1 package vmutils
      2 
      3 import (
      4 	"context"
      5 	"fmt"
      6 	"os"
      7 
      8 	"github.com/firecracker-microvm/firecracker-go-sdk"
      9 )
     10 
     11 func Run(ctx context.Context, machine *firecracker.Machine) (err error) {
     12 	err = machine.Start(ctx)
     13 	if err != nil {
     14 		return fmt.Errorf("vmutils: failed to start machine: %w", err)
     15 	}
     16 
     17 	defer func() {
     18 		err = machine.StopVMM()
     19 		if err != nil {
     20 			err = fmt.Errorf("vmutils: failed to stop VMM: %w", err)
     21 		}
     22 
     23 		// Remove the socket file after the VMM has been stopped.
     24 		os.Remove(machine.Cfg.SocketPath)
     25 	}()
     26 
     27 	err = machine.Wait(ctx)
     28 	if err != nil {
     29 		return fmt.Errorf("vmutils: failed to wait for machine: %w", err)
     30 	}
     31 
     32 	return nil
     33 }