Merge commit 'b5be6201e00421a59e574a07b3d28cde5defff84'
[foam-extend-4.0.git] / bin / foamDistccd
blob77c5e898a1167cf43b8819c8f989b0e7063900d6
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration | Version: 4.0
6 # \\ / A nd | Web: http://www.foam-extend.org
7 # \\/ M anipulation | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation, either version 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamDistccd
28 # Description
29 # Script to control distccd daemons. (distcc/distccd is a distributed
30 # C/C++ compilation frontend). Distccd daemons need to be running
31 # on all platforms one wants to build on. The platforms are specified
32 # in the DISTCC_HOSTS environment variable.
34 #------------------------------------------------------------------------------
36 printUsage()
38 echo "Usage : `basename $0` start|stop|list"
39 echo ""
42 RSH='ssh'
44 if [ ! "$DISTCC_HOSTS" ]; then
45 echo "`basename $0`: variable DISTCC_HOSTS not set."
46 echo "`basename $0`: please set DISTCC_HOSTS to the list of hosts to use."
47 echo "`basename $0`: the format is host1:port host2:port host3:port etc."
48 echo ""
50 exit 1
53 if [ $# -ne 1 ]; then
54 printUsage
55 exit 1
59 if [ "$1" = 'start' ]; then
61 grep -v '^#' /etc/hosts | awk '{print $1, $2 " "}' > ~/filteredHosts.txt
63 allowIPS=''
64 for host in $DISTCC_HOSTS
66 machine=`echo "$host" | awk -F: '{print $1}'`
67 iptest=`echo "$machine" | sed -e 's/[0-9.]//g'`
68 if [ ! "$iptest" ]; then
69 # address only contained 0-9 and '.'. Probably ip address.
70 ip=$machine
71 else
72 # address probably not ip address. Try searching /etc/hosts
73 ip=`egrep " $machine " ~/filteredHosts.txt | awk '{print $1}'`
76 if [ ! "$ip" ]; then
77 echo "$0 : host specifier $host either is not an ip address or cannot be found in /etc/hosts."
78 echo "$0 : Exiting."
79 exit 1
82 allowIPS="$allowIPS --allow $ip"
83 done
84 echo "allowIPS=$allowIPS"
86 for host in $DISTCC_HOSTS
88 echo ""
89 echo "Trying to start distccd on host $host ..."
91 machine=`echo "$host" | awk -F: '{print $1}'`
92 port=`echo "$host" | awk -F: '{print $2}'`
94 if [ "$machine" -a "$port" ]; then
95 #echo "Machine:$machine port:$port"
96 echo "distccd --daemon $allowIPS --port $port"' --jobs `egrep "^processor" /proc/cpuinfo | wc -l`'
97 $RSH $machine "distccd --verbose --daemon $allowIPS --port $port"' --jobs `egrep "^processor" /proc/cpuinfo | wc -l`'
98 else
99 echo "$0 : host specifier $host not in correct form machine:port."
100 echo "$0 : Exiting."
101 exit 1
103 done
105 elif [ "$1" = 'stop' ]; then
107 for host in $DISTCC_HOSTS
109 echo ""
110 echo "Trying to stop all distccd on host $host ..."
112 machine=`echo "$host" | awk -F: '{print $1}'`
114 $RSH $machine killall distccd
115 done
118 elif [ "$1" = 'list' ]; then
120 for host in $DISTCC_HOSTS
122 echo ""
123 echo "Trying to find process distccd on host $host ..."
125 machine=`echo "$host" | awk -F: '{print $1}'`
127 $RSH $machine "ps -ef | grep distccd | grep -v grep"
128 done
130 else
132 printUsage
133 exit 1
137 #------------------------------------------------------------------------------