#
# description: Manages all PLC services on this machine
#
-# $Id: guest.init,v 1.4 2006/03/28 20:47:57 mlhuang Exp $
+# $Id: guest.init,v 1.5 2006/03/29 00:01:35 mlhuang Exp $
#
PATH=/sbin:/bin:/usr/bin:/usr/sbin
)
nsteps=${#steps[@]}
+# Total number of errors
+ERRORS=0
+
+# Count the exit status of the last command
+check ()
+{
+ ERRORS=$(($ERRORS+$?))
+}
+
+# Return IP address of hostname if resolvable
gethostbyname ()
{
perl -MSocket -e '($a,$b,$c,$d,@addrs) = gethostbyname($ARGV[0]); print inet_ntoa($addrs[0]) . "\n";' $1 2>/dev/null
fi
if [ -z "$PLC_API_MAINTENANCE_SOURCES" ] ; then
+ # Need to configure network before resolving hostnames
+ config_network start
for server in API BOOT WWW ; do
eval hostname=\${PLC_${server}_HOST}
ip=$(gethostbyname $hostname)
case "$1" in
start)
# Minimal /etc/hosts
+ echo "127.0.0.1 localhost.localdomain localhost" >/etc/hosts
(
- echo "127.0.0.1 localhost.localdomain localhost"
for server in API BOOT WWW ; do
eval hostname=\${PLC_${server}_HOST}
ip=$(gethostbyname $hostname)
echo "$ip $hostname"
fi
done
- ) >/etc/hosts
+ ) >>/etc/hosts
# Set up nameservers
(
config_syslog ()
{
service syslog $1
- RETVAL=$?
+ check
}
config_postgresql ()
service postgresql start
# /etc/init.d/postgresql always returns 0, even on failure
status postmaster
- RETVAL=$?
+ check
# Create/update the unprivileged database user and password
if ! psql -U $PLC_DB_USER -c "" template1 >/dev/null 2>&1 ; then
# Shut down the server
service postgresql stop
- RETVAL=$?
+ check
;;
esac
}
%secring $PLC_ROOT_GPG_KEY
%commit
EOF
- RETVAL=$?
+ check
rm -f /dev/random
mknod /dev/random c 1 8
chmod 600 $PLC_ROOT_GPG_KEY_PUB $PLC_ROOT_GPG_KEY
if [ ! -f $PLC_WWW_SSL_KEY ] ; then
mkdir -p $(dirname $PLC_WWW_SSL_KEY)
openssl genrsa -rand /proc/apm:/proc/cpuinfo:/proc/dma:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/pci:/proc/rtc:/proc/uptime 1024 >$PLC_WWW_SSL_KEY
- RETVAL=$(($RETVAL+$?))
+ check
chmod 600 $PLC_WWW_SSL_KEY
fi
$PLC_WWW_HOST
$PLC_MAIL_SUPPORT_ADDRESS
EOF
- RETVAL=$(($RETVAL+$?))
+ check
chmod 644 $PLC_WWW_SSL_CRT
fi
fi
if [ ! -f $PLC_API_SSL_KEY_PUB ] ; then
openssl rsa -pubout <$PLC_API_SSL_KEY >$PLC_API_SSL_KEY_PUB
- RETVAL=$(($RETVAL+$?))
+ check
fi
if [ ! -f $PLC_API_SSL_CRT ] ; then
cp -a $PLC_WWW_SSL_CRT $PLC_API_SSL_CRT
if [ ! -f $PLC_ROOT_SSH_KEY_PUB -o ! -f $PLC_ROOT_SSH_KEY ] ; then
ssh-keygen -N "" -C "$PLC_NAME Central <$PLC_MAIL_SUPPORT_ADDRESS>" \
-b $KEY_LEN_ROOT -t $KEY_TYPE_ROOT -f $tmp/root
- RETVAL=$(($RETVAL+$?))
+ check
install -D -m 600 $tmp/root $PLC_ROOT_SSH_KEY
install -D -m 600 $tmp/root.pub $PLC_ROOT_SSH_KEY_PUB
fi
if [ ! -f $PLC_DEBUG_SSH_KEY_PUB -o ! -f $PLC_DEBUG_SSH_KEY ] ; then
ssh-keygen -N "" -C "$PLC_NAME Central <$PLC_MAIL_SUPPORT_ADDRESS>" \
-b $KEY_LEN_DEBUG -t $KEY_TYPE_DEBUG -f $tmp/debug
- RETVAL=$(($RETVAL+$?))
+ check
install -D -m 600 $tmp/debug $PLC_DEBUG_SSH_KEY
install -D -m 600 $tmp/debug.pub $PLC_DEBUG_SSH_KEY_PUB
fi
chown apache:apache $DocumentRoot/alpina-logs/nodes
service httpd start
- RETVAL=$?
+ check
;;
stop)
service httpd stop
- RETVAL=$?
+ check
;;
esac
}
# Bootstrap the DB
api-config
- RETVAL=$?
+ check
;;
esac
}
# Run them once at startup
gen-slices-xml-05.py
+ check
gen-sites-xml.py
+ check
gen-static-content.py
+ check
service crond start
- RETVAL=$?
+ check
;;
stop)
service crond stop
- RETVAL=$?
+ check
;;
esac
}
{
for step in "${steps[@]}" ; do
echo -n $"PLC: Starting $step: " >&3
- RETVAL=0
+ RETVAL=$ERRORS
config_$step start
- if [ $RETVAL -eq 0 ] ; then
+ if [ $RETVAL -eq $ERRORS ] ; then
success $"PLC: $step startup" >&3
else
failure $"PLC: $step startup" >&3
for i in $(seq 1 $nsteps) ; do
step=${steps[$(($nsteps - $i))]}
echo -n $"PLC: Shutting down $step: " >&3
- RETVAL=0
+ RETVAL=$ERRORS
config_$step stop
- if [ $RETVAL -eq 0 ] ; then
+ if [ $RETVAL -eq $ERRORS ] ; then
success $"PLC: $step shutdown" >&3
else
failure $"PLC: $step shutdown" >&3