Skip to content

Commit e01cf0d

Browse files
committed
Test with old impl
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 003d757 commit e01cf0d

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

Dockerfile.d/test-integration-rootless.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ if [[ "$(id -u)" = "0" ]]; then
3434
systemctl start ssh
3535
exec ssh -o StrictHostKeyChecking=no rootless@localhost "$0" "$@"
3636
else
37-
# Start D-Bus user session for systemd healthcheck timers
38-
systemctl --user start dbus.socket dbus.service || true
37+
# Ensure XDG_RUNTIME_DIR is set and create it if needed
38+
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
39+
mkdir -p "$XDG_RUNTIME_DIR"
40+
chmod 700 "$XDG_RUNTIME_DIR"
41+
42+
# Start systemd user session and D-Bus for healthcheck timers
43+
systemctl --user daemon-reload || true
44+
systemctl --user start dbus.socket || true
45+
systemctl --user start dbus.service || true
46+
47+
# Set D-Bus session address
3948
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
4049

50+
# Wait a moment for D-Bus to be ready
51+
sleep 1
52+
4153
containerd-rootless-setuptool.sh install
4254
if grep -q "options use-vc" /etc/resolv.conf; then
4355
containerd-rootless-setuptool.sh nsenter -- sh -euc 'echo "options use-vc" >>/etc/resolv.conf'

cmd/nerdctl/container/container_run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,12 @@ func runAction(cmd *cobra.Command, args []string) error {
447447
}
448448

449449
// Setup container healthchecks.
450-
if err := healthcheck.CreateAndStartTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
450+
if err := healthcheck.CreateTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
451451
return fmt.Errorf("failed to create healthcheck timer: %w", err)
452452
}
453+
if err := healthcheck.StartTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
454+
return fmt.Errorf("failed to start healthcheck timer: %w", err)
455+
}
453456

454457
if createOpt.Detach {
455458
fmt.Fprintln(createOpt.Stdout, id)

pkg/containerutil/containerutil.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,12 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
293293
}
294294

295295
// If container has health checks configured, create and start systemd timer/service files.
296-
if err := healthcheck.CreateAndStartTimer(ctx, container, cfg); err != nil {
296+
if err := healthcheck.CreateTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
297297
return fmt.Errorf("failed to create healthcheck timer: %w", err)
298298
}
299+
if err := healthcheck.StartTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
300+
return fmt.Errorf("failed to start healthcheck timer: %w", err)
301+
}
299302

300303
if !isAttach {
301304
return nil
@@ -529,7 +532,7 @@ func Unpause(ctx context.Context, client *containerd.Client, id string, cfg *con
529532
}
530533

531534
// Recreate healthcheck related systemd timer/service files.
532-
if err := healthcheck.CreateAndStartTimer(ctx, container, cfg); err != nil {
535+
if err := healthcheck.CreateTimer(ctx, container, cfg); err != nil {
533536
return fmt.Errorf("failed to create healthcheck timer: %w", err)
534537
}
535538

pkg/healthcheck/healthcheck_manager_linux.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,18 @@ func CreateTimer(ctx context.Context, container containerd.Container, cfg *confi
6363
}
6464

6565
log.G(ctx).Debugf("creating healthcheck timer with: systemd-run %s", strings.Join(cmdOpts, " "))
66+
67+
// Add user flag for rootless mode
68+
if rootlessutil.IsRootless() {
69+
cmdOpts = append([]string{"--user"}, cmdOpts...)
70+
}
71+
6672
run := exec.Command("systemd-run", cmdOpts...)
6773
if out, err := run.CombinedOutput(); err != nil {
74+
log.G(ctx).Errorf("systemd-run failed for container %s: %v\noutput: %s", containerID, err, strings.TrimSpace(string(out)))
6875
return fmt.Errorf("systemd-run failed: %w\noutput: %s", err, strings.TrimSpace(string(out)))
6976
}
77+
log.G(ctx).Debugf("Successfully created healthcheck timer for container %s", containerID)
7078

7179
return nil
7280
}
@@ -371,7 +379,18 @@ func CreateAndStartTimer(ctx context.Context, container containerd.Container, cf
371379
}
372380

373381
// Reload systemd and enable/start timer
382+
log.G(ctx).Debugf("Attempting systemd reload for container %s", containerID)
374383
if err := conn.ReloadContext(ctx); err != nil {
384+
// Log additional debugging information
385+
log.G(ctx).Errorf("systemd reload failed for container %s: %v", containerID, err)
386+
387+
// Try to get more information about the systemd state
388+
if rootlessutil.IsRootless() {
389+
log.G(ctx).Debugf("Running in rootless mode, checking user systemd status")
390+
} else {
391+
log.G(ctx).Debugf("Running in rootful mode, checking system systemd status")
392+
}
393+
375394
return fmt.Errorf("systemd reload failed: %w", err)
376395
}
377396
_, _, err = conn.EnableUnitFilesContext(ctx, []string{containerID + ".timer"}, false, true)

0 commit comments

Comments
 (0)