convert systemd unit to Type=notify and report readiness

This commit is contained in:
Pavel Sviderski
2024-09-20 23:11:00 +10:00
parent ea8dfca14c
commit 73be824f30
5 changed files with 35 additions and 6 deletions
+14
View File
@@ -3,6 +3,7 @@ package daemon
import (
"context"
"fmt"
systemd "github.com/coreos/go-systemd/daemon"
"log/slog"
"uncloud/internal/machine"
)
@@ -27,5 +28,18 @@ func New(dataDir string) (*Daemon, error) {
func (d *Daemon) Run(ctx context.Context) error {
slog.Info("Starting machine.")
// Notify systemd that the daemon is ready when the machine is started.
go func() {
select {
case <-d.machine.Started():
_, err := systemd.SdNotify(false, systemd.SdNotifyReady)
if err != nil {
slog.Error("Failed to notify systemd that the daemon is ready.", "error", err)
}
case <-ctx.Done():
}
}()
return d.machine.Run(ctx)
}