ExampleServer_multipleInstances shows you how to configure multiple instances of tsnet per program. This allows you to have multiple Tailscale nodes in the same process/container.
()
| 67 | // of tsnet per program. This allows you to have multiple Tailscale nodes in the |
| 68 | // same process/container. |
| 69 | func ExampleServer_multipleInstances() { |
| 70 | baseDir := "/data" |
| 71 | var servers []*tsnet.Server |
| 72 | for _, hostname := range []string{"ichika", "nino", "miku", "yotsuba", "itsuki"} { |
| 73 | os.MkdirAll(filepath.Join(baseDir, hostname), 0700) |
| 74 | srv := &tsnet.Server{ |
| 75 | Hostname: hostname, |
| 76 | AuthKey: os.Getenv("TS_AUTHKEY"), |
| 77 | Ephemeral: true, |
| 78 | Dir: filepath.Join(baseDir, hostname), |
| 79 | } |
| 80 | if err := srv.Start(); err != nil { |
| 81 | log.Fatalf("can't start tsnet server: %v", err) |
| 82 | } |
| 83 | servers = append(servers, srv) |
| 84 | } |
| 85 | |
| 86 | // When you're done, close the instances |
| 87 | defer func() { |
| 88 | for _, srv := range servers { |
| 89 | srv.Close() |
| 90 | } |
| 91 | }() |
| 92 | } |
| 93 | |
| 94 | // ExampleServer_ignoreLogsSometimes shows you how to ignore all of the log messages |
| 95 | // written by a tsnet instance, but allows you to opt-into them if a command-line |