tuanchris 3 месяцев назад
Родитель
Сommit
963ffc7554
4 измененных файлов с 10 добавлено и 24 удалено
  1. 1 1
      Dockerfile
  2. 5 4
      docker-compose.yml
  3. 4 8
      main.py
  4. 0 11
      shutdown_host.sh

+ 1 - 1
Dockerfile

@@ -10,7 +10,7 @@ WORKDIR /app
 
 COPY requirements.txt ./
 RUN apt-get update && apt-get install -y --no-install-recommends \
-        gcc libjpeg-dev zlib1g-dev git util-linux \
+        gcc libjpeg-dev zlib1g-dev git \
     && pip install --upgrade pip \
     && pip install --no-cache-dir -r requirements.txt \
     && apt-get purge -y gcc \

+ 5 - 4
docker-compose.yml

@@ -10,10 +10,11 @@ services:
       - .:/app
       # Mount timezone file from host for Still Sands scheduling
       - /etc/timezone:/etc/host-timezone:ro
-      # Mount Docker socket to allow host shutdown
-      - /var/run/docker.sock:/var/run/docker.sock:ro
-      # Mount shutdown script
-      - ./shutdown_host.sh:/usr/local/bin/shutdown_host.sh:ro
+      # Mount systemd to allow host shutdown
+      - /bin/systemctl:/bin/systemctl:ro
+      - /run/systemd/system:/run/systemd/system:ro
+      - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro
+      - /sys/fs/cgroup:/sys/fs/cgroup:ro
     devices:
       - "/dev/ttyACM0:/dev/ttyACM0"
     privileged: true

+ 4 - 8
main.py

@@ -1671,15 +1671,11 @@ async def shutdown_system():
         def delayed_shutdown():
             time.sleep(2)  # Give time for response to be sent
             try:
-                # Use nsenter to escape container and run shutdown on host
-                # This works because we're running with privileged: true
-                subprocess.run([
-                    "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid",
-                    "--", "shutdown", "-h", "now"
-                ], check=True)
-                logger.info("Host shutdown command executed successfully")
+                # Use systemctl to shutdown the host (via mounted systemd socket)
+                subprocess.run(["systemctl", "poweroff"], check=True)
+                logger.info("Host shutdown command executed successfully via systemctl")
             except FileNotFoundError:
-                logger.error("nsenter command not found - privileged container required for host shutdown")
+                logger.error("systemctl command not found - ensure systemd volumes are mounted")
             except Exception as e:
                 logger.error(f"Error executing host shutdown command: {e}")
 

+ 0 - 11
shutdown_host.sh

@@ -1,11 +0,0 @@
-#!/bin/bash
-# Script to shutdown the host system from inside Docker container
-# This must be placed on the host and mounted into the container
-
-echo "$(date): Shutdown requested from Dune Weaver" >> /tmp/dune-weaver-shutdown.log
-
-# Stop Docker containers gracefully
-docker compose -f /app/docker-compose.yml down 2>/dev/null || true
-
-# Shutdown the host system
-shutdown -h now