Merge branch '10666-report-version'
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 4 Dec 2017 21:02:39 +0000 (18:02 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 4 Dec 2017 21:02:39 +0000 (18:02 -0300)
Closes #10666

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

1  2 
services/crunch-run/crunchrun.go

index d455dd2c9f8ca1befce2a780f223ab11b3aef290,0980ba11503d0faffa4134db5022431448b561b6..f3f754b59d227c3d410ad1255a9a38da1dd9400b
@@@ -19,7 -19,6 +19,7 @@@ import 
        "os/signal"
        "path"
        "path/filepath"
 +      "regexp"
        "runtime"
        "runtime/pprof"
        "sort"
@@@ -40,6 -39,8 +40,8 @@@
        dockerclient "github.com/docker/docker/client"
  )
  
+ var version = "dev"
  // IArvadosClient is the minimal Arvados API methods used by crunch-run.
  type IArvadosClient interface {
        Create(resourceType string, parameters arvadosclient.Dict, output interface{}) error
@@@ -229,15 -230,12 +231,15 @@@ func (runner *ContainerRunner) stopSign
        }
  }
  
 -var errorBlacklist = []string{"Cannot connect to the Docker daemon"}
 +var errorBlacklist = []string{
 +      "(?ms).*[Cc]annot connect to the Docker daemon.*",
 +      "(?ms).*oci runtime error.*starting container process.*container init.*mounting.*to rootfs.*no such file or directory.*",
 +}
  var brokenNodeHook *string = flag.String("broken-node-hook", "", "Script to run if node is detected to be broken (for example, Docker daemon is not running)")
  
  func (runner *ContainerRunner) checkBrokenNode(goterr error) bool {
        for _, d := range errorBlacklist {
 -              if strings.Index(goterr.Error(), d) != -1 {
 +              if m, e := regexp.MatchString(d, goterr.Error()); m && e == nil {
                        runner.CrunchLog.Printf("Error suggests node is unable to run containers: %v", goterr)
                        if *brokenNodeHook == "" {
                                runner.CrunchLog.Printf("No broken node hook provided, cannot mark node as broken.")
@@@ -646,7 -644,7 +648,7 @@@ type infoCommand struct 
        cmd   []string
  }
  
- // Gather node information and store it on the log for debugging
+ // LogNodeInfo gathers node information and store it on the log for debugging
  // purposes.
  func (runner *ContainerRunner) LogNodeInfo() (err error) {
        w := runner.NewLogWriter("node-info")
        return nil
  }
  
- // Get and save the raw JSON container record from the API server
+ // LogContainerRecord gets and saves the raw JSON container record from the API server
  func (runner *ContainerRunner) LogContainerRecord() (err error) {
        w := &ArvLogWriter{
                ArvClient:     runner.ArvClient,
@@@ -919,7 -917,7 +921,7 @@@ func (runner *ContainerRunner) StartCon
                dockertypes.ContainerStartOptions{})
        if err != nil {
                var advice string
 -              if strings.Contains(err.Error(), "no such file or directory") {
 +              if m, e := regexp.MatchString("(?ms).*(exec|System error).*(no such file or directory|file not found).*", err.Error()); m && e == nil {
                        advice = fmt.Sprintf("\nPossible causes: command %q is missing, the interpreter given in #! is missing, or script has Windows line endings.", runner.Container.Command[0])
                }
                return fmt.Errorf("could not start container: %v%s", err, advice)
@@@ -1448,6 -1446,7 +1450,7 @@@ func (runner *ContainerRunner) NewArvLo
  
  // Run the full container lifecycle.
  func (runner *ContainerRunner) Run() (err error) {
+       runner.CrunchLog.Printf("crunch-run %s started", version)
        runner.CrunchLog.Printf("Executing container '%s'", runner.Container.UUID)
  
        hostname, hosterr := os.Hostname()
@@@ -1628,8 -1627,17 +1631,17 @@@ func main() 
                `Set networking mode for container.  Corresponds to Docker network mode (--net).
        `)
        memprofile := flag.String("memprofile", "", "write memory profile to `file` after running container")
+       getVersion := flag.Bool("version", false, "Print version information and exit.")
        flag.Parse()
  
+       // Print version information if requested
+       if *getVersion {
+               fmt.Printf("crunch-run %s\n", version)
+               return
+       }
+       log.Printf("crunch-run %s started", version)
        containerId := flag.Arg(0)
  
        if *caCertsPath != "" {