Windows 종료시 VirtualBox VM 종료를 잊어버리는 분들에게
6129 단어 VirtualBox셧다운

VirtualBox Interface
이 응용 프로그램은 종료를 방해합니다.
나도 이것이 나오면 「우와・・・또 하고 버렸다・・・」가 됩니다

그런 다음 데스크톱으로 돌아가서 작업 관리자를 열고
VirtualBox Interface
를 종료하십시오.모처럼 빨리 돌아갈 수 있다고 생각했는데

이번에는, 그런 고민을 쉘 스크립트로 해결해 보려고 생각합니다

대책?
대책은 간단합니다

즈발리,
PC를 종료하기 전에 모든 VM 종료
입니다

라고 할까, 이것을 잊어 버리기 때문에 곤란하고 있는 것입니다만

종료 명령을 준비합시다.
Windows 종료는 명령으로 실행할 수 있습니다.
shutdown -s -t 0
-s
는 종료, -t 0
는 처리가 실행되기까지의 시간 (초)을 나타냅니다.이 예의 경우라면, 「0 초가 지나면 셧다운」, 즉 즉시 셧다운을 의미하고 있습니다.
종료 명령에 대해서는 이 기사 을 참고로 했습니다.
부팅중인 모든 VM을 종료하는 명령을 준비합시다.
VirtualBox 에는 VM 의 조작을 커멘드 라인으로 실시할 수 있는
VBoxManage
가 준비되어 있습니다.이것을 이용해, 기동중의 VM 를 일람으로 표시해, 그것을 셧다운의 인수에 건네주도록(듯이) 합니다.
bash: VBoxManage: command not found
가 되려면 VBoxManage
를 환경 변수에 등록하십시오.VBoxManage
의 위치에 대해서는 【VirtualBox】VBoxManage 사용 - Qiita가 참고가 될까 생각합니다.VBoxManage list runningvms | cut -d' ' -f1 | xargs -I{} VBoxManage controlvm {} acpipowerbutton
VBoxManage 명령은 Virtualbox 가상 머신을 명령줄에서 작업 - Qiita을 참조했습니다.
스크립트를 완성하자.
필요한 명령은 갖추었으므로, 드디어 스크립트를 만들어 가려고 생각합니다.
정책은 간단하며 시작 중인 모든 VM을 종료한 다음 Windows를 종료할 뿐이지만 함정이 하나 있습니다.
VM 를 종료하는 커멘드는, VM 의 셧다운 시그널을 보내는 것만으로 곧바로 처리가 끝나, VM 의 셧다운을 기다리지 않습니다.
따라서 위의 두 명령을 그대로 나란히 실행하면 VM이 종료되지 않고 PC 종료로 들어갑니다

이를 방지하기 위해 시작 중인 VM 목록을 정기적으로 명령으로 확인하고 출력이 없어진 후 PC를 종료하는 과정을 설명합니다.
shutdown_vms.sh
#!/usr/bin/env bash
INTERVAL=3 # 起動中の VM 一覧を確認する周期
VBoxManage list runningvms | cut -d' ' -f1 | xargs -I{} VBoxManage controlvm {} acpipowerbutton
while [ $(VBoxManage list runningvms | wc -l) -ne 0 ]
do
echo "shutting down VMs..."
sleep ${INTERVAL}
done
그런 다음 종료할 때 실행할 파일을 만듭니다.
shutdown_entrypoint.sh
#!/usr/bin/env bash
./shutdown_vms.sh
wait
echo "bye"
sleep 1
shutdown -s -t 0
이것으로 완성됩니다


동작을 확인합시다.
shutdown_vms.sh
와 shutdown_entrypoint.sh
를 같은 디렉터리에 넣습니다. shutdown_entrypoint.sh
를 두 번 클릭하거나 Git Bash에서 ./shutdown_entrypoint.sh
를 실행합니다. 이런 느낌으로 출력되고 있으면 잘 되고 있습니다

shutting down VMs...
shutting down VMs...
shutting down VMs...
bye
여러분도 몸의 귀찮은 일을 자동화해 쾌적하게 개발해, 쾌적하게 집에 돌아갑시다


Reference
이 문제에 관하여(Windows 종료시 VirtualBox VM 종료를 잊어버리는 분들에게), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/noritakaIzumi/items/5b9843284425a9523ed5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)