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.

209 lines
7.0 KiB

  1. #!/bin/bash
  2. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  3. # not use this file except in compliance with the License. You may obtain
  4. # a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  10. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  11. # License for the specific language governing permissions and limitations
  12. # under the License.
  13. if [[ -e /etc/os-release ]]; then
  14. # NOTE(berendt): support for CentOS/RHEL/openSUSE/SLES will be added in the future
  15. source /etc/os-release
  16. INSTALL_DATABASE=0
  17. INSTALL_FAAFO=0
  18. INSTALL_MESSAGING=0
  19. RUN_API=0
  20. RUN_DEMO=0
  21. RUN_WORKER=0
  22. URL_DATABASE='sqlite:////tmp/sqlite.db'
  23. URL_ENDPOINT='http://127.0.0.1'
  24. URL_MESSAGING='amqp://guest:guest@localhost:5672/'
  25. while getopts e:m:d:i:r: FLAG; do
  26. case $FLAG in
  27. i)
  28. case $OPTARG in
  29. messaging)
  30. INSTALL_MESSAGING=1
  31. ;;
  32. database)
  33. INSTALL_DATABASE=1
  34. ;;
  35. faafo)
  36. INSTALL_FAAFO=1
  37. ;;
  38. esac
  39. ;;
  40. r)
  41. case $OPTARG in
  42. demo)
  43. RUN_DEMO=1
  44. ;;
  45. api)
  46. RUN_API=1
  47. ;;
  48. worker)
  49. RUN_WORKER=1
  50. ;;
  51. esac
  52. ;;
  53. e)
  54. URL_ENDPOINT=$OPTARG
  55. ;;
  56. m)
  57. URL_MESSAGING=$OPTARG
  58. ;;
  59. d)
  60. URL_DATABASE=$OPTARG
  61. ;;
  62. *)
  63. echo "error: unknown option $FLAG"
  64. exit 1
  65. ;;
  66. esac
  67. done
  68. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  69. sudo apt-get update
  70. elif [[ $ID = 'fedora' ]]; then
  71. sudo dnf update -y
  72. fi
  73. if [[ $INSTALL_DATABASE -eq 1 ]]; then
  74. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  75. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server python-mysqldb
  76. # HSFD changes for Ubuntu 18.04
  77. sudo sed -i -e "/bind-address/d" /etc/mysql/mysql.conf.d/mysqld.cnf
  78. #sudo sed -i -e "/bind-address/d" /etc/mysql/my.cnf
  79. sudo service mysql restart
  80. elif [[ $ID = 'fedora' ]]; then
  81. sudo dnf install -y mariadb-server python-mysql
  82. printf "[mysqld]\nbind-address = 127.0.0.1\n" | sudo tee /etc/my.cnf.d/faafo.conf
  83. sudo systemctl enable mariadb
  84. sudo systemctl start mariadb
  85. else
  86. echo "error: distribution $ID not supported"
  87. exit 1
  88. fi
  89. sudo mysqladmin password password
  90. sudo mysql -uroot -ppassword mysql -e "CREATE DATABASE IF NOT EXISTS faafo; GRANT ALL PRIVILEGES ON faafo.* TO 'faafo'@'%' IDENTIFIED BY 'password';"
  91. URL_DATABASE='mysql://root:password@localhost/faafo'
  92. fi
  93. if [[ $INSTALL_MESSAGING -eq 1 ]]; then
  94. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  95. sudo apt-get install -y rabbitmq-server
  96. elif [[ $ID = 'fedora' ]]; then
  97. sudo dnf install -y rabbitmq-server
  98. sudo systemctl enable rabbitmq-server
  99. sudo systemctl start rabbitmq-server
  100. else
  101. echo "error: distribution $ID not supported"
  102. exit 1
  103. fi
  104. fi
  105. if [[ $INSTALL_FAAFO -eq 1 ]]; then
  106. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  107. sudo apt-get install -y python-dev python-pip supervisor git zlib1g-dev libmysqlclient-dev python-mysqldb
  108. # Following is needed because of
  109. # https://bugs.launchpad.net/ubuntu/+source/supervisor/+bug/1594740
  110. if [ $(lsb_release --short --codename) = xenial ]; then
  111. # Make sure the daemon is enabled.
  112. if ! systemctl --quiet is-enabled supervisor; then
  113. systemctl enable supervisor
  114. fi
  115. # Make sure the daemon is started.
  116. if ! systemctl --quiet is-active supervisor; then
  117. systemctl start supervisor
  118. fi
  119. fi
  120. elif [[ $ID = 'fedora' ]]; then
  121. sudo dnf install -y python-devel python-pip supervisor git zlib-devel mariadb-devel gcc which python-mysql
  122. sudo systemctl enable supervisord
  123. sudo systemctl start supervisord
  124. #elif [[ $ID = 'opensuse' || $ID = 'sles' ]]; then
  125. # sudo zypper install -y python-devel python-pip
  126. else
  127. echo "error: distribution $ID not supported"
  128. exit 1
  129. fi
  130. # HSFD changed to local repo
  131. git clone https://gogs.informatik.hs-fulda.de/srieger/cloud-computing-msc-ai-examples
  132. cd cloud-computing-msc-ai-examples/faafo
  133. # following line required by bug 1636150
  134. sudo pip install --upgrade pbr
  135. # in m1.tiny instance during cloud-init the following pip install can experience OOM kill
  136. # setup swap to prevent that
  137. sudo dd if=/dev/zero of=/swap bs=1M count=512
  138. sudo chmod 600 /swap
  139. sudo mkswap /swap
  140. sudo swapon /swap
  141. sudo pip install -r requirements.txt
  142. sudo python setup.py install
  143. sudo sed -i -e "s#transport_url = .*#transport_url = $URL_MESSAGING#" /etc/faafo/faafo.conf
  144. sudo sed -i -e "s#database_url = .*#database_url = $URL_DATABASE#" /etc/faafo/faafo.conf
  145. sudo sed -i -e "s#endpoint_url = .*#endpoint_url = $URL_ENDPOINT#" /etc/faafo/faafo.conf
  146. fi
  147. if [[ $RUN_API -eq 1 ]]; then
  148. faafo_api="
  149. [program:faafo_api]
  150. command=$(which faafo-api)
  151. priority=10
  152. startretries=0"
  153. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  154. echo "$faafo_api" | sudo tee -a /etc/supervisor/conf.d/faafo.conf
  155. elif [[ $ID = 'fedora' ]]; then
  156. echo "$faafo_api" | sudo tee -a /etc/supervisord.d/faafo.ini
  157. else
  158. echo "error: distribution $ID not supported"
  159. exit 1
  160. fi
  161. fi
  162. if [[ $RUN_WORKER -eq 1 ]]; then
  163. faafo_worker="
  164. [program:faafo_worker]
  165. command=$(which faafo-worker)
  166. priority=20
  167. startretries=0"
  168. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  169. echo "$faafo_worker" | sudo tee -a /etc/supervisor/conf.d/faafo.conf
  170. elif [[ $ID = 'fedora' ]]; then
  171. echo "$faafo_worker" | sudo tee -a /etc/supervisord.d/faafo.ini
  172. else
  173. echo "error: distribution $ID not supported"
  174. exit 1
  175. fi
  176. fi
  177. if [[ $RUN_WORKER -eq 1 || $RUN_API -eq 1 ]]; then
  178. sudo supervisorctl reload
  179. sleep 5
  180. fi
  181. if [[ $RUN_DEMO -eq 1 && $RUN_API -eq 1 ]]; then
  182. faafo --endpoint-url $URL_ENDPOINT --debug create
  183. fi
  184. else
  185. exit 1
  186. fi