// StartShim willl start a kata shimv2 daemon which will implemented the
// ShimV2 APIs such as create/start/update etc containers.
StartShim willl start a kata shimv2 daemon which will implemented the
ShimV2 APIs such as create/start/update etc containers.
// StartShim willl start a kata shimv2 daemon which will implemented the // ShimV2 APIs such as create / start / update etc containers .
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress string) (string, error) {
	bundlePath, err := os.Getwd()
	if err != nil {
		return "", err
	}
	address, err := getAddress(ctx, bundlePath, id)
	if err != nil {
		return "", err
	}
	if address != "" {
		if err := cdshim.WriteAddress("address", address); err != nil {
			return "", err
		}
		return address, nil
	}
	cmd, err := newCommand(ctx, containerdBinary, id, containerdAddress)
	if err != nil {
		return "", err
	}
	address, err = cdshim.SocketAddress(ctx, id)
	if err != nil {
		return "", err
	}
	socket, err := cdshim.NewSocket(address)
	if err != nil {
		return "", err
	}
	defer socket.Close()
	f, err := socket.File()
	if err != nil {
		return "", err
	}
	defer f.Close()
	cmd.ExtraFiles = append(cmd.ExtraFiles, f)
	if err := cmd.Start(); err != nil {
		return "", err
	}
	defer func() {
		if err != nil {
			cmd.Process.Kill()
		}
	}()
	go cmd.Wait()
	if err = cdshim.WritePidFile("shim.pid", cmd.Process.Pid); err != nil {
		return "", err
	}
	if err = cdshim.WriteAddress("address", address); err != nil {
		return "", err
	}
	return address, nil
}
func ( s * service ) StartShim ( ctx context . Context , id , containerdBinary , containerdAddress string ) ( string , error ) { bundlePath , err := os . Getwd ( ) if err != nil { return " " , err } address , err := getAddress ( ctx , bundlePath , id ) if err != nil { return " " , err } if address != " " { if err := cdshim . WriteAddress ( " " , address ) ; err != nil { return " " , err } return address , nil } cmd , err := newCommand ( ctx , containerdBinary , id , containerdAddress ) if err != nil { return " " , err } address , err = cdshim . SocketAddress ( ctx , id ) if err != nil { return " " , err } socket , err := cdshim . NewSocket ( address ) if err != nil { return " " , err } defer socket . Close ( ) f , err := socket . File ( ) if err != nil { return " " , err } defer f . Close ( ) cmd . ExtraFiles = append ( cmd . ExtraFiles , f ) if err := cmd . Start ( ) ; err != nil { return " " , err } defer func ( ) { if err != nil { cmd . Process . Kill ( ) } } ( ) go cmd . Wait ( ) if err = cdshim . WritePidFile ( " " , cmd . Process . Pid ) ; err != nil { return " " , err } if err = cdshim . WriteAddress ( " " , address ) ; err != nil { return " " , err } return address , nil }
StartShim willl start a kata shimv2 daemon which will implemented the
ShimV2 APIs such as create/start/update etc containers.
StartShim willl start a kata shimv2 daemon which will implemented the ShimV2 APIs such as create / start / update etc containers .
// make sure to wait after start