/etc/init.d/xapi

/etc/init.d/xapi

1 내용[ | ]

#! /bin/bash
#
# xapi          Start/Stop the XAPI server
#
# chkconfig: 2345 23 77
# description: XenServer server
# processname: xapi
# config: /etc/xapi.conf
# pidfile: /var/run/xapi.pid

# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/xapi ]; then
  . /etc/sysconfig/xapi
fi

if [ -e /var/xapi/xiu-xc ]; then
	export XENCTRL_OSDEP="/opt/xensyntaxhighlight/lib/libxenctrl_xiu.so"
	export XIU=/var/xapi/xiu
fi

XAPI_STARTUP_COOKIE=/var/run/xapi_startup.cookie
XAPI_INIT_COMPLETE_COOKIE=/var/run/xapi_init_complete.cookie
XAPI_BLOCK_STARTUP_COOKIE=/etc/xensyntaxhighlight/xapi_block_startup
XAPI_BOOT_TIME_INFO_UPDATED=/etc/xensyntaxhighlight/boot_time_info_updated

# Enable core dumping for xapi
ulimit -c unlimited

start() {
	echo -n $"Starting xapi: "

	# clear out any old xapi coredumps
	rm -rf /var/xapi/debug

        if [ -e /var/lock/subsys/xapi ]; then
	    if [ -e /var/run/xapi.pid ] && [ -e /proc/`cat /var/run/xapi.pid` ]; then
		echo -n $"cannot start xapi: already running.";
		failure $"cannot start xapi: already running.";
		echo
		return 1
	    fi
	fi
	# This bit is ok though:
	rm -f ${XAPI_STARTUP_COOKIE}
	rm -f ${XAPI_INIT_COMPLETE_COOKIE}
	# Enable backtraces
	export OCAMLRUNPARAM="b"
	# Add HA scripts to the path
	PATH=$PATH:/opt/xensyntaxhighlight/xha

	# For debugging, prevent xapi startup
	if [ -e ${XAPI_BLOCK_STARTUP_COOKIE} ]; then
            if [ -e ${XAPI_BOOT_TIME_INFO_UPDATED} ]; then
	    logger "Aborting xapi startup because ${XAPI_BLOCK_STARTUP_COOKIE} is present and the system has just booted. Remove file and try again";
	    echo -n $"startup blocked."
	    failure $"startup blocked."
	    echo
	    return 1
            fi
	fi

	if [ -e ${XAPI_BOOT_TIME_INFO_UPDATED} ]; then
	    # clear out qemu coredumps/chroot dirs on system boot:
	    rm -rf /var/xen/qemu/*
	    "/opt/xensyntaxhighlight/bin/xapi" -daemon ${xapiflags} \
		-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE} -onsystemboot
		RETVAL=$?
	    rm -f ${XAPI_BOOT_TIME_INFO_UPDATED}
	else
	    "/opt/xensyntaxhighlight/bin/xapi" -daemon ${xapiflags} \
		-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE}
		RETVAL=$?
	fi

	if [ $RETVAL -eq 0 ]; then
		touch /var/lock/subsys/xapi
		echo -n $"OK"
		success $"OK"
		echo
		return 0
	else
		echo -n $"failed to start xapi."
		failure $"failed to start xapi."
		killproc xapi
		rm -f /var/lock/subsys/xapi /var/run/xapi.pid
		echo
		return 1
	fi
}

stop() {
	echo -n $"Stopping xapi: "
        if [ ! -e /var/lock/subsys/xapi ]; then
	    echo -n $"cannot stop xapi: xapi is not running."
	    failure $"cannot stop xapi: xapi is not running."
	    echo
	    return 1;
	fi
	rm -f ${XAPI_STARTUP_COOKIE}
	rm -f ${XAPI_INIT_COMPLETE_COOKIE}

	# Find out if xapi has died
	RETRIES=60
	while [ ${RETRIES} -ne 0 ]; do
		xe host-shutdown-agent 2> /dev/null
		# Finish if all xapis have gone 
		xapi_pids=$(pidof xapi)
		if [ -z "$xapi_pids" ]; then
			logger "xapi stopped successfully"
			rm -f /var/run/xapi.pid /var/lock/subsys/xapi
			success $"xapi stopped successfully"
			echo
			return 0
		fi
		sleep 1
		echo -n .
		RETRIES=$(( ${RETRIES} - 1 ))
	done

	killproc xapi
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
	    logger "xapi stopped forcibly"
	    success $"xapi stopped successfully"
	    echo
	    rm -f /var/run/xapi.pid /var/lock/subsys/xapi
	else
	    logger "failed to stop xapi"
	    failure $"failed to stop xapi"
	    echo
	fi

	return $RETVAL
}

rhstatus() {
	status xapi
}

restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  status)
	rhstatus
	;;
  condrestart)
	[ -f /var/lock/subsys/xapi ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart}"
	exit 1
esac

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}