1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#! /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
#
if [ -f ~/.gmm.conf ]; then
. ~/.gmm.conf
fi
CONMUX=${CONMUX:-/usr/local/conmux}
cmd="start"
if [ "$1" != "" ]; then
cmd="$1"
fi
PATH=$CONMUX/bin:$CONMUX/sbin:$CONMUX/lib/drivers:$CONMUX/lib/helpers:$PATH
function start() {
typeset name="$1"
typeset pf="$CONMUX/log/$name.pid"
shift
# Determine whether it is already running ... if so leave it be.
if [ -f "$pf" ]; then
if kill -0 `cat "$pf"` 2>/dev/null; then
return 1
fi
fi
echo "starting $name ..."
"$@" >"$CONMUX/log/$name.log" 2>&1 &
echo "$!" >"$pf"
return 0
}
function stop() {
typeset name="$1"
typeset pf="$CONMUX/log/$name.pid"
echo "stopping $name ..."
# Kill it and clear up
kill -HUP `cat "$pf"` 2>/dev/null
rm -f "$pf"
}
existing=""
for i in $CONMUX/log/*.pid
do
n=${i%.pid}
n=${n#$CONMUX/log/}
if [ "$n" != "*" ]; then
existing="$existing $n"
fi
done
if [ "$cmd" = "start" ]; then
autoboot=""
[ -f $CONMUX/etc/registry ] || touch $CONMUX/etc/registry
start registry $CONMUX/sbin/conmux-registry 63000 $CONMUX/etc/registry
if [ "$?" -eq 0 ]; then
sleep 1
fi
started="registry"
pause=0
for i in $CONMUX/etc/*.cf
do
n=${i%.cf}
n=${n#$CONMUX/etc/}
if [ "$n" != "*" ]; then
if [ -f "$CONMUX/log/$n.cf" ]; then
if ! cmp -s "$i" "$CONMUX/log/$n.cf"; then
stop $n
fi
fi
start $n $CONMUX/sbin/conmux $i
if [ "$?" -eq 0 ]; then
pause=1
fi
started="$started $n"
# Preserve the orginal configuration file.
cp "$i" "$CONMUX/log/$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 $name-$helper-helper $CONMUX/bin/conmux-attach $mn $helper-helper
started="$started $name-$helper-helper"
done
fi
if [ "$cmd" = "start" -o "$cmd" = "stop" ]; then
for i in $existing
do
case " $started " in
*\ $i\ *) ;;
*) stop "$i" ;;
esac
done
fi
if [ "$cmd" = "status" ]; then
for n in $existing
do
mn="${n#abat-}"
case "$n" in
registry|*-helper)
;;
*)
status=`console -s $mn`
echo "$mn $status"
esac
done
fi
|