I'm trying to run some commands whenever a VM is started or a device is attached to a VM. I came upon this Github comment by Marek which says that this is possible with Qubes extensions: https://github.com/QubesOS/qubes-issues/issues/4126#issuecomment-406888845
I wrote a simple Qubes extension with the following project structure:
my_extension/
* my_extension/
** __init__.py
* setup.py
With the following `setup.py`:
```
#!/usr/bin/env python3
import setuptools
if __name__ == '__main__':
setuptools.setup(
name='my_extension',
version="1.0",
author='Nils Amiet',
author_email='nils....@foobar.tld',
description='My extension',
license='GPLv3',
url='https://foobar.tld',
packages=('my_extension',),
entry_points={
'qubes.ext': [
'my_extension = my_extension:MyExtension',
],
}
)
```
And `__init__.py`:
```
import qubes.ext
class MyExtension(qubes.ext.Extension):
@qubes.ext.handler("domain-start", system=True)
def on_vm_start(self, app, event, vm, **kwargs):
with open("/tmp/my_extension.log", "a+") as fout:
print("Started vm: {}".format(vm), file=fout)
```
Now, I installed this extension on a deployed Qubes OS installation in dom0 with `sudo ./setup.py install` but the file `/tmp/my_extension.log` is never created after having started some VMs. I was expecting to see something being written there.
Why is my extension not being loaded? Am I missing something here? How can I debug extensions and make sure they are being loaded? Is there a log somewhere?
Is Qubes OS going to call my `on_vm_start()` function whenever a VM is started just by installing the extension with `setup.py install`? What should I do so that it does?
Thank you and have a nice day,
Nils