chore: remove serviceName or inline, update service unit description

This commit is contained in:
2025-06-23 17:47:46 -05:00
parent 06e036a116
commit 821067765e
3 changed files with 8 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
[Unit] [Unit]
Description=HATray - Home Assistant Tray Utility Description=HATray - A tray utility for Home Assistant
Documentation=https://github.com/Xevion/HATray Documentation=https://github.com/Xevion/HATray
After=network-online.target After=network-online.target
Wants=network-online.target Wants=network-online.target

View File

@@ -15,8 +15,6 @@ import (
"github.com/coreos/go-systemd/daemon" "github.com/coreos/go-systemd/daemon"
) )
const serviceName = "HATray"
// linuxService implements the Service interface for Linux // linuxService implements the Service interface for Linux
// It integrates with systemd and controls the app layer // It integrates with systemd and controls the app layer
// according to systemd signals (start, stop, reload) // according to systemd signals (start, stop, reload)

View File

@@ -14,8 +14,6 @@ import (
"golang.org/x/sys/windows/svc/eventlog" "golang.org/x/sys/windows/svc/eventlog"
) )
const serviceName = "HATray"
// WindowsService implements the Service interface for Windows // WindowsService implements the Service interface for Windows
type WindowsService struct { type WindowsService struct {
app *app.App app *app.App
@@ -43,29 +41,29 @@ func (svc *WindowsService) Run() error {
// Acquire the appropriate run function & eventlog instance depending on service type // Acquire the appropriate run function & eventlog instance depending on service type
if isService { if isService {
svc.logger.Debug("running as Windows service", "serviceName", serviceName) svc.logger.Debug("running as Windows service")
run = winsvc.Run run = winsvc.Run
svc.elog, err = eventlog.Open(serviceName) svc.elog, err = eventlog.Open("HATray")
if err != nil { if err != nil {
return fmt.Errorf("failed to open event log: %v", err) return fmt.Errorf("failed to open event log: %v", err)
} }
} else { } else {
svc.logger.Debug("running as debug service", "serviceName", serviceName) svc.logger.Debug("running as debug service")
run = debug.Run run = debug.Run
svc.elog = debug.New(serviceName) svc.elog = debug.New("HATray")
} }
defer svc.elog.Close() defer svc.elog.Close()
svc.elog.Info(1, fmt.Sprintf("starting %s service", serviceName)) svc.elog.Info(1, "starting service")
// Run the service with our handler // Run the service with our handler
err = run(serviceName, &serviceHandler{ err = run("HATray", &serviceHandler{
service: svc, service: svc,
}) })
if err != nil { if err != nil {
svc.elog.Error(1, fmt.Sprintf("%s service failed: %v", serviceName, err)) svc.elog.Error(1, fmt.Sprintf("service failed: %v", err))
return err return err
} }