-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On Wed, Oct 17, 2018 at 10:24:47PM -0700, nils.am...@gmail.com wrote: > Hi everyone, > > 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.am...@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)
'domain-start' event is called on VM object, so it should not have system=True. system=True is needed for events on Qubes() main object itself, like property-set:default_template. > def on_vm_start(self, app, event, vm, **kwargs): For system=False events, it should be: def on_vm_start(self, vm, event, **kwargs): If you need to access app, you can still do that through vm.app. > 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. Besides the system=True, everything else looks ok. Remember to restart qubesd service after installing the extension. > 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 > - -- Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAlvJsxsACgkQ24/THMrX 1ywpbAf+KLCp44W+yYOKRpNm3tvTUrvYb20KF4y4FiEoWE9vTapIfT9fLNI3yfZw eHn52vb14VdtxPnZ7yNEopHbDAKwj2+u1RTrjszsBitjRqiAEFkFeDHCRQB1QAN8 HwPUWXCIvBNbUxQzpLYXvQX6V7/Ll6a/M/9DcanfRyHlU5yCHM+ZmdgBK4kU+Nb3 0cyCsA27CV2AGYuYRyYh5kyT+WX9nIPTwRUmRNi0lIuT45gBIWQ9OYo4kKjDCIUc /YBqcHn7pTTOwz4e5ct+b/YQWLMKk3n1NX4DGYjnBbpt7E0y9vk3uNnXV8/z3dtt 4GgwIivDTAYx/5pU5AjklNksAL1pgw== =3wtl -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "qubes-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to qubes-users+unsubscr...@googlegroups.com. To post to this group, send email to qubes-users@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/qubes-users/20181019103403.GA13191%40mail-itl. For more options, visit https://groups.google.com/d/optout.