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