Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Add logs to wsnet listener#388

Merged
deansheather merged 4 commits intomasterfromdean/ch15087
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsgo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@ require (
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/rjeczalik/notify v0.9.2
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015
Expand Down
24 changes: 16 additions & 8 deletionsinternal/cmd/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
package cmd

import (
"context"
"log"
"net/url"
"os"
"os/signal"
"syscall"

// We use slog here since agent runs in the background and we can benefit
// from structured logging.
"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
"github.com/spf13/cobra"
"golang.org/x/xerrors"

Expand DownExpand Up@@ -46,7 +48,10 @@ coder agent start
coder agent start --coder-url https://my-coder.com --token xxxx-xxxx
`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
var (
ctx = cmd.Context()
log = slog.Make(sloghuman.Sink(os.Stderr)).Leveled(slog.LevelDebug)
)
if coderURL == "" {
var ok bool
coderURL, ok = os.LookupEnv("CODER_URL")
Expand All@@ -73,20 +78,23 @@ coder agent start --coder-url https://my-coder.com --token xxxx-xxxx
}
}

listener, err := wsnet.Listen(context.Background(), wsnet.ListenEndpoint(u, token), token)
log.Info(ctx, "starting wsnet listener", slog.F("coder_access_url", u.String()))
listener, err := wsnet.Listen(ctx, log, wsnet.ListenEndpoint(u, token), token)
if err != nil {
return xerrors.Errorf("listen: %w", err)
}
defer func() {
err := listener.Close()
if err != nil {
log.Error(ctx, "close listener", slog.Error(err))
}
}()

// Block until user sends SIGINT or SIGTERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs

if err = listener.Close(); err != nil {
log.Panic(err)
}

return nil
},
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp