diff options
author | Phus Lu <phus.lu@citrix.com> | 2015-06-01 10:50:41 +0100 |
---|---|---|
committer | Phus Lu <phus.lu@citrix.com> | 2015-06-03 04:37:13 +0100 |
commit | b27698cbb4ddeb06a52061cd669c510084c1f916 (patch) | |
tree | 1ddc39f8c2eee32dcf10bd6bed18b7a543caffa6 /mk/xe-linux-distribution.init | |
parent | fa78be4b463ee703c82c5b711520d3aa953ad846 (diff) | |
download | vyos-xe-guest-utilities-b27698cbb4ddeb06a52061cd669c510084c1f916.tar.gz vyos-xe-guest-utilities-b27698cbb4ddeb06a52061cd669c510084c1f916.zip |
CP-12326: move guest-packages.hg/utils into xe-guest-utilities.git
Signed-off-by: Phus Lu <phus.lu@citrix.com>
Diffstat (limited to 'mk/xe-linux-distribution.init')
-rw-r--r-- | mk/xe-linux-distribution.init | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/mk/xe-linux-distribution.init b/mk/xe-linux-distribution.init new file mode 100644 index 0000000..c2c9c03 --- /dev/null +++ b/mk/xe-linux-distribution.init @@ -0,0 +1,117 @@ +#!/bin/sh +# +# xe-linux-distribution Write Linux distribution information to XenStore. +# +# chkconfig: 2345 14 86 +# description: Writes Linux distribution version information to XenStore. +# +### BEGIN INIT INFO +# Provides: xe-linux-distribution +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: XenServer Virtual Machine daemon providing host integration services +# Description: Writes Linux distribution version information to XenStore. +### END INIT INFO + +LANG="C" +export LANG + +if [ -f /etc/init.d/functions ] ; then +. /etc/init.d/functions +else +action() +{ + descr=$1 ; shift + cmd=$@ + echo -n "$descr " + $cmd + ret=$? + if [ $ret -eq 0 ] ; then + echo "OK" + else + echo "Failed" + fi + return $ret +} +fi + +XE_LINUX_DISTRIBUTION=/usr/sbin/xe-linux-distribution +XE_LINUX_DISTRIBUTION_CACHE=/var/cache/xe-linux-distribution +XE_DAEMON=/usr/sbin/xe-daemon +XE_DAEMON_PIDFILE=/var/run/xe-daemon.pid + +if [ ! -x "${XE_LINUX_DISTRIBUTION}" ] ; then + exit 0 +fi + +start() +{ + if [ ! -e /proc/xen/xenbus ] ; then + if [ ! -d /proc/xen ] ; then + action $"Mounting xenfs on /proc/xen:" /bin/false + echo "Could not find /proc/xen directory." + echo "You need a post 2.6.29-rc1 kernel with CONFIG_XEN_COMPAT_XENFS=y and CONFIG_XENFS=y|m" + exit 1 + else + # This is needed post 2.6.29-rc1 when /proc/xen support was pushed upstream as a xen filesystem + action $"Mounting xenfs on /proc/xen:" mount -t xenfs none /proc/xen + fi + fi + + if [ -e /proc/xen/capabilities ] && grep -q control_d /proc/xen/capabilities ; then + # Do not want daemon in domain 0 + exit 0 + fi + + action $"Detecting Linux distribution version:" \ + ${XE_LINUX_DISTRIBUTION} ${XE_LINUX_DISTRIBUTION_CACHE} + + action $"Starting xe daemon: " /bin/true + mkdir -p $(dirname ${XE_DAEMON_PIDFILE}) + if start-stop-daemon --start --background --exec ${XE_DAEMON} -- -p ${XE_DAEMON_PIDFILE} 1>/dev/null 2>/dev/null; then + exit 0 + else + # This is equivalent to daemon() in C + ( exec &>/dev/null ; ${XE_DAEMON} -p ${XE_DAEMON_PIDFILE} 2>/dev/null & ) + fi +} + +stop() +{ + action $"Stopping xe daemon: " kill -TERM $(cat ${XE_DAEMON_PIDFILE}) +} + +status() +{ + cat ${XE_LINUX_DISTRIBUTION_CACHE} +} + +# fail silently if not running xen +if [ ! -d /proc/xen ]; then + exit +fi + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + force-reload|restart) + stop + start + ;; + *) + # do not advertise unreasonable commands that there is no reason + # to use with this device + echo $"Usage: $0 start|restart|status" + exit 1 +esac + +exit $? |