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
7.7 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. # fedora currently not tested nor supported
  72. sudo dnf update -y
  73. fi
  74. if [[ $INSTALL_DATABASE -eq 1 ]]; then
  75. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  76. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server python3-mysqldb
  77. # HSFD changes for Ubuntu 18.04
  78. #sudo sed -i -e "/bind-address/d" /etc/mysql/mysql.conf.d/mysqld.cnf
  79. ##sudo sed -i -e "/bind-address/d" /etc/mysql/my.cnf
  80. sudo sed -i -e "s/127.0.0.1/0.0.0.0/g" /etc/mysql/mariadb.conf.d/50-server.cnf
  81. sudo mysqladmin password password
  82. sudo systemctl restart mariadb
  83. elif [[ $ID = 'fedora' ]]; then
  84. # fedora currently not tested nor supported
  85. sudo dnf install -y mariadb-server python3-mysql
  86. printf "[mysqld]\nbind-address = 127.0.0.1\n" | sudo tee /etc/my.cnf.d/faafo.conf
  87. sudo mysqladmin password password
  88. sudo systemctl enable mariadb
  89. sudo systemctl start mariadb
  90. else
  91. echo "error: distribution $ID not supported"
  92. exit 1
  93. fi
  94. sudo mysql -uroot -ppassword mysql -e "CREATE DATABASE IF NOT EXISTS faafo; GRANT ALL PRIVILEGES ON faafo.* TO 'faafo'@'%' IDENTIFIED BY 'password';"
  95. URL_DATABASE='mysql://root:password@localhost/faafo'
  96. fi
  97. if [[ $INSTALL_MESSAGING -eq 1 ]]; then
  98. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  99. sudo apt-get install -y rabbitmq-server
  100. # fixes for rabbitmq setup
  101. sudo rabbitmqctl add_user faafo guest
  102. sudo rabbitmqctl set_user_tags faafo administrator
  103. sudo rabbitmqctl set_permissions -p / faafo ".*" ".*" ".*"
  104. elif [[ $ID = 'fedora' ]]; then
  105. # fedora currently not tested nor supported
  106. sudo dnf install -y rabbitmq-server
  107. sudo systemctl enable rabbitmq-server
  108. sudo systemctl start rabbitmq-server
  109. else
  110. echo "error: distribution $ID not supported"
  111. exit 1
  112. fi
  113. fi
  114. if [[ $INSTALL_FAAFO -eq 1 ]]; then
  115. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  116. sudo apt-get install -y python3-dev python3-pip supervisor git zlib1g-dev libmysqlclient-dev python3-mysqldb python-is-python3
  117. # Following is needed because of
  118. # https://bugs.launchpad.net/ubuntu/+source/supervisor/+bug/1594740
  119. if [ $(lsb_release --short --codename) = xenial ]; then
  120. # Make sure the daemon is enabled.
  121. if ! systemctl --quiet is-enabled supervisor; then
  122. systemctl enable supervisor
  123. fi
  124. # Make sure the daemon is started.
  125. if ! systemctl --quiet is-active supervisor; then
  126. systemctl start supervisor
  127. fi
  128. fi
  129. elif [[ $ID = 'fedora' ]]; then
  130. # fedora currently not tested nor supported
  131. sudo dnf install -y python3-devel python3-pip supervisor git zlib-devel mariadb-devel gcc which python3-mysql
  132. sudo systemctl enable supervisord
  133. sudo systemctl start supervisord
  134. #elif [[ $ID = 'opensuse' || $ID = 'sles' ]]; then
  135. # sudo zypper install -y python-devel python-pip
  136. else
  137. echo "error: distribution $ID not supported"
  138. exit 1
  139. fi
  140. # HSFD changed to local repo
  141. git clone https://gogs.informatik.hs-fulda.de/srieger/cloud-computing-msc-ai-examples
  142. cd cloud-computing-msc-ai-examples/faafo
  143. # following line required by bug 1636150
  144. sudo pip3 install --upgrade pbr
  145. # in m1.tiny instance during cloud-init the following pip install can experience OOM kill
  146. # setup swap to prevent that
  147. sudo dd if=/dev/zero of=/swap bs=1M count=512
  148. sudo chmod 600 /swap
  149. sudo mkswap /swap
  150. sudo swapon /swap
  151. sudo pip3 install -r requirements.txt
  152. sudo python3 setup.py install
  153. sudo sed -i -e "s#transport_url = .*#transport_url = $URL_MESSAGING#" /etc/faafo/faafo.conf
  154. sudo sed -i -e "s#database_url = .*#database_url = $URL_DATABASE#" /etc/faafo/faafo.conf
  155. sudo sed -i -e "s#endpoint_url = .*#endpoint_url = $URL_ENDPOINT#" /etc/faafo/faafo.conf
  156. fi
  157. if [[ $RUN_API -eq 1 ]]; then
  158. faafo_api="
  159. [program:faafo_api]
  160. command=$(which faafo-api)
  161. priority=10
  162. startretries=0"
  163. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  164. echo "$faafo_api" | sudo tee -a /etc/supervisor/conf.d/faafo.conf
  165. elif [[ $ID = 'fedora' ]]; then
  166. # fedora currently not tested nor supported
  167. echo "$faafo_api" | sudo tee -a /etc/supervisord.d/faafo.ini
  168. else
  169. echo "error: distribution $ID not supported"
  170. exit 1
  171. fi
  172. fi
  173. if [[ $RUN_WORKER -eq 1 ]]; then
  174. faafo_worker="
  175. [program:faafo_worker]
  176. command=$(which faafo-worker)
  177. priority=20
  178. startretries=0"
  179. if [[ $ID = 'ubuntu' || $ID = 'debian' ]]; then
  180. echo "$faafo_worker" | sudo tee -a /etc/supervisor/conf.d/faafo.conf
  181. elif [[ $ID = 'fedora' ]]; then
  182. # fedora currently not tested nor supported
  183. echo "$faafo_worker" | sudo tee -a /etc/supervisord.d/faafo.ini
  184. else
  185. echo "error: distribution $ID not supported"
  186. exit 1
  187. fi
  188. fi
  189. if [[ $RUN_WORKER -eq 1 || $RUN_API -eq 1 ]]; then
  190. sudo supervisorctl reload
  191. sleep 5
  192. fi
  193. if [[ $RUN_DEMO -eq 1 && $RUN_API -eq 1 ]]; then
  194. faafo --endpoint-url $URL_ENDPOINT --debug create
  195. fi
  196. else
  197. exit 1
  198. fi