Skip to content

remotely shut down your pi. no security make sure it's on a private net.

Notifications You must be signed in to change notification settings

BarryBahrami/pi-shutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Safe Shutdown Container

A lightweight Docker container that provides a simple web interface for safely shutting down your Raspberry Pi. Perfect for headless, battery-powered setups where you need a graceful shutdown option.

Features

  • 🌐 Clean, responsive web interface
  • ✅ Checkbox confirmation to prevent accidental shutdowns
  • 🔒 Secure sudo configuration (only shutdown command allowed)
  • 🏥 Built-in health check endpoint
  • 📱 Mobile-friendly design
  • 🎨 Modern, intuitive UI

Deployment Instructions

Step 1: Build the Image on Your Raspberry Pi

IMPORTANT: Build directly on the Raspberry Pi to ensure correct ARM architecture.

# On your Raspberry Pi
cd /path/to/ShutdownContainer
docker build -t barrybahrami/private:pi-shutdown .

Step 2: Run on Your Raspberry Pi

docker run -d \
  --name pi-shutdown \
  --restart unless-stopped \
  --privileged \
  --pid=host \
  -p 80:8080 \
  barrybahrami/private:pi-shutdown

Important flags:

  • --privileged: Allows container to access host system
  • --pid=host: Shares host's PID namespace (required for nsenter to work)
  • -p 80:8080: Maps host port 80 to container port 8080

Step 3 (Optional): Push to Docker Hub

If you want to save the image to Docker Hub:

docker login
docker push barrybahrami/private:pi-shutdown

Step 4: Access the Interface

Open your browser and navigate to:

  • http://<raspberry-pi-ip> (from any device on the network)

Step 5: Shutdown Process

  1. Check the confirmation checkbox
  2. Click the "Shutdown System" button
  3. The system will safely shutdown

Container Management Commands

View logs:

docker logs -f pi-shutdown

Stop the container:

docker stop pi-shutdown

Start the container:

docker start pi-shutdown

Restart the container:

docker restart pi-shutdown

Remove the container:

docker rm pi-shutdown

Update to latest version:

docker pull <your-dockerhub-username>/pi-shutdown:latest
docker stop pi-shutdown
docker rm pi-shutdown
# Then run the Step 3 command again

How It Works

  1. Web Interface: Flask serves a single-page application with HTML/CSS/JavaScript
  2. Confirmation: User must check a box before the shutdown button becomes active
  3. Shutdown Request: When clicked, sends a POST request to /shutdown endpoint
  4. System Shutdown: Container executes sudo shutdown -h now on the host system
  5. Privileged Mode: Container runs in privileged mode with access to host's shutdown command

Security Considerations

  • The container runs in privileged mode to access the host's shutdown command
  • The internal user has limited sudo access (only for the shutdown command)
  • The web interface has no authentication - ensure your network is secure
  • Consider adding authentication if exposing to untrusted networks
  • Runs on port 80 - accessible at http://<pi-ip> without specifying a port

Troubleshooting

Container won't start

docker logs pi-shutdown

Shutdown doesn't work

  • Ensure the container is running in privileged mode
  • Check that /sbin/shutdown is mounted correctly
  • Verify sudo permissions inside the container:
    docker exec -it pi-shutdown sudo -l

Can't access the web interface

  • Check if the container is running: docker ps
  • Verify port 80 is not blocked by firewall
  • Try accessing from the Pi itself: curl http://localhost:8080/health

Testing on Another Machine

IMPORTANT: Before deploying to your Raspberry Pi, test on another machine first!

The shutdown command will actually shutdown the host machine, so make sure you're ready for that.

System Requirements

  • Docker
  • Docker Compose
  • Raspberry Pi OS / Ubuntu (or any Linux distribution)
  • Sudo access for the shutdown command

License

Free to use for any purpose.

About

remotely shut down your pi. no security make sure it's on a private net.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published