(interesting) errors
- reload(): before resolving hostnames in order to generate
PLC_API_MAINTENANCE_SOURCES, need to generate network files first
#
# description: Manages all PLC services on this machine
#
#
# 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
#
PATH=/sbin:/bin:/usr/bin:/usr/sbin
+# 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
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
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)
for server in API BOOT WWW ; do
eval hostname=\${PLC_${server}_HOST}
ip=$(gethostbyname $hostname)
case "$1" in
start)
# Minimal /etc/hosts
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)
for server in API BOOT WWW ; do
eval hostname=\${PLC_${server}_HOST}
ip=$(gethostbyname $hostname)
echo "$ip $hostname"
fi
done
echo "$ip $hostname"
fi
done
config_syslog ()
{
service syslog $1
config_syslog ()
{
service syslog $1
service postgresql start
# /etc/init.d/postgresql always returns 0, even on failure
status postmaster
service postgresql start
# /etc/init.d/postgresql always returns 0, even on failure
status postmaster
# Create/update the unprivileged database user and password
if ! psql -U $PLC_DB_USER -c "" template1 >/dev/null 2>&1 ; then
# 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
# Shut down the server
service postgresql stop
%secring $PLC_ROOT_GPG_KEY
%commit
EOF
%secring $PLC_ROOT_GPG_KEY
%commit
EOF
rm -f /dev/random
mknod /dev/random c 1 8
chmod 600 $PLC_ROOT_GPG_KEY_PUB $PLC_ROOT_GPG_KEY
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
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
chmod 600 $PLC_WWW_SSL_KEY
fi
chmod 600 $PLC_WWW_SSL_KEY
fi
$PLC_WWW_HOST
$PLC_MAIL_SUPPORT_ADDRESS
EOF
$PLC_WWW_HOST
$PLC_MAIL_SUPPORT_ADDRESS
EOF
chmod 644 $PLC_WWW_SSL_CRT
fi
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
fi
if [ ! -f $PLC_API_SSL_KEY_PUB ] ; then
openssl rsa -pubout <$PLC_API_SSL_KEY >$PLC_API_SSL_KEY_PUB
fi
if [ ! -f $PLC_API_SSL_CRT ] ; then
cp -a $PLC_WWW_SSL_CRT $PLC_API_SSL_CRT
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
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
install -D -m 600 $tmp/root $PLC_ROOT_SSH_KEY
install -D -m 600 $tmp/root.pub $PLC_ROOT_SSH_KEY_PUB
fi
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
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
install -D -m 600 $tmp/debug $PLC_DEBUG_SSH_KEY
install -D -m 600 $tmp/debug.pub $PLC_DEBUG_SSH_KEY_PUB
fi
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
chown apache:apache $DocumentRoot/alpina-logs/nodes
service httpd start
;;
stop)
service httpd stop
;;
stop)
service httpd stop
# Bootstrap the DB
api-config
# Bootstrap the DB
api-config
# Run them once at startup
gen-slices-xml-05.py
# Run them once at startup
gen-slices-xml-05.py
;;
stop)
service crond stop
;;
stop)
service crond stop
{
for step in "${steps[@]}" ; do
echo -n $"PLC: Starting $step: " >&3
{
for step in "${steps[@]}" ; do
echo -n $"PLC: Starting $step: " >&3
- if [ $RETVAL -eq 0 ] ; then
+ if [ $RETVAL -eq $ERRORS ] ; then
success $"PLC: $step startup" >&3
else
failure $"PLC: $step startup" >&3
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
for i in $(seq 1 $nsteps) ; do
step=${steps[$(($nsteps - $i))]}
echo -n $"PLC: Shutting down $step: " >&3
- if [ $RETVAL -eq 0 ] ; then
+ if [ $RETVAL -eq $ERRORS ] ; then
success $"PLC: $step shutdown" >&3
else
failure $"PLC: $step shutdown" >&3
success $"PLC: $step shutdown" >&3
else
failure $"PLC: $step shutdown" >&3