PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/config/modules/openstackid/files/functions

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