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.

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