/config/modules/openstackid/files/functions
#! | 150 lines | 147 code | 3 blank | 0 comment | 0 complexity | f458344428e6881d42f90342f774c906 MD5 | raw file
1function print_help() { 2 echo "Usage: `basename $0` command [options]" 3 echo "" 4 echo "Commands:" 5 echo " status [site] return status information about site configurations" 6 echo " init <site> initialize site structure" 7 echo " update <site> update to new version" 8 echo "" 9} 10 11function site_init() { 12 if [ ! $1 ]; then 13 echo "ERROR: site parameter mandatory" 14 exit 1 15 fi 16 CONF_PATH="$CONF_DIR/conf.d/$1.conf" 17 if [ ! -f $CONF_PATH ]; then 18 echo "Site configuration not found: " $1 19 exit 1 20 fi 21 source $CONF_PATH 22 if [ -f "$SITE_ROOT/w/public/index.php" ]; then 23 echo "Cannot override an existing deployment: $SITE_ROOT/w" 24 exit 1 25 fi 26 # cleanup previous broken deployment 27 rm -rf $SITE_ROOT/slot0 28 # create directory structure 29 for dir in slot0 slot1; do 30 mkdir -p $SITE_ROOT/$dir 31 chown $FILE_OWNER:$FILE_GROUP $SITE_ROOT/$dir 32 done 33 target_dir="$SITE_ROOT/slot0" 34 # fetch and extract release tarball 35 umask 0027 36 if [[ $SOURCE_TARBALL == http* ]]; then 37 echo "Download from http!" 38 curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions 39 else 40 echo "extract from local file system" 41 if [ ! -f $SOURCE_TARBALL ]; then 42 echo "Source tarball not found: $SOURCE_TARBALL" 43 exit 1 44 fi 45 tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions 46 fi 47 chown -R $FILE_OWNER:$FILE_GROUP $target_dir 48 umask 0022 49 # link configuration files managed by puppet 50 ln -sf /etc/openstackid/environment.php $target_dir/bootstrap/environment.php 51 ln -sf /etc/openstackid/recaptcha.php $target_dir/app/config/packages/greggilbert/recaptcha/$LARAVEL_ENV/config.php 52 ln -sf /etc/openstackid/database.php $target_dir/app/config/$LARAVEL_ENV/database.php 53 ln -sf /etc/openstackid/log.php $target_dir/app/config/$LARAVEL_ENV/log.php 54 # convert app/storage into symlink and set permissions 55 mv $target_dir/app/storage $SITE_ROOT/ 56 chmod 02770 $SITE_ROOT/storage 57 find $SITE_ROOT/storage/ -type d -exec chmod 0775 {} \; 58 find $SITE_ROOT/storage/ -type f -exec chmod 0664 {} \; 59 rm -rf $target_dir/app/storage 60 ln -s $SITE_ROOT/storage $target_dir/app 61 # populate application database 62 cd $target_dir 63 php artisan migrate --env=$LARAVEL_ENV 64 php artisan db:seed --env=$LARAVEL_ENV 65 # activate site 66 rm -rf $SITE_ROOT/w 67 ln -s $SITE_ROOT/slot0 $SITE_ROOT/w 68} 69 70function site_status() { 71 if [ ! $1 ]; then 72 echo "ERROR: site parameter mandatory" 73 exit 1 74 fi 75 CONF_PATH="$CONF_DIR/conf.d/$1.conf" 76 if [ ! -f $CONF_PATH ]; then 77 echo "Site configuration not found: $1" 78 exit 0 79 fi 80 source $CONF_PATH 81 if [ ! -f "$SITE_ROOT/w/public/index.php" ]; then 82 if [ -d "$SITE_ROOT/slot0" ]; then 83 echo "PENDING" 84 else 85 echo "N/A" 86 exit 1 87 fi 88 else 89 echo "INSTALLED" 90 fi 91} 92 93function site_update() { 94 if [ ! $1 ]; then 95 echo "ERROR: missing site parameter" 96 exit 1 97 fi 98 CONF_PATH="$CONF_DIR/conf.d/$1.conf" 99 if [ ! -f $CONF_PATH ]; then 100 echo "Site configuration not found: $1" 101 exit 0 102 fi 103 source $CONF_PATH 104 SITE_LINK=`readlink -f $SITE_ROOT/w` 105 ACTIVE_SLOT=`basename $SITE_LINK` 106 case $ACTIVE_SLOT in 107 slot0) 108 TARGET_SLOT='slot1' 109 ;; 110 slot1) 111 TARGET_SLOT='slot0' 112 ;; 113 *) 114 echo "Invalid active slot" 115 exit 1 116 esac 117 echo "Target slot: $TARGET_SLOT" 118 target_dir="$SITE_ROOT/$TARGET_SLOT" 119 rm -rf $target_dir 120 mkdir $target_dir 121 # fetch and extract release tarball 122 umask 0027 123 if [[ $SOURCE_TARBALL == http* ]]; then 124 echo "Download from http!" 125 curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions 126 else 127 echo "extract from local file system" 128 if [ ! -f $SOURCE_TARBALL ]; then 129 echo "Source tarball not found: $SOURCE_TARBALL" 130 exit 1 131 fi 132 tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions 133 fi 134 chown -R $FILE_OWNER:$FILE_GROUP $target_dir 135 umask 0022 136 # link configuration files managed by puppet 137 ln -sf /etc/openstackid/environment.php $target_dir/bootstrap/environment.php 138 ln -sf /etc/openstackid/recaptcha.php $target_dir/app/config/packages/greggilbert/recaptcha/$LARAVEL_ENV/config.php 139 ln -sf /etc/openstackid/database.php $target_dir/app/config/$LARAVEL_ENV/database.php 140 ln -sf /etc/openstackid/log.php $target_dir/app/config/$LARAVEL_ENV/log.php 141 # link shared app/storage directory 142 rm -rf $target_dir/app/storage 143 ln -s $SITE_ROOT/storage $target_dir/app 144 # populate application database 145 cd $target_dir 146 php artisan migrate --env=$LARAVEL_ENV 147 # activate site 148 rm -rf $SITE_ROOT/w 149 ln -s $target_dir $SITE_ROOT/w 150}