Skip to content

Instantly share code, notes, and snippets.

@mtibben
Created August 16, 2020 06:17
Show Gist options
  • Save mtibben/ba5f96aae45d4f9b7ca6e5114200e9af to your computer and use it in GitHub Desktop.
Save mtibben/ba5f96aae45d4f9b7ca6e5114200e9af to your computer and use it in GitHub Desktop.
poll for aws vault process
func isProcessUp(pid int) bool {
process, err := os.FindProcess(pid)
if err != nil {
return false
} else {
return process.Signal(syscall.Signal(0)) == nil
}
}
func pollAwsVaultProcessAndExitWhenGone() {
pid, _ := strconv.Atoi(os.Getenv("AWS_VAULT_PID"))
if pid != 0 {
go func() {
for {
if !isProcessUp(pid) {
log.Println("PID %d gone, exiting", pid)
os.Exit(0)
}
time.Sleep(2 * time.Second)
}
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment