PageRenderTime 64ms CodeModel.GetById 59ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/rc3.d/S20distcc

http://github.com/brinkman83/bashrc
Shell | 149 lines | 103 code | 14 blank | 32 comment | 15 complexity | 5a26ffe225f3c772495e930b8e9d47fb MD5 | raw file
  1#!/bin/sh
  2### BEGIN INIT INFO
  3# Provides:          distcc
  4# Required-Start:    $remote_fs $syslog
  5# Required-Stop:     $remote_fs $syslog
  6# Should-Start:      $network
  7# Should-Stop:       $network
  8# Default-Start:     2 3 4 5
  9# Default-Stop:      1
 10# Short-Description: simple distributed compiler client and server
 11### END INIT INFO
 12#
 13# distccd Debian init.d script contributed by Jason Thomas.  (Debian #161136)
 14#
 15# skeleton	example file to build /etc/init.d/ scripts.
 16#		This file should be used to construct scripts for /etc/init.d.
 17#
 18#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
 19#		Modified for Debian GNU/Linux
 20#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
 21#
 22# Version:	@(#)skeleton  1.9.1  08-Apr-2002  miquels@cistron.nl
 23#
 24
 25PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 26DAEMON=/usr/bin/distccd
 27NAME=distccd
 28DESC="Distributed Compiler Daemon"
 29DAEMON_ARGS="--pid-file=/var/run/$NAME.pid --log-file=/var/log/$NAME.log --daemon"
 30# please change those variables by overriding them in /etc/defaults/distcc
 31ALLOWEDNETS=""
 32LISTENER=""
 33NICE=""
 34ZEROCONF=""
 35JOBS=""
 36
 37set -e
 38
 39. /lib/lsb/init-functions
 40
 41# Reads config file (will override defaults above)
 42[ -r /etc/default/distcc ] && . /etc/default/distcc
 43
 44test -x $DAEMON || exit 0
 45
 46# construct access list
 47ALLOW=""
 48for net in $ALLOWEDNETS
 49do
 50	ALLOW="$ALLOW --allow $net"
 51done
 52
 53if test -n "$ALLOW"; then
 54	DAEMON_ARGS="$DAEMON_ARGS $ALLOW"
 55fi
 56
 57if test -n "$LISTENER"; then
 58	DAEMON_ARGS="$DAEMON_ARGS --listen $LISTENER"
 59fi
 60
 61if test -n "$NICE"; then
 62	if [ "$NICE" -gt 0 ] && [ "$NICE" -le 20 ]; then
 63		DAEMON_ARGS="$DAEMON_ARGS --nice $NICE"
 64	fi
 65fi
 66
 67if test -n "$JOBS"; then
 68	DAEMON_ARGS="$DAEMON_ARGS --jobs $JOBS"
 69fi
 70
 71if [ "$ZEROCONF" = "true" ] || [ "$ZEROCONF" = "YES" ]; then
 72	DAEMON_ARGS="$DAEMON_ARGS --zeroconf"
 73fi
 74
 75should_start() {
 76	if [ "$STARTDISTCC" != "true" ] && [ "$STARTDISTCC" != "YES" ]; then
 77		log_warning_msg "STARTDISTCC is set to false in /etc/default/distcc"
 78		log_warning_msg "$DAEMON not starting"
 79		exit 0
 80	fi
 81	# we need permission to write to the pid file
 82	touch /var/run/$NAME.pid
 83	chown distccd /var/run/$NAME.pid
 84}
 85
 86case "$1" in
 87  start)
 88	should_start
 89	log_begin_msg "Starting $DESC: $NAME"
 90	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
 91	--chuid distccd \
 92	--exec $DAEMON -- $DAEMON_ARGS ||
 93	{
 94	    code=$?
 95	    log_warning_msg "$0: start failed with error code $code" >&2
 96	    log_end_msg $code
 97	    exit $code
 98	}
 99	log_end_msg 0
100	;;
101  stop)
102	log_begin_msg "Stopping $DESC: $NAME"
103	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
104		--oknodo \
105		--exec $DAEMON ||
106	{
107	    code=$?
108	    log_warning_msg "$0: stop failed with error code $code" >&2
109	    log_end_msg $code
110	    exit $code
111	}
112	rm -f /var/run/$NAME.pid >/dev/null 2>&1
113	log_end_msg 0
114	;;
115  restart|force-reload)
116	#
117	#	If the "reload" option is implemented, move the "force-reload"
118	#	option to the "reload" entry above. If not, "force-reload" is
119	#	just the same as "restart".
120	#
121	log_begin_msg "Restarting $DESC: $NAME"
122	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
123		--oknodo \
124		--exec $DAEMON
125	sleep 1
126	should_start
127	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
128		--chuid distccd \
129		--exec $DAEMON -- $DAEMON_ARGS ||
130	{
131	    code=$?
132	    rm -f /var/run/$NAME.pid >/dev/null 2>&1
133	    log_warning_msg "$0: restart failed with error code $code" >&2
134	    log_end_msg $code
135	    exit $code
136	}
137	log_end_msg 0
138	;;
139  status)
140	status_of_proc $DAEMON $NAME
141	;;
142  *)
143	N=/etc/init.d/$NAME
144	echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
145	exit 1
146	;;
147esac
148
149exit 0