Honestly, at first glance I got good laugh from this idea.
However on second thought it will save at least two mouse clicks each VM run
Also, without any research, my first solution would be to run small script as service to check for VM, and spawn LG if VM exists.
I have this idea not because it is so hard to open a terminal and run the looking glass command, but because it would be a seamless experience!
Thank you but this is already what qemu hooks are for. You can put scripts into /etc/libvirt/hooks that will be executed once you start the VM, no need really to run a service. The problem is to get the looking glass window displayed and also that, like mentioned in the reddit thread, the fact that looking glass is not a command that is getting run and then finishes immediately so the hook is not working correctly.
I talk with 0 knowledge of the software, but what you are describing sound like a launcher forking it’s software as a daemon and closing itself afterward.
Usually software who do that also offer 2 thing, a known way to get the daemon PID, and a command-line argument that don’t spawn a daemon but keep everything in the launcher.
If there isn’t an argument like that, look for a file somewhere like /run that would contain the PID of the LG software.
Then you can create a script that lunch LG, get the pid from that file, and close when the process with that pid die
Once again i never used LG nor QEMU so i may be completely of course.
I made myself shortcut in xfce menu that just runs “looking-glass-client -a -F”. No need to start console before.
Yes I’m aware, but what I meant is that self made solution will be faster than getting a grip on huge project that has small bug.
I’m also forgetful Just checked my machine and apparently I did try this mechanism for automatically mounting and dismounting samba after VM started or stopped. Timestamp shows me it was year ago.
I remember now that it was “kinda” working, I.E hook was running ok. But if mountpoint was still busy I’ve had problems with it. “Hard reset” problems. So I scrapped whole idea and forgot about it.
But It may help you to do what I did at the begining of my /etc/libvirt/hooks/qemu script:
Well, I tried to make qemu hook for it. But looking glass doesn’t like it.
When trying to run “looking-glass-client -a -F” on “vm started” signal it just does nothing.
So I tried to add delay, but hook doesn’t exit until delay is over, so no difference.
Then tried to fork function and separate script with &, (&), and setsid, but no joy.
Now I remember why I opted for menu shortcut instead hook…
Thank you for your afford. I am also still looking for a solution, I do not really understand until know why this approach is so much of an issue. There seems to be an important piece of knowledge missing in my head but until know I was unable to figure out what it is.
I know that some other software, like starting and stopping Synergy works with hooks.
@gnif: Sorry to bother you, but do you know if this has something to do with LG? I want to know if this is a problem specific to LG or if the problem is somewhere else in the software stack!
AFAIR LG doesn’t wait for IVSHMEM to start outputting data. It just exits. That’s why I tried to make delay until driver loads.
But even if it would wait, then hook doesn’t exit (and therefore VM doesn’t load) until all processes spawned inside are done. And I couldn’t find solution to that.
Edit: Oh, synergy probably works from systemd, didn’t thought about that. That could work…
Holy sh**, got it working from systemd . Thanks for hint that synergy works from hook @anon89476829
First simple script to run lg “lghelper”. You may have to change DISPLAY variable. echo $DISPLAY to check what it is:
#!/bin/sh
export DISPLAY=:0.0 # change to your display port if different!
sleep 10 # can change delay depending on host
looking-glass-client -F -a
Then service file “looking-glass.service”:
[Unit]
Description=Looking Glass workaround
After=libvirt.service
Wants=libvirt.service
[Service]
Type=simple
# change to your username and group!
User=misiek
Group=misiek
# change to your path!
ExecStart=/home/misiek/scripts/lghelper
[Install]
WantedBy=default.target
But if your distro has apparmor, it may need some extra steps.
Also after enabling service you can check if it working properly. Following should spawn looking glass while your VM is running:
sudo systemctl start looking-glass
And finally you can add hook, paste to /etc/libvirt/qemu and change VM1NAME:
#!/bin/sh
VM1NAME="my_vm_name"
if [[ $1 == $VM1NAME ]] && [[ $2 == "started" ]]; then
systemctl start looking-glass
fi
if [[ $1 == $VM1NAME ]] && [[ $2 == "stopped" ]]; then
systemctl stop looking-glass
fi
Above was tested on Manjaro 20.2
Edit: Scripts pobably could use some massage, like service should not start at boot or sth. Just grabbed some template for service for testing. Corrections encouraged
No, I just symlinked it and systemctl enabled…
Maybe its apparmor issue, for example if you using Ubu.
Check “journalctl -f” when you enabling service, maybe it will tell you what the heck
Also there are few obvious things i didn’t mention:
Change username to yours.
Change path to lghelper if its in different location.
Look like either a permission issue (system, apparmor), or the link did not work correctly.
Another way to do it, this is what I use: cp to /etc/systemd/system/ (hard link should also work no problem) sudo systemctl daemon-reload sudo systemctl start looking-glass
With systemctl start that service should spawn looking glass if VM is running.
But normally it should be stopped, and hook should start and then stop it.
If its apparmor issue (stopping it will tell you that) then you have find how to add new service to apparmor rules.
Indeed that was it. I did not even see it when I checked the files. Now everything works and the LG windows opens when starting the VM. I needed to make some small modifications like for me it is:
Display=:1
Thanks for your effort! I will mark your answer as the solution!
@misiektw I think you should be able to edit it again.
We have a short edit window for lower trust levels due to the amount of spam we have been getting.