11#! /bin/bash
22
3+ # Default VM type is windows if not specified
4+ VM_TYPE=" windows"
5+
6+ # Get the directory where the script is located
7+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
8+ # Get the parent directory (omnibox directory)
9+ OMNIBOX_DIR=" $( cd " $SCRIPT_DIR /.." && pwd ) "
10+
311create_vm () {
4- if ! docker images windows-local -q | grep -q . ; then
12+ local dockerfile=" Dockerfile"
13+ local compose_file=" compose.yml"
14+ local image_name=" windows-local"
15+
16+ if [ " $VM_TYPE " == " linux" ]; then
17+ dockerfile=" Dockerfile.linux"
18+ compose_file=" compose.linux.yml"
19+ image_name=" linux-local"
20+ fi
21+
22+ if ! docker images $image_name -q | grep -q . ; then
523 echo " Image not found locally. Building..."
6- docker build -t windows-local ..
24+ docker build --no-cache --pull -t $image_name -f " $OMNIBOX_DIR / $dockerfile " " $OMNIBOX_DIR "
725 else
826 echo " Image found locally. Skipping build."
927 fi
1028
11- docker compose -f ../compose.yml up -d
29+ docker compose -f " $OMNIBOX_DIR / $compose_file " up -d
1230
1331 # Wait for the VM to start up
1432 while true ; do
@@ -20,12 +38,39 @@ create_vm() {
2038 sleep 5
2139 done
2240
23- echo " VM + server is up and running!"
41+ echo " $VM_TYPE VM + server is up and running!"
2442}
2543
2644start_vm () {
27- echo " Starting VM..."
28- docker compose -f ../compose.yml start
45+ local compose_file=" compose.yml"
46+
47+ if [ " $VM_TYPE " == " linux" ]; then
48+ compose_file=" compose.linux.yml"
49+ fi
50+
51+ echo " Starting $VM_TYPE VM..."
52+
53+ # Show container status before starting
54+ echo " Container status before starting:"
55+ docker compose -f " $OMNIBOX_DIR /$compose_file " ps
56+
57+ # Start the containers
58+ docker compose -f " $OMNIBOX_DIR /$compose_file " start
59+
60+ # Show container status after starting
61+ echo " Container status after starting:"
62+ docker compose -f " $OMNIBOX_DIR /$compose_file " ps
63+
64+ # Check if containers are running
65+ if docker compose -f " $OMNIBOX_DIR /$compose_file " ps --status running | grep -q . ; then
66+ echo " Containers are running."
67+ else
68+ echo " Warning: No containers appear to be running. Check logs for details."
69+ echo " Container logs:"
70+ docker compose -f " $OMNIBOX_DIR /$compose_file " logs --tail=20
71+ fi
72+
73+ # Uncomment this section if you want to wait for the server to respond
2974 while true ; do
3075 response=$( curl --write-out ' %{http_code}' --silent --output /dev/null localhost:5000/probe)
3176 if [ $response -eq 200 ]; then
@@ -34,29 +79,70 @@ start_vm() {
3479 echo " Waiting for a response from the computer control server"
3580 sleep 5
3681 done
37- echo " VM started"
82+
83+ echo " $VM_TYPE VM started"
3884}
3985
4086stop_vm () {
41- echo " Stopping VM..."
42- docker compose -f ../compose.yml stop
43- echo " VM stopped"
87+ local compose_file=" compose.yml"
88+
89+ if [ " $VM_TYPE " == " linux" ]; then
90+ compose_file=" compose.linux.yml"
91+ fi
92+
93+ echo " Stopping $VM_TYPE VM..."
94+ docker compose -f " $OMNIBOX_DIR /$compose_file " stop
95+ echo " $VM_TYPE VM stopped"
4496}
4597
4698delete_vm () {
47- echo " Removing VM and associated containers..."
48- docker compose -f ../compose.yml down
49- echo " VM removed"
99+ local compose_file=" compose.yml"
100+ local image_name=" windows-local"
101+
102+ if [ " $VM_TYPE " == " linux" ]; then
103+ compose_file=" compose.linux.yml"
104+ image_name=" linux-local"
105+ fi
106+
107+ echo " Removing $VM_TYPE VM and associated containers..."
108+ docker compose -f " $OMNIBOX_DIR /$compose_file " down
109+ docker rmi $image_name
110+ echo " $VM_TYPE VM removed"
50111}
51112
52- # Check if control parameter is provided
53- if [ -z " $1 " ]; then
54- echo " Usage: $0 [create|start|stop|delete]"
113+ # Parse command line arguments
114+ while [[ $# -gt 0 ]]; do
115+ case " $1 " in
116+ create|start|stop|delete)
117+ COMMAND=" $1 "
118+ shift
119+ ;;
120+ --linux)
121+ VM_TYPE=" linux"
122+ shift
123+ ;;
124+ --windows)
125+ VM_TYPE=" windows"
126+ shift
127+ ;;
128+ * )
129+ echo " Unknown option: $1 "
130+ echo " Usage: $0 [create|start|stop|delete] [--linux|--windows]"
131+ exit 1
132+ ;;
133+ esac
134+ done
135+
136+ # Check if command is provided
137+ if [ -z " $COMMAND " ]; then
138+ echo " Usage: $0 [create|start|stop|delete] [--linux|--windows]"
139+ echo " --linux Use Linux VM configuration (default is Windows)"
140+ echo " --windows Use Windows VM configuration"
55141 exit 1
56142fi
57143
58- # Execute the appropriate function based on the control parameter
59- case " $1 " in
144+ # Execute the appropriate function based on the command
145+ case " $COMMAND " in
60146 " create" )
61147 create_vm
62148 ;;
@@ -69,9 +155,4 @@ case "$1" in
69155 " delete" )
70156 delete_vm
71157 ;;
72- * )
73- echo " Invalid option: $1 "
74- echo " Usage: $0 [create|start|stop|delete]"
75- exit 1
76- ;;
77158esac
0 commit comments