Skip to content

Commit 472bcdb

Browse files
committed
refactor: only run systemctl when systemd is running as init
Based on reviewer feedback, changed the logic to only attempt systemctl commands when systemd is actually running as PID 1 (has_systemd() returns true). This is cleaner and more explicit: - Systems with systemd running: use systemctl - Systems with service command: use service - Container environments: skip service management gracefully The previous approach of running systemctl even when systemd wasn't running was for image portability (container->VM), but this is a niche use case. Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
1 parent 5a42430 commit 472bcdb

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

install.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,25 +310,19 @@ start_docker_daemon() {
310310
>&2 echo
311311
>&2 echo "Starting and enabling Docker daemon service..."
312312

313-
# On modern RHEL/CentOS/Fedora systems, only systemctl exists (no 'service' command).
314-
# In containers, 'systemctl start' fails but 'systemctl enable' succeeds, creating
315-
# symlinks so Docker starts on boot when the system runs normally (outside container).
316-
if command_exists systemctl; then
313+
# Check if systemd is running as the init system
314+
if has_systemd && command_exists systemctl; then
315+
# systemd is running - use systemctl to start and enable the service
317316
if ! is_dry_run; then
318-
if has_systemd; then
319-
>&2 echo "Using systemd to manage Docker service"
320-
else
321-
>&2 echo "Attempting to use systemctl (systemd not running as init)"
322-
fi
317+
>&2 echo "Using systemd to manage Docker service"
323318
fi
324319
(
325320
set -x
326-
# In containers, these commands may fail but we try anyway
327-
$sh_c 'systemctl start docker' || true
328-
$sh_c 'systemctl enable docker' || true
321+
$sh_c 'systemctl start docker'
322+
$sh_c 'systemctl enable docker'
329323
)
330324
if ! is_dry_run; then
331-
>&2 echo "Docker service configuration attempted"
325+
>&2 echo "Docker daemon started and enabled"
332326
fi
333327
elif command_exists service; then
334328
# Fallback for older systems without systemd

0 commit comments

Comments
 (0)