Created
August 16, 2020 06:17
-
-
Save mtibben/ba5f96aae45d4f9b7ca6e5114200e9af to your computer and use it in GitHub Desktop.
poll for aws vault process
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
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