virsh自动关闭windows虚拟机
source link: https://jiajunhuang.com/articles/2020_05_18-virsh_shutdown_win.md.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
virsh自动关闭windows虚拟机
大家都知道,这种定时任务是通过crontab来做,但是,如果你直接尝试在crontab里关机,你会发现有时候是关不掉windows虚拟机的。 这是为啥呢?这个问题困扰了我好久,因为每次我直接输入命令关机的时候,都关机成功了,我要是放到crontab里等,它也能关机, 但是我设置crontab在晚上1点关机,第二天发现,它就是没有关机。
最后发现,原来是windows有这么一个锅:在息屏之后,如果你输入 virsh shutdown --domain win
的话,它只会激活屏幕,此时
如果你输入第二次这个命令的话,就可以成功关机。
原来问题是这样:因为我每次尝试的时候,都不是息屏状态。
解决方案有两种:
禁用Windows的息屏:Control Panel -> System and Security -> Power Options –> Click “Change plan Settings”. Set “Turn off the display” to Never (default is 10 minutes)
然后就可以用crontab来自动开关虚拟机实现自动化
# 工作日早上9点,自动开启虚拟机
0 9 * * 1-5 virsh start --domain win
# 工作日晚上18点,自动关闭虚拟机
0 18 * * 1-5 virsh shutdown --domain win
参考资料:
关注公众号,获得及时更新
Ubuntu 18.04 dhcp更换新IP
Python中的新式类(new style class)和老式类(old style class)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK