remote ssh checkvm, stopvm
This commit is contained in:
parent
03499dd17c
commit
edc5dddb8c
41
nlvmi
41
nlvmi
|
@ -156,7 +156,11 @@ function vmstart {
|
||||||
#Set VNC Password
|
#Set VNC Password
|
||||||
echo "echo \"change vnc password ${array[31]}\" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null" >>$TMPF
|
echo "echo \"change vnc password ${array[31]}\" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null" >>$TMPF
|
||||||
if [ ! -z "${array[34]}" ]; then
|
if [ ! -z "${array[34]}" ]; then
|
||||||
|
echo "chmod g+w $RUNDIRECTORY/${array[1]}.mon" >>$TMPF
|
||||||
su nlvmi -c "scp $TMPF ${array[34]}:/home/nlvmi/"
|
su nlvmi -c "scp $TMPF ${array[34]}:/home/nlvmi/"
|
||||||
|
su nlvmi -c "ssh ${array[34]} \"/usr/bin/nlvmi remote $TMPF run\""
|
||||||
|
su nlvmi -c "ssh ${array[34]} \"rm $TMPF\""
|
||||||
|
rm $TMPF
|
||||||
else
|
else
|
||||||
/bin/bash $TMPF
|
/bin/bash $TMPF
|
||||||
rm $TMPF
|
rm $TMPF
|
||||||
|
@ -167,22 +171,34 @@ function vmstart {
|
||||||
|
|
||||||
#stop VM
|
#stop VM
|
||||||
function vmstop {
|
function vmstop {
|
||||||
if [ ! -e $RUNDIRECTORY/$1.pid ]; then echo "pidfile $RUNDIRECTORY/$1.pid does not exist"; exit 1; fi
|
|
||||||
if [ $LOGLEVEL -gt "1" ]; then echo "stopvm function entered for VM $1"; fi
|
if [ $LOGLEVEL -gt "1" ]; then echo "stopvm function entered for VM $1"; fi
|
||||||
sqlite3 $SQLITEFILE "SELECT id,vmname FROM vms WHERE vmname='$1'" | while read line; do
|
sqlite3 $SQLITEFILE "SELECT vms.id AS vid,vmname,connectstring FROM vms LEFT JOIN servers ON vms.server = servers.hostname WHERE vmname='$1'" | while read line; do
|
||||||
IFS='|' read -r -a array <<< "$line"
|
IFS='|' read -r -a array <<< "$line"
|
||||||
|
if [ -z ${array[2]} ]; then
|
||||||
|
if [ ! -e $RUNDIRECTORY/$1.pid ]; then echo "pidfile $RUNDIRECTORY/$1.pid does not exist"; exit 1; fi
|
||||||
echo "system_powerdown" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null
|
echo "system_powerdown" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null
|
||||||
|
else
|
||||||
|
su nlvmi -c "ssh ${array[2]} \"echo \\\"system_powerdown\\\" | socat - unix-connect:$RUNDIRECTORY/${array[1]}.mon >/dev/null\""
|
||||||
|
fi
|
||||||
sleep 5s
|
sleep 5s
|
||||||
STOPPED="no"
|
STOPPED="no"
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
while [ $STOPPED = "no" ]; do
|
while [ $STOPPED = "no" ]; do
|
||||||
if [ $COUNTER == 200 ]; then
|
if [ $COUNTER == 200 ]; then
|
||||||
|
if [ -z ${array[2]} ]; 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"
|
||||||
|
else
|
||||||
|
su nlvmi -c "ssh ${array[2]} \"echo \\\"kill \\\$(<\\\"$RUNDIRECTORY/${array[1]}.pid\\\")\\\" >/home/nlvmi/${array[1]}.tmp\""
|
||||||
|
su nlvmi -c "ssh ${array[2]} \"/usr/bin/nlvmi remote /home/nlvmi/${array[1]}.tmp stop\""
|
||||||
|
su nlvmi -c "ssh ${array[2]} \"rm /home/nlvmi/${array[1]}.tmp\""
|
||||||
|
echo "remotekill"
|
||||||
|
STOPPED="yes"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
((COUNTER++))
|
((COUNTER++))
|
||||||
ps -ef | grep `cat $RUNDIRECTORY/${array[1]}.pid` | grep -v grep >/dev/null || STOPPED="yes"
|
checkvm ${array[1]} | grep "is not running" >/dev/null && STOPPED="yes"
|
||||||
sleep 1s
|
sleep 1s
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
@ -202,7 +218,7 @@ function checkvm {
|
||||||
sqlite3 $SQLITEFILE "SELECT connectstring from vms LEFT JOIN servers ON vms.server = servers.hostname WHERE vmname='$1'" | while read line; do
|
sqlite3 $SQLITEFILE "SELECT connectstring from vms LEFT JOIN servers ON vms.server = servers.hostname WHERE vmname='$1'" | while read line; do
|
||||||
CONN=$line
|
CONN=$line
|
||||||
if [ ! -z $CONN ]; then
|
if [ ! -z $CONN ]; then
|
||||||
su nlvmi -c "ssh 192.168.0.199 \"RPID=\\\$(<\\\"$RUNDIRECTORY/$1.pid\\\"); ps -ef | grep -v grep | grep \\\$RPID\"" &>/dev/null && echo "VM is running" || echo "VM is not running"
|
su nlvmi -c "ssh $CONN \"RPID=\\\$(<\\\"$RUNDIRECTORY/$1.pid\\\"); ps -ef | grep -v grep | grep \\\$RPID | grep qemu\"" &>/dev/null && echo "VM is running" || echo "VM is not running"
|
||||||
else
|
else
|
||||||
ps -ef | grep `cat $RUNDIRECTORY/$1.pid` | grep -v grep >/dev/null && echo "VM is running" || echo "VM is not running"
|
ps -ef | grep `cat $RUNDIRECTORY/$1.pid` | grep -v grep >/dev/null && echo "VM is running" || echo "VM is not running"
|
||||||
|
|
||||||
|
@ -215,11 +231,7 @@ function listdir {
|
||||||
sqlite3 $SQLITEFILE "SELECT $2,connectstring FROM servers WHERE hostname='$1'" | while read line; do
|
sqlite3 $SQLITEFILE "SELECT $2,connectstring FROM servers WHERE hostname='$1'" | while read line; do
|
||||||
IFS='|' read -r -a array <<< "$line"
|
IFS='|' read -r -a array <<< "$line"
|
||||||
IFS=';' read -r -a dirs <<< "${array[0]}"
|
IFS=';' read -r -a dirs <<< "${array[0]}"
|
||||||
# echo ${dirs[1]}
|
|
||||||
# echo ${array[0]}
|
|
||||||
#echo $line
|
|
||||||
for di in ${dirs[@]}; do
|
for di in ${dirs[@]}; do
|
||||||
# echo $di
|
|
||||||
if [ -z ${array[1]} ]; then
|
if [ -z ${array[1]} ]; then
|
||||||
ls -lrt -d -1 $di/{*,.*}
|
ls -lrt -d -1 $di/{*,.*}
|
||||||
else
|
else
|
||||||
|
@ -231,7 +243,7 @@ function listdir {
|
||||||
|
|
||||||
#mainloop
|
#mainloop
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
echo $1 $2 $3
|
#echo $1 $2 $3
|
||||||
if [ $1 == "createdb" ]; then
|
if [ $1 == "createdb" ]; then
|
||||||
createdb
|
createdb
|
||||||
elif [ $1 == "autostart" ]; then
|
elif [ $1 == "autostart" ]; then
|
||||||
|
@ -269,7 +281,16 @@ echo $1 $2 $3
|
||||||
elif [ $1 == "listdir" ]; then
|
elif [ $1 == "listdir" ]; then
|
||||||
if [ -z $2 ] || [ -z $3 ]; then echo listdir needs two more arguments; exit 1; fi
|
if [ -z $2 ] || [ -z $3 ]; then echo listdir needs two more arguments; exit 1; fi
|
||||||
listdir $2 $3
|
listdir $2 $3
|
||||||
|
elif [ $1 == "remote" ]; then
|
||||||
|
if [ ! -z $MASTERSERVER ]; then
|
||||||
|
if `echo $SSH_CLIENT | grep "$MASTERSERVER " &>/dev/null`; then
|
||||||
|
if [ -e $2 ]; then
|
||||||
|
/bin/bash $2;
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "not allowed";
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
checkdb
|
checkdb
|
||||||
|
|
|
@ -21,9 +21,12 @@ DATABASETYPE="sqlite"
|
||||||
|
|
||||||
#only sqlite settings
|
#only sqlite settings
|
||||||
SQLITEFILE="/etc/nlvmi/nlvmi.sqlite"
|
SQLITEFILE="/etc/nlvmi/nlvmi.sqlite"
|
||||||
|
|
||||||
#The unix user that runs php, to grand permissions on the sqlite file
|
#The unix user that runs php, to grand permissions on the sqlite file
|
||||||
PHPUSER="nobody"
|
PHPUSER="nobody"
|
||||||
|
|
||||||
|
#Masterserver only used for remote connections
|
||||||
|
MASTERSERVER="192.168.0.3"
|
||||||
|
|
||||||
|
|
||||||
#only mariadb settings
|
#only mariadb settings
|
||||||
|
|
Loading…
Reference in New Issue