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

Commita27484e

Browse files
committed
feat(agent): Allow specifying log directory via flag or env
1 parentcf8d402 commita27484e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

‎agent/agent.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060

6161
typeOptionsstruct {
6262
Filesystem afero.Fs
63+
LogDirstring
6364
TempDirstring
6465
ExchangeTokenfunc(ctx context.Context) (string,error)
6566
ClientClient
@@ -87,6 +88,9 @@ func New(options Options) io.Closer {
8788
ifoptions.TempDir=="" {
8889
options.TempDir=os.TempDir()
8990
}
91+
ifoptions.LogDir=="" {
92+
options.LogDir=options.TempDir
93+
}
9094
ifoptions.ExchangeToken==nil {
9195
options.ExchangeToken=func(ctx context.Context) (string,error) {
9296
return"",nil
@@ -102,6 +106,7 @@ func New(options Options) io.Closer {
102106
client:options.Client,
103107
exchangeToken:options.ExchangeToken,
104108
filesystem:options.Filesystem,
109+
logDir:options.LogDir,
105110
tempDir:options.TempDir,
106111
lifecycleUpdate:make(chanstruct{},1),
107112
}
@@ -114,6 +119,7 @@ type agent struct {
114119
clientClient
115120
exchangeTokenfunc(ctx context.Context) (string,error)
116121
filesystem afero.Fs
122+
logDirstring
117123
tempDirstring
118124

119125
reconnectingPTYs sync.Map
@@ -582,7 +588,7 @@ func (a *agent) runStartupScript(ctx context.Context, script string) error {
582588
}
583589

584590
a.logger.Info(ctx,"running startup script",slog.F("script",script))
585-
writer,err:=a.filesystem.OpenFile(filepath.Join(a.tempDir,"coder-startup-script.log"),os.O_CREATE|os.O_RDWR,0o600)
591+
writer,err:=a.filesystem.OpenFile(filepath.Join(a.logDir,"coder-startup-script.log"),os.O_CREATE|os.O_RDWR,0o600)
586592
iferr!=nil {
587593
returnxerrors.Errorf("open startup script log file: %w",err)
588594
}

‎cli/agent.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
funcworkspaceAgent()*cobra.Command {
3030
var (
3131
authstring
32+
logDirstring
3233
pprofAddressstring
3334
noReapbool
3435
)
@@ -55,7 +56,7 @@ func workspaceAgent() *cobra.Command {
5556
// of zombie processes.
5657
ifreaper.IsInitProcess()&&!noReap&&isLinux {
5758
logWriter:=&lumberjack.Logger{
58-
Filename:filepath.Join(os.TempDir(),"coder-agent-init.log"),
59+
Filename:filepath.Join(logDir,"coder-agent-init.log"),
5960
MaxSize:5,// MB
6061
}
6162
deferlogWriter.Close()
@@ -91,7 +92,7 @@ func workspaceAgent() *cobra.Command {
9192
godumpHandler(ctx)
9293

9394
logWriter:=&lumberjack.Logger{
94-
Filename:filepath.Join(os.TempDir(),"coder-agent.log"),
95+
Filename:filepath.Join(logDir,"coder-agent.log"),
9596
MaxSize:5,// MB
9697
}
9798
deferlogWriter.Close()
@@ -178,6 +179,7 @@ func workspaceAgent() *cobra.Command {
178179
closer:=agent.New(agent.Options{
179180
Client:client,
180181
Logger:logger,
182+
LogDir:logDir,
181183
ExchangeToken:func(ctx context.Context) (string,error) {
182184
ifexchangeToken==nil {
183185
returnclient.SDK.SessionToken(),nil
@@ -199,8 +201,9 @@ func workspaceAgent() *cobra.Command {
199201
}
200202

201203
cliflag.StringVarP(cmd.Flags(),&auth,"auth","","CODER_AGENT_AUTH","token","Specify the authentication type to use for the agent")
202-
cliflag.BoolVarP(cmd.Flags(),&noReap,"no-reap","","",false,"Do not start a process reaper.")
204+
cliflag.StringVarP(cmd.Flags(),&logDir,"log-dir","","CODER_AGENT_LOG_DIR",os.TempDir(),"Specify the location for the agent log files")
203205
cliflag.StringVarP(cmd.Flags(),&pprofAddress,"pprof-address","","CODER_AGENT_PPROF_ADDRESS","127.0.0.1:6060","The address to serve pprof.")
206+
cliflag.BoolVarP(cmd.Flags(),&noReap,"no-reap","","",false,"Do not start a process reaper.")
204207
returncmd
205208
}
206209

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp