#!/bin/sh # # start -- start up configured conmux servers on this host. # # (C) Copyright IBM Corp. 2004, 2005, 2006 # Author: Andy Whitcroft <andyw@uk.ibm.com> # # The Console Multiplexor is released under the GNU Public License V2 # # chkconfig: - 95 5 # description: The Conmux daemon is used for console management. # # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 if [ -f ~/.gmm.conf ]; then . ~/.gmm.conf fi DAEMON=conmuxd PROG=/usr/sbin/$DAEMON CONMUX=${CONMUX:-/usr/share/conmux} PATH=$CONMUX/drivers:$CONMUX/helpers:$PATH LOCK=/var/lock/subsys/conmux CFGDIR=/etc/conmux PIDDIR=/var/run/conmux RETVAL="0" [ -x "$PROG" ] || exit 0 cmd="$1" existing="" for i in $PIDDIR/*.pid do n=${i%.pid} n=${n#$PIDDIR/} if [ "$n" != "*" ]; then existing="$existing $n" fi done start_component() { local component="$1" local pidfile="$PIDDIR/$component.pid" shift # Determine whether it is already running ... if so leave it be. if [ -f "$pidfile" ]; then if kill -0 `cat "$pidfile"` 2>/dev/null; then return 1 fi fi case "$component" in registry) echo -n " starting $component..." ;; *) echo -n " connecting to $component..." ;; esac "$@" >"/var/log/conmux/$component.log" 2>&1 & if [ "$?" -eq 0 ]; then echo "$!" >"$pidfile" success; echo return 0 else failure; echo return 1 fi } stop_component() { local component="$1" local pidfile="$PIDDIR/$component.pid" case "$component" in registry) echo -n " stopping $component..." ;; *) echo -n " disconnecting $component..." ;; esac # Kill it and clear up kill -HUP `cat "$pidfile"` 2>/dev/null if [ "$?" -eq 0 ]; then rm -f "$pidfile" success; echo return 0 else failure; echo return 1 fi } start_conmuxd(){ autoboot="" [ -f $CFGDIR/registry ] || touch $CFGDIR/registry start_component registry /usr/sbin/conmux-registry 63000 $CFGDIR/registry if [ "$?" -eq 0 ]; then sleep 1 fi started="registry" pause=0 for i in $CFGDIR/*.cf do n=${i%.cf} n=${n#$CFGDIR/} if [ "$n" != "*" ]; then if [ -f "/var/run/conmux/$n.cf" ]; then if ! cmp -s "$i" "/var/run/conmux/$n.cf"; then stop_component $n fi fi start_component $n $PROG $i if [ "$?" -eq 0 ]; then pause=1 fi started="$started $n" # Preserve the orginal configuration file. cp "$i" "/var/run/conmux/$n.cf" if grep -q TYPE:numaq "$i"; then autoboot="$autoboot $n" fi for i in `grep FLAGS: "$i"`; do case "$i" in \#|FLAGS:) ;; *) autoboot="$autoboot $n/$i" ;; esac done fi done if [ "$pause" -eq 1 ]; then sleep 1 fi for nh in $autoboot do name="${nh%/*}" helper="${nh#*/}" mn="${name#abat-}" start_component $name-$helper-helper /usr/bin/conmux-attach $mn $helper-helper started="$started $name-$helper-helper" done return 0 } case "$1" in start) echo "Starting ConMux Daemon: " for i in $existing do case " $started " in *\ $i\ *) ;; *) stop_component "$i" ;; esac done start_conmuxd RETVAL=$? echo -n "ConMux Daemon Started: " [ $RETVAL -eq 0 ] && success && touch $LOCK echo ;; stop) echo "Stopping ConMux Daemon: " for i in $existing do case " $started " in *\ $i\ *) ;; *) stop_component "$i" ;; esac done RETVAL=$? echo -n "ConMux Daemon Stopped: " [ $RETVAL -eq 0 ] && success && rm -f $LOCK echo ;; status) if [ -e $PIDDIR/registry.pid ]; then regpid=$(cat $PIDDIR/registry.pid) ps -p $regpid >/dev/null 2>&1 RETVAL=$? if [ "$RETVAL" -eq "0" ]; then echo "Conmux registry (pid $regpid) is running.." echo "Individual console connections: " for n in $existing do mn="${n#abat-}" case "$n" in registry|*-helper) ;; *) status=`conmux -s $mn` echo " $mn $status" ;; esac done else echo "Conmux is not running, but a stale pid file exists." RETVAL=1 fi else echo "Conmux is not running." RETVAL=1 fi ;; restart|reload) $0 status >/dev/null && $0 stop $0 start RETVAL=$? echo ;; condrestart) [ ! -f $LOCK ] || $0 restart ;; *) echo "Usage: $0 {start|stop|status|restart|reload|condrestart}" exit 1 ;; esac exit $RETVAL