unix useradd and chown
This commit is contained in:
parent
3ab4fa63fc
commit
33d473a6e1
18
nlvmi
18
nlvmi
|
@ -110,16 +110,24 @@ function vmstart {
|
||||||
if [ $LOGLEVEL -gt "1" ]; then echo "startvm function entered for vmid $1"; fi
|
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
|
sqlite3 $SQLITEFILE "SELECT * FROM vms WHERE id=$1" | while read line; do
|
||||||
IFS='|' read -r -a array <<< "$line"
|
IFS='|' read -r -a array <<< "$line"
|
||||||
|
if ! `id -u ${array[2]} &>/dev/null`; then
|
||||||
|
useradd ${array[2]} -d /run/nlvmi -g nlvmi -M -s /bin/false -G kvm;
|
||||||
|
if [ $LOGLEVEL -gt "1" ]; then echo "user ${array[2]} created"; fi
|
||||||
|
fi
|
||||||
|
if [ -e $RUNDIRECTORY/${array[1]}.* ]; then
|
||||||
|
if [ $LOGLEVEL -gt "1" ]; then echo "chowning pid and monfiles "; fi
|
||||||
|
chown ${array[2]}:nlvmi $RUNDIRECTORY/${array[1]}.*
|
||||||
|
fi
|
||||||
if [ ! -z ${array[5]} ]; then CPUTYPE="-cpu ${array[5]}"; fi
|
if [ ! -z ${array[5]} ]; then CPUTYPE="-cpu ${array[5]}"; fi
|
||||||
if [ ! -z ${array[6]} ]; then SMP="-smp ${array[6]}"; fi
|
if [ ! -z ${array[6]} ]; then SMP="-smp ${array[6]}"; fi
|
||||||
if [ ! -z ${array[7]} ]; then MEMORY="-m ${array[7]}"; 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[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[10]} ]; then CUSTOM="${array[10]}"; fi
|
||||||
if [ ! -z ${array[13]} ]; then DRIVE1="-drive file=${array[13]}"; fi
|
if [ ! -z ${array[13]} ]; then DRIVE1="-drive file=${array[13]}"; chown ${array[2]}:nlvmi ${array[13]}; fi
|
||||||
if [ ! -z ${array[14]} ]; then FORMAT1=",format=${array[14]},if=virtio"; 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[15]} ]; then DRIVE2="-drive file=${array[15]}"; chown ${array[2]}:nlvmi ${array[15]}; fi
|
||||||
if [ ! -z ${array[16]} ]; then FORMAT2=",format=${array[16]},if=virtio"; 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[17]} ]; then DRIVE3="-drive file=${array[17]}"; chown ${array[2]}:nlvmi ${array[17]}; fi
|
||||||
if [ ! -z ${array[18]} ]; then FORMAT3=",format=${array[18]},if=virtio"; 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[19]} ]; then CDROM="-cdrom ${array[19]}"; fi
|
||||||
if [ ! -z ${array[20]} ]; then TAPDEV1="-netdev tap,ifname=${array[20]},script=no,id=net0"; tunctl -t ${array[20]} -u ${array[2]} && ifconfig ${array[20]} up; fi
|
if [ ! -z ${array[20]} ]; then TAPDEV1="-netdev tap,ifname=${array[20]},script=no,id=net0"; tunctl -t ${array[20]} -u ${array[2]} && ifconfig ${array[20]} up; fi
|
||||||
|
@ -133,7 +141,7 @@ function vmstart {
|
||||||
if [ ! -z ${array[28]} ]; then BRDEV3="${array[28]}"; brctl addif ${array[28]} ${array[26]}; fi
|
if [ ! -z ${array[28]} ]; then BRDEV3="${array[28]}"; brctl addif ${array[28]} ${array[26]}; fi
|
||||||
if [ ! -z ${array[30]} ]; then WEBSOCK=",websocket=${array[30]}"; else WEBSOCK=""; fi
|
if [ ! -z ${array[30]} ]; then WEBSOCK=",websocket=${array[30]}"; else WEBSOCK=""; fi
|
||||||
if [ ! -z ${array[29]} ]; then VNCPORT="-vnc :${array[29]}$WEBSOCK,password"; fi
|
if [ ! -z ${array[29]} ]; then VNCPORT="-vnc :${array[29]}$WEBSOCK,password"; fi
|
||||||
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 $MACADDR2 $TAPDEV2 $MACADDR3 $TAPDEV3 $VNCPORT $CUSTOM -pidfile $RUNDIRECTORY/${array[1]}.pid -monitor unix:$RUNDIRECTORY/${array[1]}.mon,server,nowait")
|
COMMAND=(su - ${array[2]} -s /bin/bash -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 $MACADDR2 $TAPDEV2 $MACADDR3 $TAPDEV3 $VNCPORT $CUSTOM -pidfile $RUNDIRECTORY/${array[1]}.pid -monitor unix:$RUNDIRECTORY/${array[1]}.mon,server,nowait")
|
||||||
if [ $LOGLEVEL -gt "1" ]; then echo ${COMMAND[@]}; fi
|
if [ $LOGLEVEL -gt "1" ]; then echo ${COMMAND[@]}; fi
|
||||||
`"${COMMAND[@]}"`
|
`"${COMMAND[@]}"`
|
||||||
#Set VNC Password
|
#Set VNC Password
|
||||||
|
@ -153,7 +161,7 @@ function vmstop {
|
||||||
STOPPED="no"
|
STOPPED="no"
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
while [ $STOPPED = "no" ]; do
|
while [ $STOPPED = "no" ]; do
|
||||||
if [ $COUNTER==100 ]; then
|
if [ $COUNTER == 200 ]; then
|
||||||
kill `cat $RUNDIRECTORY/${array[1]}.pid`
|
kill `cat $RUNDIRECTORY/${array[1]}.pid`
|
||||||
echo "${array[1]} forcefully killed!";
|
echo "${array[1]} forcefully killed!";
|
||||||
STOPPED="yes"
|
STOPPED="yes"
|
||||||
|
|
|
@ -396,13 +396,13 @@ if (isset($_SESSION['username'])){
|
||||||
echo "</div></div></div></div><input type=hidden id=archbuttonh name=arch value=x86_64>";
|
echo "</div></div></div></div><input type=hidden id=archbuttonh name=arch value=x86_64>";
|
||||||
// echo "$arrColnames[$col] <select name=arch><option value=qemu-system-x86_64>x86_64</option></select></br>";
|
// echo "$arrColnames[$col] <select name=arch><option value=qemu-system-x86_64>x86_64</option></select></br>";
|
||||||
} elseif (preg_match('/format/', $arrColnames[$col])){
|
} elseif (preg_match('/format/', $arrColnames[$col])){
|
||||||
echo "<div class=row><div class=col>$arrColnames[$col]</div><div class=col><div class=dropdown><button class=\"btn btn-secondary dropdown-toggle\" type=button id=formatbutton$arrColnames[$col] data-toggle=dropdown aria-haspopup=true aria-expanded=false>$val</button>";
|
echo "<div class=row><div class=col>$arrColnames[$col]</div><div class=col><div class=dropdown><button class=\"btn btn-secondary dropdown-toggle\" type=button id=$arrColnames[$col]button$arrColnames[$col] data-toggle=dropdown aria-haspopup=true aria-expanded=false>$val</button>";
|
||||||
echo "<div class=dropdown-menu aria-labelledby=formatbutton$arrColnames[$col]>";
|
echo "<div class=dropdown-menu aria-labelledby=formatbutton$arrColnames[$col]>";
|
||||||
echo "<a class=dropdown-item href=\"javascript:dropdown('formatbutton$arrColnames[$col]','')\"> </a>";
|
echo "<a class=dropdown-item href=\"javascript:dropdown('$arrColnames[$col]button$arrColnames[$col]','')\"> </a>";
|
||||||
echo "<div class=dropdown-divider></div>";
|
echo "<div class=dropdown-divider></div>";
|
||||||
echo "<a class=dropdown-item href=\"javascript:dropdown('formatbutton$arrColnames[$col]','raw')\">raw</a>";
|
echo "<a class=dropdown-item href=\"javascript:dropdown('$arrColnames[$col]button$arrColnames[$col]','raw')\">raw</a>";
|
||||||
echo "<a class=dropdown-item href=\"javascript:dropdown('formatbutton$arrColnames[$col]','qcow2')\">qcow2</a>";
|
echo "<a class=dropdown-item href=\"javascript:dropdown('$arrColnames[$col]button$arrColnames[$col]','qcow2')\">qcow2</a>";
|
||||||
echo "</div></div></div></div></div><input type=hidden id=formatbutton$arrColnames[$col]h name=arch value=x86_64>";
|
echo "</div></div></div></div></div><input type=hidden id=$arrColnames[$col]button$arrColnames[$col]h name=$arrColnames[$col] value=\"$val\">";
|
||||||
} elseif ($arrColnames[$col] == "autostart"){
|
} elseif ($arrColnames[$col] == "autostart"){
|
||||||
$checked="";
|
$checked="";
|
||||||
if ($val=="1"){
|
if ($val=="1"){
|
||||||
|
|
Loading…
Reference in New Issue