Bash scripts for power button

neatrasm

New Member
Jan 10, 2026
16
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 using a bash script inside the VMs when pressing or holding the physical power button.

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



Here is a boilerplate 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:
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.
 
the answer is still the same.

when you push the button once it will start (gracefully) shutting down all the vms in reverse order from startup.
its as if you tell the vm to shutdown via the context menu in the pve-gui.

the only way it doesnt do that is if the vm refuses to shut down within 180 seconds or 3 minutes after which it assumes the vm hangs and forcefully kills it.
 
If the proprietary software inside the VM doesn't do a shutdown procedure I lose data.

I can manually do this, but I want to run a bash script to save my data.
Google Gemini says to reinstall acpid on the Debian VM so I can hook a bash script for shutdown of the custom software.
This seems insane to me because the qemu agent is there...doing stuff.

How am I wording this question wrong? Help me word this correctly please.