New DataBase-Schema and nlvmi start stop function reconfigured
This commit is contained in:
parent
1834f8df55
commit
ae851b491c
95
nlvmi
95
nlvmi
|
@ -42,33 +42,36 @@ function createdb {
|
|||
sqlite3 $SQLITEFILE "CREATE TABLE vms (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
vmname VARCHAR(50) NOT NULL,
|
||||
server VARCHAR(50),
|
||||
user VARCHAR(50) NOT NULL,
|
||||
autostart INTEGER,
|
||||
bootoption VARCHAR(2) NOT NULL,
|
||||
drive1 VARCHAR(50),
|
||||
drive2 VARCHAR(50),
|
||||
drive3 VARCHAR(50),
|
||||
cdrom VARCHAR(50),
|
||||
server VARCHAR(50),
|
||||
arch VARCHAR(50) NOT NULL,
|
||||
mac VARCHAR(50),
|
||||
brdev1 VARCHAR(50),
|
||||
brdev2 VARCHAR(50),
|
||||
brdev3 VARCHAR(50),
|
||||
cputype VARCHAR(50),
|
||||
cpus INTEGER,
|
||||
memory INTEGER,
|
||||
usbdev VARCHAR(50),
|
||||
kblang VARCHAR(50),
|
||||
custom VARCHAR(50),
|
||||
bootoption VARCHAR(2) NOT NULL,
|
||||
autostart INTEGER,
|
||||
drive1 VARCHAR(50),
|
||||
format1 VARCHAR(50),
|
||||
drive2 VARCHAR(50),
|
||||
format2 VARCHAR(50),
|
||||
drive3 VARCHAR(50),
|
||||
format3 VARCHAR(50),
|
||||
cdrom VARCHAR(50),
|
||||
tapdev1 VARCHAR(50),
|
||||
macaddr1 VARCHAR(50),
|
||||
brdev1 VARCHAR(50),
|
||||
tapdev2 VARCHAR(50),
|
||||
macaddr2 VARCHAR(50),
|
||||
brdev2 VARCHAR(50),
|
||||
tapdev3 VARCHAR(50),
|
||||
macaddr3 VARCHAR(50),
|
||||
brdev3 VARCHAR(50),
|
||||
vncport VARCHAR(50),
|
||||
websocket INTEGER,
|
||||
vncpasswort VARCHAR(50),
|
||||
usbdev1 VARCHAR(50),
|
||||
usbdev2 VARCHAR(50),
|
||||
usbdev3 VARCHAR(50),
|
||||
kblang VARCHAR(50),
|
||||
memory INTEGER,
|
||||
cpus INTEGER,
|
||||
custom VARCHAR(50),
|
||||
cputype VARCHAR(50)
|
||||
vncpasswort VARCHAR(50)
|
||||
);"
|
||||
sqlite3 $SQLITEFILE "CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
@ -97,28 +100,36 @@ function vmstart {
|
|||
if [ $LOGLEVEL -gt "1" ]; then echo "startvm function entered for vmid $1"; fi
|
||||
sqlite3 $SQLITEFILE "SELECT * FROM vms WHERE id=$1" | while read line; do
|
||||
IFS='|' read -r -a array <<< "$line"
|
||||
if [ ! -z ${array[6]} ]; then DRIVE1="-drive file=${array[6]},cache=none,format=raw,if=virtio,aio=native"; fi
|
||||
if [ ! -z ${array[7]} ]; then DRIVE2="-drive file=${array[7]},cache=none,format=raw,if=virtio,aio=native"; fi
|
||||
if [ ! -z ${array[8]} ]; then DRIVE3="-drive file=${array[8]},cache=none,format=raw,if=virtio,aio=native"; fi
|
||||
if [ ! -z ${array[9]} ]; then CDROM="-cdrom ${array[9]}"; fi
|
||||
if [ ! -z ${array[11]} ]; then NETDEV1="-net nic,macaddr=${array[11]},model=virtio,netdev=net0"; fi
|
||||
if [ ! -z ${array[15]} ]; then TAPDEV1="-netdev tap,ifname=${array[15]},script=no,id=net0"; fi
|
||||
if [ ! -z ${array[16]} ]; then TAPDEV2="-netdev tap,ifname=${array[16]},script=no,id=net0"; fi
|
||||
if [ ! -z ${array[17]} ]; then TAPDEV3="-netdev tap,ifname=${array[17]},script=no,id=net0"; fi
|
||||
if [ ! -z ${array[18]} ]; then VNCPORT="-vnc ${array[18]},websocket=${array[19]},password"; fi
|
||||
if [ ! -z ${array[21]} ]; then USBDEV1="-usb -device usb-ehci,id=ehci -device usb-${array[21]},bus=usb-bus.0"; fi
|
||||
if [ ! -z ${array[28]} ]; then CPUTYPE="-cpu ${array[28]}"; fi
|
||||
if [ ! -z ${array[26]} ]; then SMP="-smp ${array[26]}"; fi
|
||||
if [ ! -z ${array[25]} ]; then MEMORY="-m ${array[25]}"; fi
|
||||
if [ ! -z ${array[27]} ]; then CUSTOM="${array[27]}"; fi
|
||||
# tunctl -t $TAPDEV1 -u ${array[3]}
|
||||
# brctl addif br0 $TAPDEV1
|
||||
# ifconfig $TAPDEV1 up
|
||||
COMMAND=(su ${array[3]} -c "${array[10]} -enable-kvm $CPUTYPE $MEMORY $SMP -boot ${array[5]} $USBDEV1 -k ${array[24]} -daemonize $DRIVE1 $DRIVE2 $DRIVE3 $CDROM $NETDEV1 $TAPDEV1 $TAPDEV2 $TAPDEV3 $VNCPORT $CUSTOM -pidfile $RUNDIRECTORY/${array[1]}.pid -monitor unix:$RUNDIRECTORY/${array[1]}.mon,server,nowait")
|
||||
if [ ! -z ${array[5]} ]; then CPUTYPE="-cpu ${array[5]}"; fi
|
||||
if [ ! -z ${array[6]} ]; then SMP="-smp ${array[6]}"; fi
|
||||
if [ ! -z ${array[7]} ]; then MEMORY="-m ${array[7]}"; fi
|
||||
if [ ! -z ${array[8]} ]; then USBDEV="-usb -device usb-ehci,id=ehci -device usb-${array[8]},bus=usb-bus.0"; fi
|
||||
if [ ! -z ${array[10]} ]; then CUSTOM="${array[10]}"; fi
|
||||
if [ ! -z ${array[13]} ]; then DRIVE1="-drive file=${array[13]}"; fi
|
||||
if [ ! -z ${array[14]} ]; then FORMAT1=",format=${array[14]},if=virtio"; fi
|
||||
if [ ! -z ${array[15]} ]; then DRIVE2="-drive file=${array[15]},format=raw,if=virtio,aio=native"; fi
|
||||
if [ ! -z ${array[16]} ]; then FORMAT2=",format=${array[16]},if=virtio"; fi
|
||||
if [ ! -z ${array[17]} ]; then DRIVE3="-drive file=${array[17]},format=raw,if=virtio,aio=native"; fi
|
||||
if [ ! -z ${array[18]} ]; then FORMAT3=",format=${array[18]},if=virtio"; fi
|
||||
if [ ! -z ${array[19]} ]; then CDROM="-cdrom ${array[19]}"; fi
|
||||
if [ ! -z ${array[20]} ]; then TAPDEV1="-netdev tap,ifname=${array[20]},script=no,id=net0"; fi
|
||||
if [ ! -z ${array[21]} ]; then MACADDR1="-net nic,macaddr=${array[21]},model=virtio,netdev=net0"; fi
|
||||
if [ ! -z ${array[22]} ]; then BRDEV1="${array[22]}"; fi
|
||||
if [ ! -z ${array[23]} ]; then TAPDEV2="-netdev tap,ifname=${array[23]},script=no,id=net0"; fi
|
||||
if [ ! -z ${array[24]} ]; then MACADDR2="-net nic,macaddr=${array[24]},model=virtio,netdev=net0"; fi
|
||||
if [ ! -z ${array[25]} ]; then BRDEV2="${array[25]}"; fi
|
||||
if [ ! -z ${array[26]} ]; then TAPDEV3="-netdev tap,ifname=${array[26]},script=no,id=net0"; fi
|
||||
if [ ! -z ${array[27]} ]; then MACADDR3="-net nic,macaddr=${array[27]},model=virtio,netdev=net0"; fi
|
||||
if [ ! -z ${array[28]} ]; then BRDEV3="${array[28]}"; fi
|
||||
if [ ! -z ${array[29]} ]; then VNCPORT="-vnc ${array[29]},websocket=${array[30]},password"; fi
|
||||
# tunctl -t ${array[20]} -u ${array[2]}
|
||||
# brctl addif ${array[22]} ${array[20]}
|
||||
# ifconfig ${array[20]} up
|
||||
COMMAND=(su ${array[2]} -c "${array[4]} -enable-kvm $CPUTYPE $MEMORY $SMP -boot ${array[11]} $USBDEV -k ${array[9]} -daemonize $DRIVE1$FORMAT1 $DRIVE2$FORMAT2 $DRIVE3$FORMAT3 $CDROM $MACADDR1 $TAPDEV1 $BRDEV1 $MACADDR2 $TAPDEV2 $BRDEV2 $MACADDR3 $TAPDEV3 $BRDEV3 $VNCPORT $CUSTOM -pidfile $RUNDIRECTORY/${array[1]}.pid -monitor unix:$RUNDIRECTORY/${array[1]}.mon,server,nowait")
|
||||
if [ $LOGLEVEL -gt "1" ]; then echo ${COMMAND[@]}; fi
|
||||
`"${COMMAND[@]}"`
|
||||
#Set VNC Password
|
||||
# echo "change vnc password ${array[20]}" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null
|
||||
# echo "change vnc password ${array[31]}" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null
|
||||
done
|
||||
export VMFOUND="yes"
|
||||
}
|
||||
|
@ -140,7 +151,7 @@ function vmstop {
|
|||
#mainloop
|
||||
if [ $# -gt 0 ]; then
|
||||
if [ $1 == "createdb" ]; then
|
||||
createdb
|
||||
createdb
|
||||
elif [ $1 == "autostart" ]; then
|
||||
vmautostart
|
||||
elif [ $1 == "start" ]; then
|
||||
|
@ -155,7 +166,6 @@ if [ $# -gt 0 ]; then
|
|||
done
|
||||
if [[ $VMFOUND == "no" ]]; then echo "no VM with that name found!"; exit 1; fi)
|
||||
elif [ $1 == "stop" ]; then
|
||||
echo $1 $2
|
||||
if [ -z $2 ]; then echo "stop needs a vmname!"; exit 1; fi
|
||||
VMFOUND="no"
|
||||
if [ $LOGLEVEL -gt "1" ]; then echo "searching for vmname $2"; fi
|
||||
|
@ -166,8 +176,7 @@ echo $1 $2
|
|||
vmstop $2
|
||||
done
|
||||
if [[ $VMFOUND == "no" ]]; then echo "no VM with that name found!"; exit 1; fi)
|
||||
|
||||
fi
|
||||
fi
|
||||
else
|
||||
checkdb
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue