#! /bin/bash ### BEGIN INIT INFO # Provides: xapissl # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: XenAP server SSL proxy # Description: This file will initialize stunnel for # the XenAPI server. ### END INIT INFO # Source function library. . /lib/lsb/init-functions PEMFILE="/etc/xensource/xapi-ssl.pem" SSLPIDFILE="/var/run/xapissl.pid" SSLCONFFILE="/etc/xensource/xapi-ssl.conf" STUNNEL=$(which stunnel4) XAPISSL_LOCK="/var/lock/xapissl" mgmt_ip() { . /etc/xensource-inventory if [ -n "${MANAGEMENT_INTERFACE}" ] && [ "${MANAGEMENT_INTERFACE}" != "lo" ]; then /sbin/ifconfig ${MANAGEMENT_INTERFACE} | \ sed -ne 's/.*inet addr:\([^ ]*\).*/\1/p' fi } # Write out the stunnel config file. This requires the management # interface, so it's done here rather than written statically. writeconffile () { # Initial boilerplate which is valid whether the management # interface is enabled or disabled. cat > $SSLCONFFILE <> $SSLCONFFILE < /dev/null if [ $? -eq 0 ]; then echo -n . kill ${SSLPID} # in case the first signal was missed sleep 1 else echo rm -f ${XAPISSL_LOCK} return 0 fi done # If stunnel still hasn't exited then kill it forcefully echo -n "stunnel ($SSLPID) failed to terminate \ gracefully, terminating forcefully" failure "stunnel ($SSLPID) failed to terminate \ gracefully, terminating forcefully" kill -9 ${SSLPID} rm -f ${XAPISSL_LOCK} return 1 } status() { if [ -e ${XAPISSL_LOCK} ] && [ -e ${SSLPIDFILE} ] && [ -e /proc/`cat ${SSLPIDFILE}` ]; then status_of_proc ${STUNNEL} `basename ${STUNNEL}` && exit 0 || exit $? else echo "stunnel is not running ... failed!" exit 1 fi } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; condrestart) [ -f ${XAPISSL_LOCK} ] && restart || : ;; *) echo "Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac