1180740Sdes#!/sbin/sh
2180740Sdes
3180740Sdes#
4180740Sdes# egd.rc: EGD start-up and shutdown script
5180740Sdes#
6180740Sdes
7180740Sdes# Allowed exit values:
8180740Sdes#       0 = success; causes "OK" to show up in checklist.
9180740Sdes#       1 = failure; causes "FAIL" to show up in checklist.
10180740Sdes#       2 = skip; causes "N/A" to show up in the checklist.
11180740Sdes#           Use this value if execution of this script is overridden
12180740Sdes#           by the use of a control variable, or if this script is not
13180740Sdes#           appropriate to execute for some other reason.
14180740Sdes#       3 = reboot; causes the system to be rebooted after execution.
15180740Sdes
16180740Sdes# Input and output:
17180740Sdes#       stdin is redirected from /dev/null
18180740Sdes#
19180740Sdes#       stdout and stderr are redirected to the /etc/rc.log file
20180740Sdes#       during checklist mode, or to the console in raw mode.
21180740Sdes
22180740Sdesumask 022
23180740Sdes
24180740SdesPATH=/usr/sbin:/usr/bin:/sbin
25180740Sdesexport PATH
26180740Sdes
27180740SdesWHAT='EGD (entropy gathering daemon)'
28180740SdesWHAT_PATH=/opt/perl/bin/egd.pl
29180740SdesWHAT_CONFIG=/etc/rc.config.d/egd
30180740SdesWHAT_LOG=/etc/opt/egd/egd.log
31180740Sdes
32180740Sdes# NOTE: If your script executes in run state 0 or state 1, then /usr might
33180740Sdes#       not be available.  Do not attempt to access commands or files in
34180740Sdes#       /usr unless your script executes in run state 2 or greater.  Other
35180740Sdes#       file systems typically not mounted until run state 2 include /var
36180740Sdes#       and /opt.
37180740Sdes
38180740Sdesrval=0
39180740Sdes
40180740Sdes# Check the exit value of a command run by this script.  If non-zero, the
41180740Sdes# exit code is echoed to the log file and the return value of this script
42180740Sdes# is set to indicate failure.
43180740Sdes
44180740Sdesset_return() {
45180740Sdes	x=$?
46180740Sdes	if [ $x -ne 0 ]; then
47180740Sdes		echo "EXIT CODE: $x"
48180740Sdes		rval=1	# script FAILed
49180740Sdes	fi
50180740Sdes}
51180740Sdes
52180740Sdescase $1 in
53180740Sdes'start_msg')
54180740Sdes	echo "Starting $WHAT"
55180740Sdes	;;
56180740Sdes
57180740Sdes'stop_msg')
58180740Sdes	echo "Stopping $WHAT"
59180740Sdes	;;
60180740Sdes
61180740Sdes'start')
62180740Sdes	if [ -f $WHAT_CONFIG ] ; then
63180740Sdes		. $WHAT_CONFIG
64180740Sdes	else
65180740Sdes		echo "ERROR: $WHAT_CONFIG defaults file MISSING"
66180740Sdes	fi
67180740Sdes	
68180740Sdes
69180740Sdes	if [ "$EGD_START" -eq 1 -a -x $WHAT_PATH ]; then
70180740Sdes		EGD_LOG=${EGD_LOG:-$WHAT_LOG}
71180740Sdes		su egd -c "nohup $WHAT_PATH $EGD_ARGS >$EGD_LOG 2>&1" &&
72180740Sdes			echo $WHAT started
73180740Sdes		set_return
74180740Sdes	else
75180740Sdes		rval=2
76180740Sdes	fi
77180740Sdes	;;
78180740Sdes
79180740Sdes'stop')
80180740Sdes	pid=`ps -fuegd | awk '$1 == "egd" { print $2 }'`
81180740Sdes	if [ "X$pid" != "X" ]; then
82180740Sdes		if kill "$pid"; then
83180740Sdes			echo "$WHAT stopped"
84180740Sdes		else
85180740Sdes			rval=1
86180740Sdes			echo "Unable to stop $WHAT"
87180740Sdes		fi
88180740Sdes	fi
89180740Sdes	set_return
90180740Sdes	;;
91180740Sdes
92180740Sdes*)
93180740Sdes	echo "usage: $0 {start|stop|start_msg|stop_msg}"
94180740Sdes	rval=1
95180740Sdes	;;
96180740Sdesesac
97180740Sdes
98180740Sdesexit $rval
99