xenserver 虚拟机定时开关机实现
1. 在xencenter中创建vapp,并备注为autostart
2. 编辑vapp启动和关机脚本
#!/bin/bash TAG="autostart" usage(){ echo "Usage: $0 [start | shutdown]" } shutvapp(){ for vapp_uuid in $vapp_uuids do vapp_tags=`xe appliance-list uuid=$vapp_uuid params=name-description --minimal` vapp_oper=`xe appliance-list uuid=$vapp_uuid params=allowed-operations --minimal` if [ "$vapp_tags" == "$TAG" ];then if [ "$vapp_oper" != "start" ];then echo "shutdown vAPP $vapp_uuid" xe appliance-shutdown uuid=$vapp_uuid else echo "the vAPP $vapp_uuid has turned off" fi fi done } startvapp(){ for vapp_uuid in $vapp_uuids do vapp_tags=`xe appliance-list uuid=$vapp_uuid params=name-description --minimal` vapp_oper=`xe appliance-list uuid=$vapp_uuid params=allowed-operations --minimal` if [ "$vapp_tags" == "$TAG" ];then if [ `echo "$vapp_oper" |grep -wc start` == 1 ];then echo "start vAPP $vapp_uuid" xe appliance-start uuid=$vapp_uuid else echo "the vAPP $vapp_uuid has start" fi fi done } vapp_uuids=`xe appliance-list params=uuid |grep uuid |awk -F": " '{print $2}'` if [ -z "$1" ]; then usage else opration=$1 fi if [ "$opration" == "start" ];then startvapp elif [ "$opration" == "shutdown" ];then shutvapp else usage fi
3. 通过crontab -e 编辑计划任务文件