#!/bin/sh -e


# you can use /bin/df > /path/to/file.txt to see at this point which (you can
# place the command at the beginning of /etc/rc.local also to get all
# directories that are mounted. I first tried to use /run/user which turned
# out was not available and the virtual machine was not initiated. The
# directory /run is available and mounted as tmpfs so it will do the
# work.


MONITOR_SOCKET_DIR=/run

# start say sql server
/usr/bin/qemu-system-x86_64 -enable-kvm\
	-m 4096 -cpu host -smp 4\
	-drive file=/path/to/vm01_sql.qcow2 \
	-nic tap,mac=E1:B4:AD:2B:D3:01 \
	-monitor unix:$MONITOR_SOCKET_DIR/vm01_sql.sock,server,nowait \
	-display none \
	-serial null \
	-daemonize \
	-pidfile $MONITOR_SOCKET_DIR/vm01.pid \
	-name vm01_sql,process=vm01_sql

# these are equivalent
# 	-nic tap,mac=E1:B4:AD:2B:D3:01 \
#	-device e1000,netdev=v1eth,mac=E1:B4:AD:2B:D3:01  -netdev tap,id=v1eth \
# 
# for debuggin you can use redirect the serial output to a file with
#	-serial file:/path/to/file.txt \
# or to a socket but to use a socket the socket must first be created
#	-serial unix:$MONITOR_SOCKET_DIR/serial_sql.sock \
#
# You can see the output of qemu command by redirecting its output to a file
# with
#	-name vm01_sql,process=vm01_sql >> /home/bustaoglu/qmerr.txt 2>&1


# start a second virtual machine
/usr/bin/qemu-system-x86_64 -enable-kvm\
	-m 8192 -cpu host -smp 4\
	-drive file=/path/to/vm02_www.qcow2 \
	-nic tap,mac=E1:B4:AD:2B:D3:02  \
	-monitor unix:$MONITOR_SOCKET_DIR/vm02_www.sock,server,nowait \
	-display none \
	-serial null \
	-daemonize \
	-pidfile $MONITOR_SOCKET_DIR/vm02.pid \
	-name vm02_www,process=vm02_www

exit 0
