整理休眠虚拟机的服务

This commit is contained in:
陈浩南 2023-07-13 21:38:03 +08:00
parent e440a96dbf
commit 83b7fae8e9

View File

@ -34,7 +34,7 @@ inputs:
''
if [ "$(LANG=C ${virsh} domstate $1)" = 'shut off' ] && [ -f "/tmp/libvirt.$1.suspended" ]
then
if virsh start "$1"
if ${virsh} start "$1"
then
echo "Waiting for $1 to resume"
while ! [ "$(LANG=C ${virsh} domstate $1)" = 'running' ]
@ -48,40 +48,24 @@ inputs:
fi
fi
'';
in
makeServices = machine:
{
"libvirt-hibernate@" =
"libvirt-hibernate-${machine}" =
{
description = "libvirt hibernate";
description = "libvirt hibernate ${machine}";
wantedBy = [ "systemd-hibernate.service" "systemd-suspend.service" ];
before = [ "systemd-hibernate.service" "systemd-suspend.service" ];
serviceConfig = { Type = "oneshot"; ExecStart = "${hibernate} %i"; };
serviceConfig = { Type = "oneshot"; ExecStart = "${hibernate} ${machine}"; };
};
"libvirt-resume@" =
"libvirt-resume-${machine}" =
{
description = "libvirt resume";
description = "libvirt resume ${machine}";
wantedBy = [ "systemd-hibernate.service" "systemd-suspend.service" ];
after = [ "systemd-hibernate.service" "systemd-suspend.service" ];
serviceConfig = { Type = "oneshot"; ExecStart = "${resume} %i"; };
};
"libvirt-hibernate@win10" =
{
wantedBy = [ "systemd-hibernate.service" "systemd-suspend.service" ];
overrideStrategy = "asDropin";
};
"libvirt-resume@win10" =
{
wantedBy = [ "systemd-hibernate.service" "systemd-suspend.service" ];
overrideStrategy = "asDropin";
};
"libvirt-hibernate@hardconnect" =
{
wantedBy = [ "systemd-hibernate.service" "systemd-suspend.service" ];
overrideStrategy = "asDropin";
};
"libvirt-resume@hardconnect" =
{
wantedBy = [ "systemd-hibernate.service" "systemd-suspend.service" ];
overrideStrategy = "asDropin";
serviceConfig = { Type = "oneshot"; ExecStart = "${resume} ${machine}"; };
};
};
in
(makeServices "win10") // (makeServices "hardconnect");
};
}