You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
6.8 KiB

  1. #!/bin/bash
  2. ## 0k git remote path
  3. GIT_0K_BASE=${GIT_0K_BASE:-"0k-ro:/var/git"}
  4. ## 0k git remote options
  5. GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""}
  6. ##
  7. ## Install 0k-manage
  8. ##
  9. mkdir -p /opt/apps
  10. (
  11. if [ -d "/opt/apps/0k-manage" ]; then
  12. cd /opt/apps/0k-manage &&
  13. git pull -r
  14. else
  15. cd /opt/apps &&
  16. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" &&
  17. cd /opt/apps/0k-manage &&
  18. git checkout 0k/prod/master
  19. fi
  20. pip install sact.epoch || exit 1
  21. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "ImportError: No module named interface" ]; then
  22. echo "Error: conflicting installation of zope.interface detected. Trying workaround."
  23. (
  24. cd /usr/local/lib/python2.7/dist-packages
  25. mv zope zope-bad
  26. ) &&
  27. pip install zope.interface --upgrade &&
  28. pip install zope.component --upgrade
  29. if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "" ]; then
  30. echo "Workaround worked."
  31. else
  32. echo "Failed work around."
  33. exit 1
  34. fi
  35. fi
  36. # ln -sf /opt/apps/0k-manage/src/bin/* /usr/local/bin/
  37. )
  38. ##
  39. ## Install 0k-charms
  40. ##
  41. (
  42. if [ -d "/opt/apps/0k-charms" ]; then
  43. cd /opt/apps/0k-charms &&
  44. git checkout master &&
  45. git pull -r
  46. else
  47. cd /opt/apps &&
  48. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git"
  49. fi
  50. if ! [ -d "/srv/charm-store" ]; then
  51. mkdir -p /srv/charm-store
  52. fi
  53. ln -sfn /opt/apps/0k-charms /srv/charm-store/0k-charms
  54. )
  55. ##
  56. ## Install lxc-scripts
  57. ##
  58. (
  59. if ! [ -d "/opt/apps/lxc-scripts" ]; then
  60. cd /opt/apps &&
  61. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git"
  62. fi
  63. cd /opt/apps/lxc-scripts &&
  64. git checkout master &&
  65. git pull -r &&
  66. ln -sfn /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
  67. if [ -f /etc/default/lxc.pre-install ]; then
  68. cp /etc/default/lxc.pre-install /etc/default/lxc
  69. else
  70. cp /etc/default/lxc /etc/default/lxc.pre-install
  71. fi
  72. [ -d /usr/lib/lxc/templates ] && {
  73. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
  74. echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc
  75. }
  76. [ -d /usr/share/lxc/templates ] && {
  77. ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates
  78. echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc
  79. }
  80. )
  81. ##
  82. ## Install 0k-docker
  83. ##
  84. (
  85. if [ -d "/opt/apps/0k-docker" ]; then
  86. cd /opt/apps/0k-docker &&
  87. git checkout master &&
  88. git pull -r
  89. else
  90. cd /opt/apps &&
  91. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-docker"
  92. fi
  93. ln -sfn /opt/apps/0k-docker/bin/* /usr/local/sbin/
  94. ## in update, will remove broken links to binaries that were removed
  95. find -L /usr/local/sbin -maxdepth 1 -type l -delete
  96. )
  97. ##
  98. ## Install 0k.io certificate authority
  99. ##
  100. ## Note that docker should be installed after (or be restarted).
  101. apt-get install -y curl </dev/null
  102. ## This does not seem to work anymore (docker v1.12, ubutnu 14.04 on gani)
  103. echo "Fetching 0k.io CA certificate..."
  104. curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem
  105. cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt
  106. ## This is the new way: https://docs.docker.com/engine/security/certificates/
  107. mkdir -p /etc/docker/certs.d/docker.0k.io
  108. ln -sfn /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt
  109. service docker restart
  110. echo "Login into our server."
  111. docker login -u vm -p iamavm -e vm@0k.io https://docker.0k.io
  112. sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
  113. sysctl -w net.ipv4.ip_forward=1
  114. ##
  115. ## docker-compose
  116. ##
  117. if type -p docker-compose >/dev/null; then
  118. #echo "Found docker-compose..." >&2
  119. if ! docker-compose --version >/dev/null 2>&1; then
  120. echo "'docker-compose' failed ! Please check your docker-compose binary."
  121. echo "Failed install."
  122. docker-compose --version
  123. exit 1
  124. fi
  125. VALID_VERSION_TEXT="docker-compose version 1.21.2, build a133471"
  126. if [ "$(docker-compose --version)" != "$VALID_VERSION_TEXT" ]; then
  127. echo "Invalid version of docker-compose: we need exactly:"
  128. echo "version text: $VALID_VERSION_TEXT"
  129. echo "Failed install."
  130. exit 1
  131. fi
  132. else
  133. if ! [ -d /opt/apps/docker-compose ]; then
  134. (
  135. mkdir -p /opt/apps
  136. cd /opt/apps
  137. git clone https://github.com/docker/compose.git docker-compose &&
  138. cd docker-compose &&
  139. git checkout 0898c783ad2e0d01bd55b47fcb9eb7183edc1015 ## version pinning
  140. )
  141. fi
  142. mkdir -p /opt/venv
  143. if ! type -p virtualenv >/dev/null; then
  144. pip install virtualenv==13.1.2
  145. fi
  146. if ! [ -d /opt/venv/docker-compose ]; then
  147. virtualenv /opt/venv/docker-compose/
  148. fi
  149. . /opt/venv/docker-compose/bin/activate
  150. ( cd /opt/apps/docker-compose &&
  151. python setup.py install )
  152. if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
  153. pip install requests==2.17.3 --upgrade
  154. fi
  155. deactivate
  156. mkdir -p /etc/compose
  157. if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
  158. cat <<EOF >> /etc/compose/local.conf
  159. . /opt/venv/docker-compose/bin/activate
  160. EOF
  161. fi
  162. fi
  163. if [ -d "/opt/apps/0k-compose" ]; then
  164. cd "/opt/apps/0k-compose" &&
  165. git pull -r
  166. else
  167. mkdir -p /opt/apps && cd /opt/apps
  168. git clone "$GIT_0K_BASE"/0k/0k-compose.git
  169. fi
  170. [ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
  171. cat <<EOF > /etc/default/datastore
  172. DATASTORE=/srv/datastore
  173. SNAPSHOT_BACKUP=/var/backups/snapshot
  174. EOF
  175. cat <<EOF > /etc/default/compose
  176. ## if not provided, this will be the default service launched.
  177. export DEFAULT_SERVICES=""
  178. export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
  179. export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
  180. export DATASTORE=\$DOCKER_DATASTORE/data
  181. export CONFIGSTORE=\$DOCKER_DATASTORE/config
  182. EOF
  183. if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
  184. echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
  185. fi
  186. ##
  187. ## Install pgm
  188. ##
  189. (
  190. if [ -d "/opt/apps/0k-pgm" ]; then
  191. cd /opt/apps/0k-pgm &&
  192. git pull -r
  193. else
  194. cd /opt/apps &&
  195. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
  196. cd /opt/apps/0k-pgm &&
  197. git checkout master
  198. fi
  199. ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
  200. apt-get install -y --force-yes pv buffer < /dev/null
  201. apt-get install -y postgresql-client </dev/null
  202. )