...

Source file src/golang.conradwood.net/tests/linuxcom/linuxcom.go

Documentation: golang.conradwood.net/tests/linuxcom

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"time"
     7  
     8  	"golang.conradwood.net/go-easyops/authremote"
     9  	"golang.conradwood.net/go-easyops/linux"
    10  	"golang.conradwood.net/go-easyops/utils"
    11  )
    12  
    13  func main() {
    14  	flag.Parse()
    15  	fmt.Printf("linuxcom tests starting\n")
    16  	mc, err := linux.MyCgroup()
    17  	utils.Bail("failed to get my cgroup", err)
    18  	fmt.Printf("My cgroup: %s\n", mc)
    19  	com := linux.NewCommand()
    20  	ctx := authremote.ContextWithTimeout(time.Duration(30) * time.Second)
    21  	//	ci, err := com.Start(ctx, "/usr/bin/md5sum")
    22  	ci, err := com.Start(ctx, "./test_com.sh")
    23  	utils.Bail("failed to start", err)
    24  	go func(c linux.Command) {
    25  		time.Sleep(time.Duration(10) * time.Second)
    26  		utils.Bail("sigint failed", c.SigInt())
    27  		time.Sleep(time.Duration(15) * time.Second)
    28  		utils.Bail("sigkill failed", c.SigKill())
    29  	}(com)
    30  	started := time.Now()
    31  	err = ci.WaitAll(ctx)
    32  	dur := time.Since(started)
    33  	fmt.Printf("\n\nStopped after %0.1fs\n", dur.Seconds())
    34  	utils.Bail("failed to wait", err)
    35  
    36  }
    37  

View as plain text