1#!/bin/bash 2# 3# xencommons Script to start and stop xenstored and xenconsoled 4# 5# Author: Ian Jackson <ian.jackson@eu.citrix.com> 6# 7# chkconfig: 2345 70 10 8# description: Starts and stops xenstored and xenconsoled 9### BEGIN INIT INFO 10# Provides: xenstored xenconsoled 11# Required-Start: $syslog $remote_fs 12# Should-Start: 13# Required-Stop: $syslog $remote_fs 14# Should-Stop: 15# Default-Start: 2 3 5 16# Default-Stop: 0 1 6 17# Short-Description: Start/stop xenstored and xenconsoled 18# Description: Starts and stops the daemons neeeded for xl/xend 19### END INIT INFO 20 21BACKEND_MODULES="@LINUX_BACKEND_MODULES@" 22 23. @XEN_SCRIPT_DIR@/hotplugpath.sh 24 25xencommons_config=@CONFIG_DIR@/@CONFIG_LEAF_DIR@ 26 27test -f $xencommons_config/xencommons && . $xencommons_config/xencommons 28 29XENCONSOLED_PIDFILE=@XEN_RUN_DIR@/xenconsoled.pid 30QEMU_PIDFILE=@XEN_RUN_DIR@/qemu-dom0.pid 31shopt -s extglob 32 33# not running in Xen dom0 or domU 34if ! test -d /proc/xen ; then 35 exit 0 36fi 37 38# mount xenfs in dom0 or domU with a pv_ops kernel 39if test "x$1" = xstart && \ 40 ! test -f /proc/xen/capabilities && \ 41 ! grep '^xenfs ' /proc/mounts >/dev/null; 42then 43 mount -t xenfs xenfs /proc/xen 44fi 45 46# run this script only in dom0: 47# no capabilities file in xenlinux domU kernel 48# empty capabilities file in pv_ops domU kernel 49if test -f /proc/xen/capabilities && \ 50 ! grep -q "control_d" /proc/xen/capabilities ; then 51 exit 0 52fi 53 54do_start () { 55 local mod 56 57 for mod in $BACKEND_MODULES ; do modprobe "$mod" &>/dev/null ; done 58 59 mkdir -p ${XEN_RUN_DIR} 60 mkdir -p ${XEN_LOCK_DIR} 61 mkdir -p ${XEN_LOG_DIR} 62 63 @XEN_SCRIPT_DIR@/launch-xenstore || exit 1 64 65 echo Setting domain 0 name, domid and JSON config... 66 ${LIBEXEC_BIN}/xen-init-dom0 67 68 echo Starting xenconsoled... 69 test -z "$XENCONSOLED_TRACE" || XENCONSOLED_ARGS=" --log=$XENCONSOLED_TRACE" 70 ${sbindir}/xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_ARGS 71 echo Starting QEMU as disk backend for dom0 72 test -z "$QEMU_XEN" && QEMU_XEN="@qemu_xen_path@" 73 $QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize \ 74 -monitor /dev/null -serial /dev/null -parallel /dev/null \ 75 -pidfile $QEMU_PIDFILE 76} 77do_stop () { 78 echo Stopping xenconsoled 79 if read 2>/dev/null <$XENCONSOLED_PIDFILE pid; then 80 kill $pid 81 while kill -9 $pid >/dev/null 2>&1; do sleep 1; done 82 rm -f $XENCONSOLED_PIDFILE 83 fi 84 85 echo Stopping QEMU 86 if read 2>/dev/null <$QEMU_PIDFILE pid; then 87 kill $pid 88 while kill -9 $pid >/dev/null 2>&1; do sleep 1; done 89 rm -f $QEMU_PIDFILE 90 fi 91 92 echo WARNING: Not stopping xenstored, as it cannot be restarted. 93} 94 95case "$1" in 96 start) 97 do_start 98 ;; 99 status) 100 test -f @XEN_RUN_DIR@/xenstored.pid 101 ;; 102 stop) 103 do_stop 104 ;; 105 reload) 106 echo >&2 'Reload not available; use force-reload'; exit 1 107 ;; 108 force-reload|restart) 109 do_stop 110 do_start 111 ;; 112 *) 113 # do not advertise unreasonable commands that there is no reason 114 # to use with this device 115 echo $"Usage: $0 {start|stop|status|restart|force-reload}" 116 exit 1 117esac 118 119exit $? 120