#!/sbin/runscript # Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Default pidfile location DEFAULT_PIDFILE="/var/run/stunnel/stunnel.pid" FILES="/etc/stunnel/*.conf" DAEMON="/usr/sbin/stunnel" depend() { need net before logger } get_pids() { local file=${1} if test -f ${file} ; then CHROOT=$(grep "^chroot" ${file} | sed "s;.*= *;;") PIDFILE=$(grep "^pid" ${file} | sed "s;.*= *;;") if [ "${PIDFILE}" == "" ] ; then PIDFILE="${DEFAULT_PIDFILE}" fi if test -f ${CHROOT}/${PIDFILE} ; then cat ${CHROOT}/${PIDFILE} fi fi } start() { rm -rf /var/run/stunnel/*.pid ebegin "Starting stunnel" for file in ${FILES} ; do if test -f "${file}" ; then ARGS="${file} ${STUNNEL_OPTIONS}" PROCLIST="$(get_pids ${file})" CHROOT=$(grep "^chroot" ${file} | sed "s;.*= *;;") PIDFILE=$(grep "^pid" ${file} | sed "s;.*= *;;") if [ "${PROCLIST}" ] && kill -0 ${PROCLIST} 2> /dev/null ; then ewarn " already running: ${file} " elif ${DAEMON} ${ARGS} ; then if ! test -f ${CHROOT}/${PIDFILE} ; then # give the daemon time to create the pid file # See bug #308931 for more details sleep 0.5s fi if test -f ${CHROOT}/${PIDFILE} ; then einfo " ${file}" else eerror " error starting: ${file}" fi fi fi done eend $? } stop() { ebegin "Stopping stunnel" for file in ${FILES} ; do PROCLIST=$(get_pids ${file}) if [ "${PROCLIST}" ] && kill -0 ${PROCLIST} 2> /dev/null ; then kill ${PROCLIST} einfo " ${file} " fi done eend $? } restart() { svc_stop sleep 1 svc_start }