mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
convert systemd unit to Type=notify and report readiness
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user