Bash scripts for power button

neatrasm

New Member
Jan 10, 2026
14
0
1
I'm new to Proxmox and not finding satisfactory information for shutdown procedures for my Workstation.

I want to shut down everything properly when pressing or holding the physical power button.

Google Gemini is saying something about installing acpid which hasn't been in Debian since Wheezy.

An example for when I press the power button, I want a similar script to run in the VM.


Bash:
#!/bin/bash

# Define the directory where your docker-compose.yml file is located
COMPOSE_DIR="/path/to/your/project"

cd "$COMPOSE_DIR"

echo "Stopping and removing Docker Compose containers in $COMPOSE_DIR..."

# Stop and remove containers, networks, and anonymous volumes
# -v: Removes named volumes
# --remove-orphans: Removes containers for services not defined in the Compose file
docker compose down -v --remove-orphans

echo "Docker Compose shutdown complete."

Thanks
 
Last edited:
On my Proxmox VE, a short press of the power button does a normal graceful shut down like you are asking for. I do think this is standard Debian behavior and not Proxmox specific.
Does your "Workstation" shut down hard immediately instead? Then check the BIOS/UEFI settings of the motherboard. Usually you can influence the behavior of the short press there. The long press usually always shuts down hard immediately and cannot be changed.
 
  • Like
Reactions: beisser
shutdown -hP now works the same, but thats not what op asked for. @leesteken is right that, if the bios is configured correctly, the powerbutton will gracefully shutdown the computer unless a vm takes longer than 3 minutes to shut down, then that vm will be forcefully killed and the computer itself continues to shut down gracefully.

if it immediately powers off that means the behaviour is misconfigured in the bios and needs to be fixed there.
 
An example for when I press the power button, I want a similar script to run in the VM.


Bash:
#!/bin/bash

# Define the directory where your docker-compose.yml file is located
COMPOSE_DIR="/path/to/your/project"

cd "$COMPOSE_DIR"

echo "Stopping and removing Docker Compose containers in $COMPOSE_DIR..."

# Stop and remove containers, networks, and anonymous volumes
# -v: Removes named volumes
# --remove-orphans: Removes containers for services not defined in the Compose file
docker compose down -v --remove-orphans

echo "Docker Compose shutdown complete."

Please don't tell me to run the container on the host. Like the posts mentioned above, that is already handled.