mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
fix: containerd socket detection and unregistry startup on machine reboot
This commit is contained in:
+29
-25
@@ -104,27 +104,6 @@ func (c *Config) SetDefaults() (*Config, error) {
|
|||||||
}
|
}
|
||||||
cfg.DockerClient = cli
|
cfg.DockerClient = cli
|
||||||
}
|
}
|
||||||
if cfg.ContainerdSockPath == "" {
|
|
||||||
// Auto-detect the containerd.sock path used by Docker.
|
|
||||||
paths := []string{
|
|
||||||
"/run/containerd/containerd.sock", // Default path on most Linux distributions.
|
|
||||||
"/run/docker/containerd/containerd.sock",
|
|
||||||
"/var/run/containerd/containerd.sock",
|
|
||||||
"/var/run/docker/containerd/containerd.sock",
|
|
||||||
}
|
|
||||||
for _, path := range paths {
|
|
||||||
if _, err := os.Stat(path); err == nil {
|
|
||||||
cfg.ContainerdSockPath = path
|
|
||||||
slog.Debug("Detected containerd socket used by Docker.", "path", path)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.ContainerdSockPath == "" {
|
|
||||||
slog.Warn("Failed to auto-detect containerd socket used by Docker.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.CorrosionDir == "" {
|
if cfg.CorrosionDir == "" {
|
||||||
cfg.CorrosionDir = filepath.Join(cfg.DataDir, "corrosion")
|
cfg.CorrosionDir = filepath.Join(cfg.DataDir, "corrosion")
|
||||||
}
|
}
|
||||||
@@ -340,6 +319,31 @@ func (m *Machine) Initialised() bool {
|
|||||||
return m.state.ID != ""
|
return m.state.ID != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContainerdSock returns the path to the containerd socket used by Docker, auto-discovering it from well-known
|
||||||
|
// locations if it's not explicitly configured.
|
||||||
|
// Returns an empty string if the socket cannot be detected.
|
||||||
|
func (m *Machine) ContainerdSock() string {
|
||||||
|
if m.config.ContainerdSockPath != "" {
|
||||||
|
return m.config.ContainerdSockPath
|
||||||
|
}
|
||||||
|
|
||||||
|
paths := []string{
|
||||||
|
"/run/containerd/containerd.sock", // Default path on most Linux distributions.
|
||||||
|
"/run/docker/containerd/containerd.sock",
|
||||||
|
"/var/run/containerd/containerd.sock",
|
||||||
|
"/var/run/docker/containerd/containerd.sock",
|
||||||
|
}
|
||||||
|
for _, path := range paths {
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
slog.Debug("Detected containerd socket used by Docker.", "path", path)
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Warn("Failed to auto-detect containerd socket used by Docker.")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// IP returns the machine IPv4 address in the cluster network which is the first address in the machine subnet.
|
// IP returns the machine IPv4 address in the cluster network which is the first address in the machine subnet.
|
||||||
func (m *Machine) IP() netip.Addr {
|
func (m *Machine) IP() netip.Addr {
|
||||||
if !m.Initialised() {
|
if !m.Initialised() {
|
||||||
@@ -460,7 +464,7 @@ func (m *Machine) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var unreg *unregistry.Registry
|
var unreg *unregistry.Registry
|
||||||
if m.config.ContainerdSockPath != "" {
|
if containerdSock := m.ContainerdSock(); containerdSock != "" {
|
||||||
isContainerdStore, err := m.dockerService.IsContainerdImageStoreEnabled(ctx)
|
isContainerdStore, err := m.dockerService.IsContainerdImageStoreEnabled(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("check if Docker uses containerd image store: %w", err)
|
return fmt.Errorf("check if Docker uses containerd image store: %w", err)
|
||||||
@@ -472,7 +476,7 @@ func (m *Machine) Run(ctx context.Context) error {
|
|||||||
unreg, err = unregistry.NewRegistry(unregistry.Config{
|
unreg, err = unregistry.NewRegistry(unregistry.Config{
|
||||||
Addr: net.JoinHostPort(m.IP().String(), strconv.Itoa(constants.UnregistryPort)),
|
Addr: net.JoinHostPort(m.IP().String(), strconv.Itoa(constants.UnregistryPort)),
|
||||||
ContainerdNamespace: "moby",
|
ContainerdNamespace: "moby",
|
||||||
ContainerdSock: m.config.ContainerdSockPath,
|
ContainerdSock: containerdSock,
|
||||||
LogFormatter: "text",
|
LogFormatter: "text",
|
||||||
LogLevel: "info",
|
LogLevel: "info",
|
||||||
})
|
})
|
||||||
@@ -483,7 +487,7 @@ func (m *Machine) Run(ctx context.Context) error {
|
|||||||
slog.Warn("Skipping embedded unregistry setup as Docker is not using the containerd image store.")
|
slog.Warn("Skipping embedded unregistry setup as Docker is not using the containerd image store.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
slog.Warn("Skipping embedded unregistry setup as the containerd socket path is not configured.")
|
slog.Warn("Skipping embedded unregistry setup as the containerd socket path could not be detected.")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
@@ -1131,7 +1135,7 @@ func (m *Machine) InspectService(
|
|||||||
const logsHeartbeatInterval = 200 * time.Millisecond
|
const logsHeartbeatInterval = 200 * time.Millisecond
|
||||||
|
|
||||||
// MachineLogs streams logs from a systemd service.
|
// MachineLogs streams logs from a systemd service.
|
||||||
func (s *Machine) MachineLogs(
|
func (m *Machine) MachineLogs(
|
||||||
req *pb.LogsRequest, stream grpc.ServerStreamingServer[pb.LogEntry],
|
req *pb.LogsRequest, stream grpc.ServerStreamingServer[pb.LogEntry],
|
||||||
) error {
|
) error {
|
||||||
// TODO(miek): almost duplicate of docker/server.ContainerLogs
|
// TODO(miek): almost duplicate of docker/server.ContainerLogs
|
||||||
|
|||||||
+1
-1
@@ -204,7 +204,7 @@ install_uncloud_systemd() {
|
|||||||
cat > "${uncloud_service_path}" << EOF
|
cat > "${uncloud_service_path}" << EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Uncloud machine daemon
|
Description=Uncloud machine daemon
|
||||||
After=network-online.target
|
After=network-online.target docker.service
|
||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
|||||||
Reference in New Issue
Block a user