Merge "Clean up bashate failures"

This commit is contained in:
Jenkins 2014-10-20 18:35:44 +00:00 committed by Gerrit Code Review
commit a266ab3e7a
3 changed files with 180 additions and 180 deletions

View File

@ -23,17 +23,17 @@ source $TOP_DIR/deployrc
command="${1}" command="${1}"
case $command in case $command in
init) init)
site_init ${2} site_init ${2}
;; ;;
status) status)
site_status ${2} site_status ${2}
;; ;;
update) update)
site_update ${2} site_update ${2}
;; ;;
*) *)
print_help print_help
exit 1 exit 1
;; ;;
esac esac

View File

@ -5,4 +5,4 @@ FILE_GROUP=www-data
# allow local overrides of env variables # allow local overrides of env variables
if [ -f $TOP_DIR/localrc ]; then if [ -f $TOP_DIR/localrc ]; then
. $TOP_DIR/localrc . $TOP_DIR/localrc
fi fi

View File

@ -1,176 +1,176 @@
function print_help() { function print_help {
echo "Usage: `basename $0` command [options]" echo "Usage: `basename $0` command [options]"
echo "" echo ""
echo "Commands:" echo "Commands:"
echo " status [site] return status information about site configurations" echo " status [site] return status information about site configurations"
echo " init <site> initialize site structure" echo " init <site> initialize site structure"
echo " update <site> update to new version" echo " update <site> update to new version"
echo "" echo ""
} }
function site_init() { function site_init {
if [ ! $1 ]; then if [ ! $1 ]; then
echo "ERROR: site parameter mandatory" echo "ERROR: site parameter mandatory"
exit 1 exit 1
fi
CONF_PATH="$CONF_DIR/conf.d/$1.conf"
if [ ! -f $CONF_PATH ]; then
echo "Site configuration not found: " $1
exit 1
fi
source $CONF_PATH
if [ -f "$SITE_ROOT/w/public/index.php" ]; then
echo "Cannot override an existing deployment: $SITE_ROOT/w"
exit 1
fi
# cleanup previous broken deployment
rm -rf $SITE_ROOT/slot0
# create directory structure
for dir in slot0 slot1; do
mkdir -p $SITE_ROOT/$dir
chown $FILE_OWNER:$FILE_GROUP $SITE_ROOT/$dir
done
target_dir="$SITE_ROOT/slot0"
# fetch catalog and write actual version
fetch_catalog
RELEASE_VERSION=`catalog_get_version`
echo $RELEASE_VERSION > $SITE_ROOT/slot0/release
# fetch and extract release tarball
umask 0027
if [[ $SOURCE_TARBALL == http* ]]; then
echo "Download from http!"
curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions
else
echo "extract from local file system"
if [ ! -f $SOURCE_TARBALL ]; then
echo "Source tarball not found: $SOURCE_TARBALL"
exit 1
fi fi
tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions CONF_PATH="$CONF_DIR/conf.d/$1.conf"
fi if [ ! -f $CONF_PATH ]; then
chown -R $FILE_OWNER:$FILE_GROUP $target_dir echo "Site configuration not found: " $1
umask 0022 exit 1
# link configuration files managed by puppet
ln -sf /etc/openstackid/environment.php $target_dir/bootstrap/environment.php
ln -sf /etc/openstackid/recaptcha.php $target_dir/app/config/packages/greggilbert/recaptcha/$LARAVEL_ENV/config.php
ln -sf /etc/openstackid/database.php $target_dir/app/config/$LARAVEL_ENV/database.php
ln -sf /etc/openstackid/log.php $target_dir/app/config/$LARAVEL_ENV/log.php
# convert app/storage into symlink and set permissions
mv $target_dir/app/storage $SITE_ROOT/
chmod 02770 $SITE_ROOT/storage
find $SITE_ROOT/storage/ -type d -exec chmod 0775 {} \;
find $SITE_ROOT/storage/ -type f -exec chmod 0664 {} \;
rm -rf $target_dir/app/storage
ln -s $SITE_ROOT/storage $target_dir/app
# populate application database
cd $target_dir
php artisan migrate --env=$LARAVEL_ENV
php artisan db:seed --env=$LARAVEL_ENV
# activate site
rm -rf $SITE_ROOT/w
ln -s $SITE_ROOT/slot0 $SITE_ROOT/w
}
function site_status() {
if [ ! $1 ]; then
echo "ERROR: site parameter mandatory"
exit 1
fi
CONF_PATH="$CONF_DIR/conf.d/$1.conf"
if [ ! -f $CONF_PATH ]; then
echo "Site configuration not found: $1"
exit 0
fi
source $CONF_PATH
if [ ! -f "$SITE_ROOT/w/public/index.php" ]; then
if [ -d "$SITE_ROOT/slot0" ]; then
echo "PENDING"
else
echo "N/A"
exit 1
fi fi
else source $CONF_PATH
if [ -f "$SITE_ROOT/w/public/index.php" ]; then
echo "Cannot override an existing deployment: $SITE_ROOT/w"
exit 1
fi
# cleanup previous broken deployment
rm -rf $SITE_ROOT/slot0
# create directory structure
for dir in slot0 slot1; do
mkdir -p $SITE_ROOT/$dir
chown $FILE_OWNER:$FILE_GROUP $SITE_ROOT/$dir
done
target_dir="$SITE_ROOT/slot0"
# fetch catalog and write actual version
fetch_catalog fetch_catalog
REMOTE_VERSION=`catalog_get_version` RELEASE_VERSION=`catalog_get_version`
RELEASE_VERSION=$(head -n 1 $SITE_ROOT/w/release) echo $RELEASE_VERSION > $SITE_ROOT/slot0/release
if [ "$REMOTE_VERSION" == "$RELEASE_VERSION" ]; then # fetch and extract release tarball
echo "INSTALLED [$RELEASE_VERSION]" umask 0027
if [[ $SOURCE_TARBALL == http* ]]; then
echo "Download from http!"
curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions
else else
echo "UPDATE AVAILABLE [$RELEASE_VERSION-$REMOTE_VERSION]" echo "extract from local file system"
if [ ! -f $SOURCE_TARBALL ]; then
echo "Source tarball not found: $SOURCE_TARBALL"
exit 1
fi
tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions
fi fi
fi chown -R $FILE_OWNER:$FILE_GROUP $target_dir
umask 0022
# link configuration files managed by puppet
ln -sf /etc/openstackid/environment.php $target_dir/bootstrap/environment.php
ln -sf /etc/openstackid/recaptcha.php $target_dir/app/config/packages/greggilbert/recaptcha/$LARAVEL_ENV/config.php
ln -sf /etc/openstackid/database.php $target_dir/app/config/$LARAVEL_ENV/database.php
ln -sf /etc/openstackid/log.php $target_dir/app/config/$LARAVEL_ENV/log.php
# convert app/storage into symlink and set permissions
mv $target_dir/app/storage $SITE_ROOT/
chmod 02770 $SITE_ROOT/storage
find $SITE_ROOT/storage/ -type d -exec chmod 0775 {} \;
find $SITE_ROOT/storage/ -type f -exec chmod 0664 {} \;
rm -rf $target_dir/app/storage
ln -s $SITE_ROOT/storage $target_dir/app
# populate application database
cd $target_dir
php artisan migrate --env=$LARAVEL_ENV
php artisan db:seed --env=$LARAVEL_ENV
# activate site
rm -rf $SITE_ROOT/w
ln -s $SITE_ROOT/slot0 $SITE_ROOT/w
} }
function fetch_catalog() { function site_status {
curl --silent $SOURCE_ROOT > $SITE_ROOT/releases.lst if [ ! $1 ]; then
grep -q "^<!DOCTYPE HTML PUBLIC" $SITE_ROOT/releases.lst echo "ERROR: site parameter mandatory"
} exit 1
fi
function catalog_get_version() { CONF_PATH="$CONF_DIR/conf.d/$1.conf"
RAW_LINE=`cat $SITE_ROOT/releases.lst | grep "$RELEASE_NAME" | sed "s/<[^>]\+>//g" | sed -r "s/^$RELEASE_NAME//"` if [ ! -f $CONF_PATH ]; then
RELEASE_DATE=`echo $RAW_LINE | awk '{ print $1 " " $2}'` echo "Site configuration not found: $1"
echo $RELEASE_DATE exit 0
} fi
source $CONF_PATH
function site_update() { if [ ! -f "$SITE_ROOT/w/public/index.php" ]; then
if [ ! $1 ]; then if [ -d "$SITE_ROOT/slot0" ]; then
echo "ERROR: missing site parameter" echo "PENDING"
exit 1 else
fi echo "N/A"
CONF_PATH="$CONF_DIR/conf.d/$1.conf" exit 1
if [ ! -f $CONF_PATH ]; then fi
echo "Site configuration not found: $1" else
exit 0 fetch_catalog
fi REMOTE_VERSION=`catalog_get_version`
source $CONF_PATH RELEASE_VERSION=$(head -n 1 $SITE_ROOT/w/release)
SITE_LINK=`readlink -f $SITE_ROOT/w` if [ "$REMOTE_VERSION" == "$RELEASE_VERSION" ]; then
ACTIVE_SLOT=`basename $SITE_LINK` echo "INSTALLED [$RELEASE_VERSION]"
case $ACTIVE_SLOT in else
slot0) echo "UPDATE AVAILABLE [$RELEASE_VERSION-$REMOTE_VERSION]"
TARGET_SLOT='slot1' fi
;;
slot1)
TARGET_SLOT='slot0'
;;
*)
echo "Invalid active slot"
exit 1
esac
echo "Target slot: $TARGET_SLOT"
target_dir="$SITE_ROOT/$TARGET_SLOT"
rm -rf $target_dir
mkdir $target_dir
# fetch catalog and write actual version
fetch_catalog
RELEASE_VERSION=`catalog_get_version`
echo $RELEASE_VERSION > $target_dir/release
# fetch and extract release tarball
umask 0027
if [[ $SOURCE_TARBALL == http* ]]; then
echo "Download from http!"
curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions
else
echo "extract from local file system"
if [ ! -f $SOURCE_TARBALL ]; then
echo "Source tarball not found: $SOURCE_TARBALL"
exit 1
fi fi
tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions }
fi
chown -R $FILE_OWNER:$FILE_GROUP $target_dir function fetch_catalog {
umask 0022 curl --silent $SOURCE_ROOT > $SITE_ROOT/releases.lst
# link configuration files managed by puppet grep -q "^<!DOCTYPE HTML PUBLIC" $SITE_ROOT/releases.lst
ln -sf /etc/openstackid/environment.php $target_dir/bootstrap/environment.php }
ln -sf /etc/openstackid/recaptcha.php $target_dir/app/config/packages/greggilbert/recaptcha/$LARAVEL_ENV/config.php
ln -sf /etc/openstackid/database.php $target_dir/app/config/$LARAVEL_ENV/database.php function catalog_get_version {
ln -sf /etc/openstackid/log.php $target_dir/app/config/$LARAVEL_ENV/log.php RAW_LINE=`cat $SITE_ROOT/releases.lst | grep "$RELEASE_NAME" | sed "s/<[^>]\+>//g" | sed -r "s/^$RELEASE_NAME//"`
# link shared app/storage directory RELEASE_DATE=`echo $RAW_LINE | awk '{ print $1 " " $2}'`
rm -rf $target_dir/app/storage echo $RELEASE_DATE
ln -s $SITE_ROOT/storage $target_dir/app }
# populate application database
cd $target_dir function site_update {
php artisan migrate --env=$LARAVEL_ENV if [ ! $1 ]; then
# activate site echo "ERROR: missing site parameter"
rm -rf $SITE_ROOT/w exit 1
ln -s $target_dir $SITE_ROOT/w fi
CONF_PATH="$CONF_DIR/conf.d/$1.conf"
if [ ! -f $CONF_PATH ]; then
echo "Site configuration not found: $1"
exit 0
fi
source $CONF_PATH
SITE_LINK=`readlink -f $SITE_ROOT/w`
ACTIVE_SLOT=`basename $SITE_LINK`
case $ACTIVE_SLOT in
slot0)
TARGET_SLOT='slot1'
;;
slot1)
TARGET_SLOT='slot0'
;;
*)
echo "Invalid active slot"
exit 1
esac
echo "Target slot: $TARGET_SLOT"
target_dir="$SITE_ROOT/$TARGET_SLOT"
rm -rf $target_dir
mkdir $target_dir
# fetch catalog and write actual version
fetch_catalog
RELEASE_VERSION=`catalog_get_version`
echo $RELEASE_VERSION > $target_dir/release
# fetch and extract release tarball
umask 0027
if [[ $SOURCE_TARBALL == http* ]]; then
echo "Download from http!"
curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions
else
echo "extract from local file system"
if [ ! -f $SOURCE_TARBALL ]; then
echo "Source tarball not found: $SOURCE_TARBALL"
exit 1
fi
tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions
fi
chown -R $FILE_OWNER:$FILE_GROUP $target_dir
umask 0022
# link configuration files managed by puppet
ln -sf /etc/openstackid/environment.php $target_dir/bootstrap/environment.php
ln -sf /etc/openstackid/recaptcha.php $target_dir/app/config/packages/greggilbert/recaptcha/$LARAVEL_ENV/config.php
ln -sf /etc/openstackid/database.php $target_dir/app/config/$LARAVEL_ENV/database.php
ln -sf /etc/openstackid/log.php $target_dir/app/config/$LARAVEL_ENV/log.php
# link shared app/storage directory
rm -rf $target_dir/app/storage
ln -s $SITE_ROOT/storage $target_dir/app
# populate application database
cd $target_dir
php artisan migrate --env=$LARAVEL_ENV
# activate site
rm -rf $SITE_ROOT/w
ln -s $target_dir $SITE_ROOT/w
} }