ARMTC Forum
Shutdown RPi when user shuts down VM - Printable Version

+- ARMTC Forum (https://forum.armtc.net)
+-- Forum: Raspberry Pi 2/3 – Thin Client Project (https://forum.armtc.net/forumdisplay.php?fid=15)
+--- Forum: RPiTC 2/3 Discussion and Q/A (https://forum.armtc.net/forumdisplay.php?fid=17)
+--- Thread: Shutdown RPi when user shuts down VM (/showthread.php?tid=1967)



Shutdown RPi when user shuts down VM - Alec Kempendorf - 15-12-2017

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


RE: Shutdown RPi when user shuts down VM - Jean Raconte - 02-01-2018

(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 !


RE: Shutdown RPi when user shuts down VM - DaWast - 10-01-2018

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


RE: Shutdown RPi when user shuts down VM - Alec Kempendorf - 30-01-2018

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.