summaryrefslogtreecommitdiff
path: root/packaging/RedHat/init.d/distcc
blob: 70d6d3176514538696da87e899fbd44186eb3209 (plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
#
#	/etc/rc.d/init.d/distcc
#
# Starts the distccd daemon
#
# WARNING: Don't enable on untrusted networks
#
# NOTE: Allows access from all networks listed in clients.allow
# clients.allow is searched for in directories
#   /etc/distcc/`dnsdomainname`/clients.allow
#   /etc/distcc/clients.allow
# Format of clients.allow is 
#   addr/size
#   addr/size
#   addr/size
# etc. e.g.
#   196.168.0.0/16
#   127.0.0.0/8
#
# chkconfig: - 80 20
# description: Start the distcc daemon
# processname: distccd
#

#
# Determine which kind of configuration we're using
#
system=unknown
if [ -f /etc/debian_version ]; then
    system=debian
elif [ -f /etc/redhat-release ]; then
    system=redhat
else
    echo "$0: Unknown system, please port and contact distcc-admin@google.com" 1>&2
    exit 1
fi

OPTIONS="--daemon --stats --job-lifetime=1200"
USER=distcc
PROG="distccd"
PIDFILE=/var/run/$PROG.pid
EXEC="/usr/bin/distccd"


if [[ -f /etc/sitename.install ]]; then
        # goobuntu
        DOMAIN=`cat /etc/sitename.install`
        CONFIGDIR=/etc/site/current/distcc
	NORESTART=$CONFIGDIR/no-restart
else
        # grhat
        DOMAIN=`/bin/dnsdomainname`
        CONFIGDIR=/etc/distcc
	NORESTART=$CONFIGDIR/no-restart
fi


if [ $system = redhat ]; then

	. /etc/init.d/functions

	# Source networking configuration.
	. /etc/sysconfig/network

	# Check that networking is up.
	[ ${NETWORKING} = "no" ] && exit 0
fi


if [ $system = debian ]; then
    . /lib/lsb/init-functions
    . /etc/default/distcc
    thisscript="$0"
    if [ ! -f "$thisscript" ]; then
        echo "$0: Cannot find myself" 1>&2
        exit 1
    fi
    if [ "$STARTDISTCC" != "true" ] ; then
        echo "STARTDISTCC is set to false in /etc/default/distcc"
        echo "$something is not starting"
        exit 0
    fi
    touch $PIDFILE
    chown $USER $PIDFILE
fi



# Tell distccd to store temp files in /var/tmp/distcc to avoid filling up /
# The sysadmin may want to make /var/tmp/distcc be a symlink to a
# directory on a larger partition (hence the /. on the chown)
TMPDIR=/var/tmp/distcc
export TMPDIR
mkdir -p $TMPDIR
chown $USER $TMPDIR/.
rm -rf $TMPDIR/* || :
chmod 700 $TMPDIR

RETVAL=0

[ -x /usr/bin/distccd ] || exit 0

ALLOWFILE=""


if test -f $CONFIGDIR/clients.allow; then
        ALLOWFILE=$CONFIGDIR/clients.allow
elif test -f $CONFIGDIR/$DOMAIN/clients.allow; then
        ALLOWFILE=$CONFIGDIR/$DOMAIN/clients.allow
else
	echo "$0: no clients allowed"
	exit 1
fi


if test "$ALLOWFILE"x != x; then
	ALLOW_OPTIONS=$(sed -e 's/#.*$//' -e '/^[ 	]*$/d' -e 's/^/--allow=/' < $ALLOWFILE)
	OPTIONS="$OPTIONS $ALLOW_OPTIONS"
fi


rh_start() {
	echo -n "Starting $PROG"

	if [[ -f $NORESTART ]]
	then
		echo "failed -- $NORESTART present"
		return 1
	fi

        #--- begin crosstool-specific configuration ---
	# List directories which might contain installations of crosstool on this node
	# This will let users compile on this node regardless of where crosstool
	# is installed on client or server
	# Neccessary because crosstool compilers are identified not just by
	# a command name, but also by the directory they're in (if you have
	# several toolchains built for a particular target).
	COMPILERS=
	# modern crosstool 
	test -d /usr/crosstool && COMPILERS="$COMPILERS /usr/crosstool/*/*/bin/*-[cg][+c][+c] /usr/crosstool/v*/*/*/bin/*-[cg][+c][+c] /usr/crosstool/v4/*/*/*/bin/*-[cg][+c][+c]"
	# old crosstool (which stored everything in a directory named for the build system type)
	test -d /opt/crosstool && COMPILERS="$COMPILERS /opt/crosstool/*/*/*/bin/*-[cg][+c][+c]"
	test -d /home/build/buildtools/crosstool/v7 && COMPILERS="$COMPILERS /home/build/buildtools/crosstool/v7/*/*/bin/*-[cg][+c][+c]"
	if test ! -d $CONFIGDIR; then
		mkdir -p $CONFIGDIR
	fi
	CMDLIST=$CONFIGDIR/commands.allow
	# Expand the wildcards in $COMPILERS, put one file per line, empty file if no match
	echo $COMPILERS | tr '\040' '\012' > $CMDLIST
	ENV="DISTCC_CMDLIST=$CMDLIST DISTCC_CMDLIST_NUMWORDS=5 TMPDIR=$TMPDIR"
        #--- done crosstool-specific configuration ---

	daemon --user $USER $ENV $PROG $OPTIONS
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$PROG
        return $RETVAL
}

rh_stop() {
	echo -n "Shutting down $PROG"
	killproc $PROG
	RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
        return $RETVAL
}

redhat() {
	case "$1" in
		start)
			rh_start
			;;
		stop)
			rh_stop
			;;
		status)
			status $PROG
			RETVAL=$?
			;;
		restart|reload)
			rh_stop
			rh_start
			RETVAL=$?
			;;
		condrestart)
			if [ -f /var/lock/subsys/$PROG ]; then
				rh_stop
				rh_start
				RETVAL=$?
			fi
			;;
		*)
			echo $"Usage $0 {start|stop|restart|condrestart|status}"
			exit 1
	esac
}

deb_start() {
        log_begin_msg "Starting $PROG..."

	if [[ -f $NORESTART ]]
	then
		log_end_msg 1
		echo "distcc start failed -- $NORESTART present"
		return 1
	fi

        #--- begin crosstool-specific configuration ---
	# List directories which might contain installations of crosstool on this node
	# This will let users compile on this node regardless of where crosstool
	# is installed on client or server
	# Neccessary because crosstool compilers are identified not just by
	# a command name, but also by the directory they're in (if you have
	# several toolchains built for a particular target).
	COMPILERS=
	# modern crosstool 
	test -d /usr/crosstool && COMPILERS="$COMPILERS /usr/crosstool/*/*/bin/*-[cg][+c][+c] /usr/crosstool/v*/*/*/bin/*-[cg][+c][+c] /usr/crosstool/v4/*/*/*/bin/*-[cg][+c][+c]"
	# old crosstool (which stored everything in a directory named for the build system type)
	test -d /opt/crosstool && COMPILERS="$COMPILERS /opt/crosstool/*/*/*/bin/*-[cg][+c][+c]"
	test -d /home/build/buildtools/crosstool/v7 && COMPILERS="$COMPILERS /home/build/buildtools/crosstool/v7/*/*/bin/*-[cg][+c][+c]"
	if test ! -d $CONFIGDIR; then
		mkdir -p $CONFIGDIR
	fi
	CMDLIST=$CONFIGDIR/commands.allow
	# Expand the wildcards in $COMPILERS, put one file per line, empty file if no match
	echo $COMPILERS | tr '\040' '\012' > $CMDLIST
	export DISTCC_CMDLIST=$CMDLIST
	export DISTCC_CMDLIST_NUMWORDS=5
	export TMPDIR=$TMPDIR

        #--- done crosstool-specific configuration ---

	start-stop-daemon --start --name distccd --pidfile $PIDFILE -m --chuid $USER --exec $EXEC -- $OPTIONS || log_end_msg 1
	RETVAL=$?
        log_end_msg 0
        return $RETVAL
}

deb_stop() {
	log_begin_msg "Shutting down $PROG..."
        start-stop-daemon --stop  --name distccd --exec $EXEC --retry 30 || \
                log_success_msg "$PROG not running"
	RETVAL=$?
        log_end_msg 0
        [ $RETVAL -eq 0 ] && rm -f $PIDFILE
        return $RETVAL
}

debian() {
	case "$1" in
		start)
			deb_start
			;;
		stop)
			deb_stop
			;;
		restart|reload)
			deb_stop
			deb_start
			RETVAL=$?
			;;
		condrestart)
			if [ -f /var/lock/subsys/$PROG ]; then
				deb_stop
				deb_start
				RETVAL=$?
			fi
			;;
		*)
			echo $"Usage $0 {start|stop|restart|condrestart}"
			exit 1
	esac
}

# See how we were called.

RETVAL=0
if [ $system = debian ]; then
        debian "$@"
elif [ $system = redhat ]; then
        redhat "$@"
fi

exit $RETVAL