xenserver 脚本学习之/opt/xensource/bin/xapi-wait-init-complete

#! /bin/bash
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
# wait (given specified timeout) for xapi to complete all
# initialisation (including storage initialisation)
#
#如果/proc/xen 目录不存在退出该脚本
[ -e /proc/xen ] || exit 0

usage () {
  echo Usage: $0 \<timeout\> \(seconds\)
  echo Poll for xapi to complete initialisation, for up to \<timeout\> seconds
  exit 1
}
#检查/var/run/xapi_init_complete.cookie 文件是否存在
XAPI_INIT_COMPLETE_COOKIE=/var/run/xapi_init_complete.cookie

if [ -z "$1" ]; then
  usage
else
  RETRIES=$1
fi

while [ ${RETRIES} -ne 0 ]; do
    if [ -e ${XAPI_INIT_COMPLETE_COOKIE} ]; then
        # success; xapi has completed initialisation
        #文件存在,说明xapi 初始化已完成
    exit 0
    fi
    sleep 1
    RETRIES=$(( ${RETRIES} - 1 ))
done

# xapi did not complete initialisation during specified timeout interval
exit 1

知识点:通过判断/var/run/xapi_init_complete.cookie 文件是否存在来确定xapi是否初始化完成。

posted @ 2017-12-13 13:40  hayden__wang  阅读(180)  评论(0编辑  收藏  举报