#
# description: Manages all PLC services on this machine
#
-# $Id: guest.init,v 1.16 2006/04/17 17:04:37 mlhuang Exp $
+# $Id$
#
# Source function library and configuration
# being run. The idea is that when the configuration changes, "service
# plc restart" is called, all dependencies are fixed up, and
# everything just works.
+
+### NOTE.
+# we want the resulting myplc to be able to easily skip
+# some steps. e.g. the packages step takes ages if you install
+# all rpms under the repository.
+# We skip steps whose name contains a dot (.) or a tilde (~)
+# this way the operations would just rename a step name e.g.
+# cd /etc/plc.d
+# mv packages packages.hide
+#
+# The drawback is, this stuff does not survive an rpm update
+# but that's maybe a good thing, that all is done at first start
+###
+
steps=($(
for step in /etc/plc.d/* ; do
- if [ -f $step -a -x $step ] ; then
+ stepname=$(basename $step)
+ plainstepname=$(echo $stepname | sed -e 's,\.,,' -e 's,~,,')
+ if [ -f $step -a -x $step -a "$stepname" = "$plainstepname" ] ; then
priority=$(sed -ne 's/# priority: \(.*\)/\1/p' $step)
- echo $priority $(basename $step)
+ echo $priority $stepname
fi
done | sort -n | cut -d' ' -f2
))
# Regenerate configuration files
reload ()
{
+ force=$1
+
# Regenerate the main configuration file from default values
# overlaid with site-specific and current values.
- tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
- plc-config --xml \
- /etc/planetlab/default_config.xml \
- /etc/planetlab/configs/* \
- /etc/planetlab/plc_config.xml \
- >$tmp
- if [ $? -eq 0 ] ; then
- mv $tmp /etc/planetlab/plc_config.xml
- chmod 644 /etc/planetlab/plc_config.xml
- else
- echo "PLC: Warning: Invalid configuration file(s) detected"
- rm -f $tmp
- fi
-
- # Shell constants
- plc-config --shell >/etc/planetlab/plc_config
- . /etc/planetlab/plc_config
+ # Thierry -- 2007-07-05 : values in plc_config.xml are *not* taken into account here
+ files=(
+ /etc/planetlab/default_config.xml
+ /etc/planetlab/configs/site.xml
+ )
+ for file in "${files[@]}" ; do
+ if [ -n "$force" -o $file -nt /etc/planetlab/plc_config.xml ] ; then
+ tmp=$(mktemp /tmp/plc_config.xml.XXXXXX)
+ plc-config --xml "${files[@]}" >$tmp
+ if [ $? -eq 0 ] ; then
+ mv $tmp /etc/planetlab/plc_config.xml
+ chmod 444 /etc/planetlab/plc_config.xml
+ else
+ echo "PLC: Warning: Invalid configuration file(s) detected"
+ rm -f $tmp
+ fi
+ break
+ fi
+ done
- # Generate various defaults
- if [ -z "$PLC_DB_PASSWORD" ] ; then
- PLC_DB_PASSWORD=$(uuidgen)
- plc-config --category=plc_db --variable=password --value="$PLC_DB_PASSWORD" --save
+ # Convert configuration to various formats
+ if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config ] ; then
+ plc-config --shell >/etc/planetlab/plc_config
fi
-
- if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
- PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
- plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save
+ if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/plc_config.py ] ; then
+ plc-config --python >/etc/planetlab/plc_config.py
+ fi
+ if [ -n "$force" -o /etc/planetlab/plc_config.xml -nt /etc/planetlab/php/plc_config.php ] ; then
+ mkdir -p /etc/planetlab/php
+ plc-config --php >/etc/planetlab/php/plc_config.php
fi
-
- # Need to configure network before resolving hostnames
- /etc/plc.d/network start 3>/dev/null 4>/dev/null
-
- PLC_API_MAINTENANCE_SOURCES=$(
- for server in API BOOT WWW ; do
- hostname=PLC_${server}_HOST
- gethostbyname ${!hostname}
- done | sort -u
- )
- plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save
-
- # Save configuration
- mkdir -p /etc/planetlab/php
- plc-config --php >/etc/planetlab/php/plc_config.php
- plc-config --shell >/etc/planetlab/plc_config
-
- # For backward compatibility, until we can convert all code to use
- # the now standardized variable names.
-
- # DB constants are all named the same
- ln -sf plc_config /etc/planetlab/plc_db
-
- # API constants
- cat >/etc/planetlab/plc_api <<EOF
-PL_API_SERVER='$PLC_API_HOST'
-PL_API_PATH='$PLC_API_PATH'
-PL_API_PORT=$PLC_API_PORT
-PL_API_CAPABILITY_AUTH_METHOD='capability'
-PL_API_CAPABILITY_PASS='$PLC_API_MAINTENANCE_PASSWORD'
-PL_API_CAPABILITY_USERNAME='$PLC_API_MAINTENANCE_USER'
-PL_API_TICKET_KEY_FILE='$PLC_API_SSL_KEY'
-PLANETLAB_SUPPORT_EMAIL='$PLC_MAIL_SUPPORT_ADDRESS'
-BOOT_MESSAGES_EMAIL='$PLC_MAIL_BOOT_ADDRESS'
-WWW_BASE='$PLC_WWW_HOST'
-BOOT_BASE='$PLC_BOOT_HOST'
-EOF
-
- # API expects root SSH public key to be at /etc/planetlab/node_root_key
- ln -sf "$PLC_ROOT_SSH_KEY_PUB" /etc/planetlab/node_root_key
-
- # The format is
- #
- # ip:max_role_id:organization_id:password
- #
- # It is unlikely that we will let federated sites use the
- # maintenance account to access each others' APIs, so we always
- # set organization_id to -1.
- (
- echo -n "PL_API_CAPABILITY_SOURCES='"
- first=1
- for ip in $PLC_API_MAINTENANCE_SOURCES ; do
- if [ $first -ne 1 ] ; then
- echo -n " "
- fi
- first=0
- echo -n "$ip:-1:-1:$PLC_API_MAINTENANCE_PASSWORD"
- done
- echo "'"
- ) >>/etc/planetlab/plc_api
-
- cat >/etc/planetlab/php/site_constants.php <<"EOF"
-<?php
-include('plc_config.php');
-
-define('PL_API_SERVER', PLC_API_HOST);
-define('PL_API_PATH', PLC_API_PATH);
-define('PL_API_PORT', PLC_API_PORT);
-define('PL_API_CAPABILITY_AUTH_METHOD', 'capability');
-define('PL_API_CAPABILITY_PASS', PLC_API_MAINTENANCE_PASSWORD);
-define('PL_API_CAPABILITY_USERNAME', PLC_API_MAINTENANCE_USER);
-define('WWW_BASE', PLC_WWW_HOST);
-define('BOOT_BASE', PLC_BOOT_HOST);
-define('DEBUG', PLC_WWW_DEBUG);
-define('API_CALL_DEBUG', PLC_API_DEBUG);
-define('SENDMAIL', PLC_MAIL_ENABLED);
-define('PLANETLAB_SUPPORT_EMAIL', PLC_NAME . ' Support <' . PLC_MAIL_SUPPORT_ADDRESS . '>');
-define('PLANETLAB_SUPPORT_EMAIL_ONLY', PLC_MAIL_SUPPORT_ADDRESS);
-?>
-EOF
}
usage()
echo " stop Stop all PLC subsystems"
echo " reload Regenerate configuration files"
echo " restart Restart all PLC subsystems"
+ echo " checkpoint filename : Checkpoint the current state of MyPLC to filename"
+ echo " restore filename : Restore MyPLC state from filename"
+ echo " steps Displays ordered list of subsystems"
echo
echo "Steps:"
for step in "${steps[@]}" ; do
# Redirect stdout and stderr of each step to /var/log/boot.log
if [ $verbose -eq 0 ] ; then
+ touch /var/log/boot.log
+ chmod 600 /var/log/boot.log
exec 1>>/var/log/boot.log
exec 2>>/var/log/boot.log
fi
shift 1
if [ -z "$1" ] ; then
# Start or stop everything. Regenerate configuration first.
- reload
+ reload force
else
# Start or stop a particular step
steps=("$@")
for step in "${steps[@]}" ; do
if [ -x /etc/plc.d/$step ] ; then
/etc/plc.d/$step start
+ # Steps may alter the configuration, may need to regenerate
+ reload
else
echo "PLC: $step: unrecognized step" >&4
exit 1
step=${steps[$(($nsteps - $i))]}
if [ -x /etc/plc.d/$step ] ; then
/etc/plc.d/$step stop
+ # Steps may alter the configuration, may need to regenerate
+ reload
else
echo "PLC: $step: unrecognized step" >&4
exit 1
;;
reload)
+ reload force
+ ;;
+
+ checkpoint)
+ cpfile=$1
+ if [ -z "$cpfile" ] ; then
+ echo "PLC: checkpoint requires a filename as an argument"
+ exit 1
+ fi
+ cpdir=$(mktemp -d tmp.XXXXXX)
+ cd $cpdir
+ mkdir -p ./etc/planetlab/
+ rsync -av /etc/planetlab/ ./etc/planetlab/
+ /etc/plc.d/db checkpoint ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
+ tar cjf $cpfile etc
+ cd -
+ rm -rf $cpdir
+ ;;
+
+ restore)
+ cpfile=$1
+ cpdir=$(mktemp -d tmp.XXXXXX)
+ cd $cpdir
+ tar xjf $cpfile
+ /etc/plc.d/db restore ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
+ rm -f ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint
+ rsync -av ./etc/planetlab/ /etc/planetlab/
+ cd -
+ rm -rf $cpdir
+ ;;
+
+ steps)
+ echo "${steps[@]}" >&4
+ ;;
+
+ # for backwards compatibility
+ mount|umount|mountstatus)
+ echo "${command} not used within native myplc environment"
;;
*)