Merge branch 'master' of github.com:OpenCFD/OpenFOAM-2.0.x
[OpenFOAM-2.0.x.git] / bin / foamDistccd
blobc020031c54f521c3e7d1d7feade75db5e8b470c8
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. 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 usage()
38 echo "Usage : ${0##*/} start|stop|list"
39 echo ""
40 exit 1
43 RSH='ssh'
45 if [ ! "$DISTCC_HOSTS" ]
46 then
47 echo "${0##*/} Warnings"
48 echo " variable DISTCC_HOSTS not set."
49 echo " please set DISTCC_HOSTS to the list of hosts to use."
50 echo " the format is host1:port host2:port host3:port etc."
51 echo
53 exit 1
56 [ $# -eq 1 ] || usage
59 case "$1" in
60 start)
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" ]
69 then
70 # address only contained 0-9 and '.'. Probably ip address.
71 ip=$machine
72 else
73 # address probably not ip address. Try searching /etc/hosts
74 ip=`egrep " $machine " ~/filteredHosts.txt | awk '{print $1}'`
77 if [ ! "$ip" ]
78 then
79 echo "$0 : host specifier $host either is not an ip address or cannot be found in /etc/hosts."
80 echo "$0 : Exiting."
81 exit 1
84 allowIPS="$allowIPS --allow $ip"
85 done
86 echo "allowIPS=$allowIPS"
88 for host in $DISTCC_HOSTS
90 echo ""
91 echo "Trying to start distccd on host $host ..."
93 machine=`echo "$host" | awk -F: '{print $1}'`
94 port=`echo "$host" | awk -F: '{print $2}'`
96 if [ "$machine" -a "$port" ]
97 then
98 #echo "Machine:$machine port:$port"
99 echo "distccd --daemon $allowIPS --port $port"' --jobs `egrep "^processor" /proc/cpuinfo | wc -l`'
100 $RSH $machine "distccd --verbose --daemon $allowIPS --port $port"' --jobs `egrep "^processor" /proc/cpuinfo | wc -l`'
101 else
102 echo "$0 : host specifier $host not in correct form machine:port."
103 echo "$0 : Exiting."
104 exit 1
106 done
109 stop)
110 for host in $DISTCC_HOSTS
112 echo ""
113 echo "Trying to stop all distccd on host $host ..."
115 machine=`echo "$host" | awk -F: '{print $1}'`
117 $RSH $machine killall distccd
118 done
121 list)
122 for host in $DISTCC_HOSTS
124 echo ""
125 echo "Trying to find process distccd on host $host ..."
127 machine=`echo "$host" | awk -F: '{print $1}'`
129 $RSH $machine "ps -ef | grep distccd | grep -v grep"
130 done
134 usage
136 esac
138 #------------------------------------------------------------------------------