Commit f39d03af authored by Vitaly Lipatov's avatar Vitaly Lipatov

pve: add pve-stop.sh to stop VM/CT by VMID

Default is graceful shutdown; --force issues an immediate stop. No-op when the resource is already stopped. Co-Authored-By: 's avatarClaude Opus 4.7 (1M context) <noreply@anthropic.com>
parent d4c9d940
#!/bin/sh
# Stop VM or CT by VMID
# Usage: pve-stop.sh VMID [--force]
set -e
MYDIR=$(dirname "$0")
. "$MYDIR/functions"
FORCE=""
VMID=""
while [ $# -gt 0 ] ; do
case "$1" in
--force) FORCE=1 ; shift ;;
--help|-h)
echo "Usage: $(basename "$0") VMID [--force]" >&2
echo "Stop a VM or CT. Default: graceful shutdown. --force: immediate stop." >&2
exit 0
;;
*) VMID="$1" ; shift ;;
esac
done
if [ -z "$VMID" ] ; then
echo "Usage: $(basename "$0") VMID [--force]" >&2
exit 1
fi
resolve_vmid "$VMID"
mgr=$(vm_mgr)
if [ "$RES_STATUS" = "stopped" ] ; then
log "$RES_TYPE $VMID ($RES_NAME) is already stopped on $RES_NODE"
exit 0
fi
if [ -n "$FORCE" ] ; then
log "Force stopping $RES_TYPE $VMID ($RES_NAME) on $RES_NODE ..."
vm_cmd "$mgr" stop "$VMID"
else
log "Shutting down $RES_TYPE $VMID ($RES_NAME) on $RES_NODE ..."
vm_cmd "$mgr" shutdown "$VMID"
fi
log "Done."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment