-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop-vm.sh
More file actions
executable file
·65 lines (58 loc) · 1.43 KB
/
stop-vm.sh
File metadata and controls
executable file
·65 lines (58 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#
# This stops a given vm
#
# gnd @ gnd.sk, 2017 - 2019
#
####################################################################
# Check if LIMA_ROOT set
if [ -z $LIMA_ROOT ]; then
echo "Cant find LIMA. Please check if the install finished correctly."
echo "Exiting. Reason: LIMA_ROOT not set."
exit
fi
# Define globals
source $LIMA_ROOT/vms/settings
usage() {
printf "\n"
printf "This stops the given VM\n"
printf "Usage: \n"
printf "$0 <name NAME> \n\n"
}
### Check if VM_NAME is unique and existing, otherwise exit
case "$1" in
'name')
VM_NAME=$2
LINS=`cat $VM_LIST | awk {'print $2;'}|grep "^$VM_NAME$"|wc -l`
if [[ $LINS -lt 1 ]]; then
printf "\n$0: No such name $VM_NAME found\n\n"
exit
fi
if [[ $LINS -gt 1 ]]; then
printf "\n$0: More names like '$VM_NAME' found, please be specific:\n"
cat $VM_LIST | awk {'print $2;'}|grep "^$VM_NAME$"
printf "\n"
exit
fi
;;
*)
usage
exit
;;
esac
### Check if the VM runs first
CHECK=`virsh list --all|grep " $VM_NAME "`
if [[ -z $CHECK ]]; then
printf "\n$0: Warning: $VM_NAME not running.\n"
else
### Stop the VM
printf "Stoping $VM_NAME\n"
virsh destroy $VM_NAME
### Sleep for a while
sleep 1 # this is so arbitrary
### Check if successfull
CHECK=`virsh list --all|grep " $VM_NAME "`
if [[ ! -z $CHECK ]]; then
printf "$0: Warning: $VM_NAME still running.\n\n"
fi
fi