Support for autostart VMs (#724)
This commit is contained in:
parent
2005207462
commit
6fddae3b9b
@ -120,6 +120,7 @@ class QubesVm(object):
|
|||||||
"debug": { "default": False },
|
"debug": { "default": False },
|
||||||
"default_user": { "default": "user" },
|
"default_user": { "default": "user" },
|
||||||
"qrexec_timeout": { "default": 60 },
|
"qrexec_timeout": { "default": 60 },
|
||||||
|
"autostart": { "default": False, "attr": "_autostart" },
|
||||||
##### Internal attributes - will be overriden in __init__ regardless of args
|
##### Internal attributes - will be overriden in __init__ regardless of args
|
||||||
"config_file_template": { "eval": 'system_path["config_template_pv"]' },
|
"config_file_template": { "eval": 'system_path["config_template_pv"]' },
|
||||||
"icon_path": { "eval": 'os.path.join(self.dir_path, "icon.png") if self.dir_path is not None else None' },
|
"icon_path": { "eval": 'os.path.join(self.dir_path, "icon.png") if self.dir_path is not None else None' },
|
||||||
@ -137,7 +138,7 @@ class QubesVm(object):
|
|||||||
'uses_default_kernel', 'kernel', 'uses_default_kernelopts',\
|
'uses_default_kernel', 'kernel', 'uses_default_kernelopts',\
|
||||||
'kernelopts', 'services', 'installed_by_rpm',\
|
'kernelopts', 'services', 'installed_by_rpm',\
|
||||||
'uses_default_netvm', 'include_in_backups', 'debug',\
|
'uses_default_netvm', 'include_in_backups', 'debug',\
|
||||||
'default_user', 'qrexec_timeout' ]:
|
'default_user', 'qrexec_timeout', 'autostart' ]:
|
||||||
attrs[prop]['save'] = 'str(self.%s)' % prop
|
attrs[prop]['save'] = 'str(self.%s)' % prop
|
||||||
# Simple paths
|
# Simple paths
|
||||||
for prop in ['conf_file', 'root_img', 'volatile_img', 'private_img']:
|
for prop in ['conf_file', 'root_img', 'volatile_img', 'private_img']:
|
||||||
@ -444,6 +445,20 @@ class QubesVm(object):
|
|||||||
for hook in self.hooks_post_rename:
|
for hook in self.hooks_post_rename:
|
||||||
hook(self, old_name)
|
hook(self, old_name)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def autostart(self):
|
||||||
|
return self._autostart
|
||||||
|
|
||||||
|
@autostart.setter
|
||||||
|
def autostart(self, value):
|
||||||
|
if value:
|
||||||
|
retcode = subprocess.call(["sudo", "systemctl", "enable", "qubes-vm@%s.service" % self.name])
|
||||||
|
else:
|
||||||
|
retcode = subprocess.call(["sudo", "systemctl", "disable", "qubes-vm@%s.service" % self.name])
|
||||||
|
if retcode != 0:
|
||||||
|
raise QubesException("Failed to set autostart for VM via systemctl")
|
||||||
|
self._autostart = bool(value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def template(self):
|
def template(self):
|
||||||
return self._template
|
return self._template
|
||||||
|
12
linux/systemd/qubes-vm@.service
Normal file
12
linux/systemd/qubes-vm@.service
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Start Qubes VM %i
|
||||||
|
After=qubes-netvm.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/bin/qvm-start --no-guid %i
|
||||||
|
Group=qubes
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -42,6 +42,7 @@ def do_list(vm):
|
|||||||
if vm.netvm is not None:
|
if vm.netvm is not None:
|
||||||
print fmt.format ("netvm", vm.netvm.name)
|
print fmt.format ("netvm", vm.netvm.name)
|
||||||
print fmt.format ("updateable?", vm.updateable)
|
print fmt.format ("updateable?", vm.updateable)
|
||||||
|
print fmt.format ("autostart", vm.autostart)
|
||||||
print fmt.format ("installed by RPM?", vm.installed_by_rpm)
|
print fmt.format ("installed by RPM?", vm.installed_by_rpm)
|
||||||
print fmt.format ("include in backups", vm.include_in_backups)
|
print fmt.format ("include in backups", vm.include_in_backups)
|
||||||
print fmt.format ("dir", vm.dir_path)
|
print fmt.format ("dir", vm.dir_path)
|
||||||
@ -360,6 +361,14 @@ def set_guiagent_installed(vms, vm, args):
|
|||||||
vm.guiagent_installed = bool(eval(args[0].capitalize()))
|
vm.guiagent_installed = bool(eval(args[0].capitalize()))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def set_autostart(vms, vm, args):
|
||||||
|
if len (args) != 1:
|
||||||
|
print >> sys.stderr, "Missing value (True/False)!"
|
||||||
|
return False
|
||||||
|
|
||||||
|
vm.autostart = bool(eval(args[0].capitalize()))
|
||||||
|
return True
|
||||||
|
|
||||||
def set_qrexec_timeout(vms, vm, args):
|
def set_qrexec_timeout(vms, vm, args):
|
||||||
if len (args) != 1:
|
if len (args) != 1:
|
||||||
print >> sys.stderr, "Missing timeout value (seconds)!"
|
print >> sys.stderr, "Missing timeout value (seconds)!"
|
||||||
@ -401,6 +410,7 @@ properties = {
|
|||||||
"qrexec_timeout": set_qrexec_timeout,
|
"qrexec_timeout": set_qrexec_timeout,
|
||||||
"timezone": set_timezone,
|
"timezone": set_timezone,
|
||||||
"internal": set_internal,
|
"internal": set_internal,
|
||||||
|
"autostart": set_autostart,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ cp linux/systemd/qubes-setupdvm.service $RPM_BUILD_ROOT%{_unitdir}
|
|||||||
cp linux/systemd/qubes-meminfo-writer.service $RPM_BUILD_ROOT%{_unitdir}
|
cp linux/systemd/qubes-meminfo-writer.service $RPM_BUILD_ROOT%{_unitdir}
|
||||||
cp linux/systemd/qubes-netvm.service $RPM_BUILD_ROOT%{_unitdir}
|
cp linux/systemd/qubes-netvm.service $RPM_BUILD_ROOT%{_unitdir}
|
||||||
cp linux/systemd/qubes-qmemman.service $RPM_BUILD_ROOT%{_unitdir}
|
cp linux/systemd/qubes-qmemman.service $RPM_BUILD_ROOT%{_unitdir}
|
||||||
|
cp linux/systemd/qubes-vm@.service $RPM_BUILD_ROOT%{_unitdir}
|
||||||
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/usr/bin/
|
mkdir -p $RPM_BUILD_ROOT/usr/bin/
|
||||||
cp qvm-tools/qvm-* $RPM_BUILD_ROOT/usr/bin
|
cp qvm-tools/qvm-* $RPM_BUILD_ROOT/usr/bin
|
||||||
@ -299,6 +300,7 @@ fi
|
|||||||
%{_unitdir}/qubes-meminfo-writer.service
|
%{_unitdir}/qubes-meminfo-writer.service
|
||||||
%{_unitdir}/qubes-netvm.service
|
%{_unitdir}/qubes-netvm.service
|
||||||
%{_unitdir}/qubes-qmemman.service
|
%{_unitdir}/qubes-qmemman.service
|
||||||
|
%{_unitdir}/qubes-vm@.service
|
||||||
%attr(0770,root,qubes) %dir /var/lib/qubes
|
%attr(0770,root,qubes) %dir /var/lib/qubes
|
||||||
%attr(0770,root,qubes) %dir /var/lib/qubes/vm-templates
|
%attr(0770,root,qubes) %dir /var/lib/qubes/vm-templates
|
||||||
%attr(0770,root,qubes) %dir /var/lib/qubes/appvms
|
%attr(0770,root,qubes) %dir /var/lib/qubes/appvms
|
||||||
|
Loading…
Reference in New Issue
Block a user