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.

246 lines
6.2 KiB

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