Created
June 2, 2018 04:07
-
-
Save shayne/c7f4314e280f926b9b61d5ad3a4c6a83 to your computer and use it in GitHub Desktop.
Holdup
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"time" | |
"github.com/docker/docker/api/types" | |
"github.com/docker/docker/api/types/filters" | |
"github.com/docker/docker/client" | |
) | |
func main() { | |
// check if volume /test is mounted by listing directory (should see at least one file) | |
files, err := ioutil.ReadDir("/test") | |
if err != nil { | |
time.Sleep(time.Second * 10) | |
log.Fatal(err) | |
} else if len(files) == 0 { | |
time.Sleep(time.Second * 10) | |
log.Fatal("No files found in /test, must not be mounted") | |
} | |
// if we get here then we have /test and it sees files | |
// which means that the mount is ready | |
log.Println("Found files in /test... continuing to the docker restart step") | |
// query exited containers and issue restart | |
cli, err := client.NewEnvClient() | |
if err != nil { | |
panic(err) | |
} | |
args := filters.NewArgs() | |
args.Add("status", "exited") | |
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{Filters: args}) | |
if err != nil { | |
panic(err) | |
} | |
duration := time.Second * 10 | |
fmt.Println("Restarting containers...") | |
for _, container := range containers { | |
fmt.Printf("%s %s\n", container.ID[:10], container.Image) | |
err := cli.ContainerRestart(context.Background(), container.ID, &duration) | |
if err != nil { | |
log.Printf("Failed to restart container: %s - %s\n", container.Image, err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Shayne
I'm trying to get this to work on my Raspberry Pi running LibreElec.
I'm getting the error: standard_init_linux.go:178: exec user process caused "exec format error".
Any idea what I might need to do get it working?
Thanks
Charles