Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shutdown RPi when user shuts down VM
15-12-2017, 03:01 PM,
#1
Shutdown RPi when user shuts down VM
Hello everyone,

i want my RPi to shut down when the user hits the shut down button in the VM.

Does anyone know how to do it?

I already got a python script (actually it´s a service) that does this work, but i don´t think it´s the optimal method for this.

It uses the process id of the vm and checks every 20sec (time is variable) if the filepath linked to this id is still existing. (os.path.exists(process_folder))

Alec
Reply
02-01-2018, 01:13 PM,
#2
RE: Shutdown RPi when user shuts down VM
(15-12-2017, 03:01 PM)Alec Kempendorf Wrote: Hello everyone,

i want my RPi to shut down when the user hits the shut down button in the VM.

Does anyone know how to do it?

I already got a python script (actually it´s a service) that does this work, but i don´t think it´s the optimal method for this.

It uses the process id of the vm and checks every 20sec (time is variable) if the filepath linked to this id is still existing. (os.path.exists(process_folder))

Alec

Hi,

I did the same with Powershell on W7e on thin clients to logoff the user from the client when the session ends.

I'd like to do the same with the Rpi, could you share your script please ? If it's ok for you.

Thanks !
Reply
10-01-2018, 10:11 AM,
#3
RE: Shutdown RPi when user shuts down VM
You can do this with a script.
Maybe you have already a script to start your vm connection.
So you could add a shutdown command to the end of you script.
But you will maybe lose access to the system expect the vm connection.

Regards DaWast
-= Feel Free to use the Search function in the upper right corner =-
Reply
30-01-2018, 02:09 PM, (This post was last modified: 30-01-2018, 02:09 PM by Alec Kempendorf.)
#4
RE: Shutdown RPi when user shuts down VM
Sry for that late reply... i am using the following script now:


Code:
import subprocess
from subprocess import check_output
import os
import time
import psutil

def get_pid(name):
    try:
        return int(check_output(["pidof","-s",name]))
    except subprocess.CalledProcessError as e:
        process_id = -1

while True:
    time.sleep(60)
    process_id = get_pid("vmware-view")
    time.sleep(3)
    if (psutil.pid_exists(process_id) == False):
        os.system("/usr/lib/vmware/view/bin/vmware-view &")
        print("Trying to restart vmware-view")
        time.sleep(3)
        process_id = get_pid("vmware-view")
    if (psutil.pid_exists(process_id) == False):
        os.system('shutdown -h now')


I had some problems installing psutils, but it´s working now.


But i have another question:

When i shutdown the vm, my vmware-view client should terminate. On my windows pc it does it automatically.

I am using version 4.4 on my RPi and i couldn´t figure out any start parameters which would do this. Except for "--once" but this parameter closes my program whenever it runs into an error, this could be annoying when i just missspell my password and have to restart my program every time. Anyone got some better solutions?

Another problem linked to the one above is that my client sometimes says "Error: Hostname could not be resolved", when i use the starting parameter "--once" and then this error occurs and i click "close" (error message) then it will close my view client.

I really don´t get why it can resolve the hostname 30% of the time and for 70% everything works fine.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)