Last active
March 22, 2018 08:47
-
-
Save otiai10/df340a6a090ddf999aefd63f1d6a7002 to your computer and use it in GitHub Desktop.
daapミドルウェアを使ったGoのソースコードからのNFSサーバの起動
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
package main | |
import ( | |
"context" | |
"fmt" | |
"os" | |
"os/signal" | |
"github.com/otiai10/daap" | |
"github.com/otiai10/dkmachine/v0/dkmachine" | |
) | |
func main() { | |
ctx := context.Background() | |
machine, err := dkmachine.Create(&dkmachine.CreateOptions{ | |
Name: "otiai10-nfs-server", | |
Driver: "amazonec2", | |
AmazonEC2Region: "ap-northeast-1", | |
AmazonEC2InstanceType: "t2.micro", | |
AmazonEC2SecurityGroup: "otiai10-test", | |
}) | |
if err != nil { | |
fmt.Println("001:", err) | |
return | |
} | |
defer func() { | |
fmt.Println("Remove Machine", machine.Remove()) | |
}() | |
c1 := daap.NewContainer("otiai10/nfs-server", daap.Args{ | |
Machine: &daap.MachineConfig{ | |
CertPath: machine.CertPath(), | |
Host: machine.Host(), | |
}, | |
}) | |
logs, err := c1.PullImage(ctx) | |
if err != nil { | |
fmt.Println("003:", err) | |
return | |
} | |
for payload := range logs { | |
fmt.Printf("\r%s", payload.Progress) | |
} | |
fmt.Printf("\n") | |
if err := c1.Create(ctx); err != nil { | |
fmt.Println("004:", err) | |
return | |
} | |
if err := c1.Start(ctx); err != nil { | |
fmt.Println("005:", err) | |
return | |
} | |
fmt.Println("NFS Server is up. Interrupt with Ctrl+C if you want to stop.") | |
fmt.Printf("You might do next:\n\n\tsudo mount %s:/ /your/path\n\n", machine.Inspection.Driver.PrivateIPAddress) | |
interrupted := make(chan os.Signal, 1) | |
signal.Notify(interrupted, os.Interrupt) | |
for _ = range interrupted { | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment