virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / conmux / start
blobdabcd583ea1eb370b9cfaad8da8b0f1def2eece9
1 #!/bin/bash
3 # start -- start up configured conmux servers on this host.
5 # (C) Copyright IBM Corp. 2004, 2005, 2006
6 # Author: Andy Whitcroft <andyw@uk.ibm.com>
8 # The Console Multiplexor is released under the GNU Public License V2
10 if [ -f ~/.gmm.conf ]; then
11 . ~/.gmm.conf
13 CONMUX=${CONMUX:-/usr/local/conmux}
15 cmd="start"
16 if [ "$1" != "" ]; then
17 cmd="$1"
20 PATH=$CONMUX/bin:$CONMUX/sbin:$CONMUX/lib/drivers:$CONMUX/lib/helpers:$PATH
22 function start() {
23 typeset name="$1"
24 typeset pf="$CONMUX/log/$name.pid"
26 shift
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
35 echo "starting $name ..."
36 "$@" >"$CONMUX/log/$name.log" 2>&1 &
37 echo "$!" >"$pf"
39 return 0
41 function stop() {
42 typeset name="$1"
43 typeset pf="$CONMUX/log/$name.pid"
45 echo "stopping $name ..."
46 # Kill it and clear up
47 kill -HUP `cat "$pf"` 2>/dev/null
48 rm -f "$pf"
51 existing=""
52 for i in $CONMUX/log/*.pid
54 n=${i%.pid}
55 n=${n#$CONMUX/log/}
57 if [ "$n" != "*" ]; then
58 existing="$existing $n"
60 done
62 if [ "$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
69 started="registry"
70 pause=0
71 for i in $CONMUX/etc/*.cf
73 n=${i%.cf}
74 n=${n#$CONMUX/etc/}
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
82 start $n $CONMUX/sbin/conmux $i
83 if [ "$?" -eq 0 ]; then
84 pause=1
86 started="$started $n"
88 # Preserve the orginal configuration file.
89 cp "$i" "$CONMUX/log/$n.cf"
91 if grep -q TYPE:numaq "$i"; then
92 autoboot="$autoboot $n"
94 for i in `grep FLAGS: "$i"`; do
95 case "$i" in
96 \#|FLAGS:) ;;
97 *) autoboot="$autoboot $n/$i" ;;
98 esac
99 done
101 done
102 if [ "$pause" -eq 1 ]; then
103 sleep 1
105 for nh in $autoboot
107 name="${nh%/*}"
108 helper="${nh#*/}"
110 mn="${name#abat-}"
111 start $name-$helper-helper $CONMUX/bin/conmux-attach $mn $helper-helper
112 started="$started $name-$helper-helper"
113 done
116 if [ "$cmd" = "start" -o "$cmd" = "stop" ]; then
117 for i in $existing
119 case " $started " in
120 *\ $i\ *) ;;
121 *) stop "$i" ;;
122 esac
123 done
126 if [ "$cmd" = "status" ]; then
127 for n in $existing
129 mn="${n#abat-}"
130 case "$n" in
131 registry|*-helper)
134 status=`console -s $mn`
135 echo "$mn $status"
136 esac
137 done