Skip to content

Commit

Permalink
vm: disable/enable qubes-vm@ service when domain is removed/created
Browse files Browse the repository at this point in the history
If domain is set to autostart, qubes-vm@ systemd service is used to
start it at boot. Cleanup the service when domain is removed, and
similarly enable the service when domain is created and already have
autostart=True.

Fixes QubesOS/qubes-issues#4014
  • Loading branch information
marmarek committed Oct 23, 2018
1 parent 18f6b31 commit 2928be1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,22 @@ def on_property_pre_del_autostart(self, event, name, oldvalue=None):
raise qubes.exc.QubesException(
'Failed to reset autostart for VM in systemd')

@qubes.events.handler('domain-remove-from-disk')
def on_remove_from_disk(self, event, **kwargs):
# pylint: disable=unused-argument
if self.autostart:
subprocess.call(
['sudo', 'systemctl', 'disable',
'qubes-vm@{}.service'.format(self.name)])

@qubes.events.handler('domain-create-on-disk')
def on_create_on_disk(self, event, **kwargs):
# pylint: disable=unused-argument
if self.autostart:
subprocess.call(
['sudo', 'systemctl', 'enable',
'qubes-vm@{}.service'.format(self.name)])

#
# methods for changing domain state
#
Expand Down

0 comments on commit 2928be1

Please sign in to comment.