-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
third_party/wait-for-it: replace with a simple go program
The program doesn't have all the features of wait-for-it, but it implements the core functionality we need. For golang/go#61399 Change-Id: Ia5498523e44b74dcd5af1c984521f1a46208d2c5 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/552295 kokoro-CI: kokoro <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
- Loading branch information
Showing
13 changed files
with
72 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build unix | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"syscall" | ||
"time" | ||
|
||
"golang.org/x/pkgsite/internal/log" | ||
) | ||
|
||
var timeout = 15 * time.Second | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
if len(os.Args) < 2 { | ||
log.Fatalf(ctx, "expected at least one argument; got none") | ||
} | ||
hostport := os.Args[1] | ||
var command []string | ||
|
||
if len(os.Args) > 2 { | ||
if os.Args[2] != "--" { | ||
log.Fatalf(ctx, "expected second argument to be \"--\"; got %q", os.Args[2]) | ||
} | ||
command = os.Args[3:] | ||
} | ||
|
||
start := time.Now() | ||
for { | ||
if time.Since(start) > timeout { | ||
break | ||
} | ||
if conn, err := net.DialTimeout("tcp", hostport, 1*time.Second); err != nil { | ||
time.Sleep(1 * time.Second) | ||
continue | ||
} else { | ||
conn.Close() | ||
break | ||
} | ||
} | ||
var err error | ||
binpath := command[0] | ||
if !filepath.IsAbs(binpath) { | ||
binpath, err = exec.LookPath(command[0]) | ||
if err != nil { | ||
log.Fatalf(ctx, "looking up err: %v", err) | ||
} | ||
} | ||
if len(command) > 0 { | ||
err := syscall.Exec(binpath, command, os.Environ()) | ||
if err != nil { | ||
log.Fatalf(ctx, "exec-ing binary: %v", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.