diff --git a/daemon.go b/daemon.go index cdf1e0e..ecf8cea 100644 --- a/daemon.go +++ b/daemon.go @@ -39,7 +39,7 @@ type DaemonOptions struct { Registry *Registry // RegistryEntry provides the code and daemon name for registration. - // PID, Health, and Started are filled automatically. + // PID, Health, Project, Binary, and Started are filled automatically. RegistryEntry DaemonEntry } @@ -113,6 +113,16 @@ func (d *Daemon) Start() error { if d.health != nil { entry.Health = d.health.Addr() } + if entry.Project == "" { + if wd, err := os.Getwd(); err == nil { + entry.Project = wd + } + } + if entry.Binary == "" { + if binary, err := os.Executable(); err == nil { + entry.Binary = binary + } + } if err := d.opts.Registry.Register(entry); err != nil { if d.health != nil { _ = d.health.Stop(context.Background()) diff --git a/daemon_test.go b/daemon_test.go index 8d8f802..cb862b5 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -144,6 +144,10 @@ func TestDaemon_StopIdempotent(t *testing.T) { func TestDaemon_AutoRegisters(t *testing.T) { dir := t.TempDir() reg := NewRegistry(filepath.Join(dir, "daemons")) + wd, err := os.Getwd() + require.NoError(t, err) + exe, err := os.Executable() + require.NoError(t, err) d := NewDaemon(DaemonOptions{ HealthAddr: "127.0.0.1:0", @@ -154,7 +158,7 @@ func TestDaemon_AutoRegisters(t *testing.T) { }, }) - err := d.Start() + err = d.Start() require.NoError(t, err) // Should be registered @@ -162,6 +166,8 @@ func TestDaemon_AutoRegisters(t *testing.T) { require.True(t, ok) assert.Equal(t, os.Getpid(), entry.PID) assert.NotEmpty(t, entry.Health) + assert.Equal(t, wd, entry.Project) + assert.Equal(t, exe, entry.Binary) // Stop should unregister err = d.Stop()