installer.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. import subprocess
  2. import os
  3. class Installer:
  4. ############################################################
  5. # install_software
  6. ############################################################
  7. def install_software(self):
  8. self.__install_server_software()
  9. self.__install_client_software()
  10. ############################################################
  11. # End install_software
  12. ############################################################
  13. ############################################################
  14. # __install_server_software
  15. ############################################################
  16. def __install_server_software(self):
  17. #######################################
  18. # Prerequisites
  19. #######################################
  20. self.__run_command("sudo apt-get update", True)
  21. self.__run_command("sudo apt-get upgrade", True)
  22. self.__run_command("sudo apt-get install build-essential libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev python-software-properties unzip git-core libcurl4-openssl-dev libbz2-dev libmysqlclient-dev mongodb-clients libreadline6-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev libgdbm-dev ncurses-dev automake libffi-dev htop libtool bison", True)
  23. self.__run_command("cp ../config/benchmark_profile ../../.bash_profile")
  24. #######################################
  25. # Languages
  26. #######################################
  27. #
  28. # Python
  29. #
  30. self.__run_command("curl http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz | tar xvz")
  31. self.__run_command("./configure", cwd="Python-2.7.3")
  32. self.__run_command("sudo make install", cwd="Python-2.7.3")
  33. self.__run_command("curl http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz | tar xvz")
  34. self.__run_command("sudo python setup.py install", cwd="setuptools-0.6c11")
  35. self.__run_command("curl http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz | tar xvz")
  36. self.__run_command("sudo python setup.py install", cwd="pip-1.1")
  37. self.__run_command("sudo pip install MySQL-python==1.2.4")
  38. self.__run_command("sudo pip install simplejson==3.0.7")
  39. #
  40. # nodejs
  41. #
  42. self.__run_command("curl http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-x64.tar.gz | tar xvz")
  43. #
  44. # Java
  45. #
  46. self.__run_command("sudo apt-get install openjdk-7-jdk", True)
  47. self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
  48. #
  49. # Ruby/JRuby
  50. #
  51. self.__run_command("curl -L get.rvm.io | bash -s head")
  52. self.__run_command("echo rvm_auto_reload_flag=2 >> ~/.rvmrc")
  53. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install 2.0.0-p0"])
  54. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler"])
  55. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.3"])
  56. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do gem install bundler"])
  57. # We need a newer version of jruby-rack
  58. self.__run_command("git clone git://github.com/jruby/jruby-rack.git")
  59. subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do bundle install"])
  60. subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do jruby -S bundle exec rake clean gem SKIP_SPECS=true"])
  61. subprocess.call(["bash", "-c", "cd installs/jruby-rack/target && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do gem install jruby-rack-1.2.0.SNAPSHOT.gem"])
  62. #
  63. # go
  64. #
  65. self.__run_command("curl http://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz | tar xvz")
  66. #
  67. # php
  68. #
  69. self.__run_command("wget --trust-server-names http://www.php.net/get/php-5.4.13.tar.gz/from/us1.php.net/mirror")
  70. self.__run_command("tar xvf php-5.4.13.tar.gz")
  71. self.__run_command("./configure --with-pdo-mysql --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data", cwd="php-5.4.13")
  72. self.__run_command("make", cwd="php-5.4.13")
  73. self.__run_command("sudo make install", cwd="php-5.4.13")
  74. self.__run_command("printf \"\\n\" | sudo pecl install apc-beta", cwd="php-5.4.13")
  75. self.__run_command("sudo cp ../config/php.ini /usr/local/lib/php.ini")
  76. self.__run_command("sudo cp ../config/php-fpm.conf /usr/local/lib/php-fpm.conf")
  77. self.__run_command("rm php-5.4.13.tar.gz")
  78. #
  79. # Haskell
  80. #
  81. self.__run_command("sudo apt-get install ghc cabal-install", True)
  82. #######################################
  83. # Webservers
  84. #######################################
  85. #
  86. # Apache
  87. #
  88. self.__run_command("sudo apt-get install apache2 libapache2-mod-php5", True)
  89. self.__run_command("sudo mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.orig")
  90. self.__run_command("sudo sh -c \"cat ../config/apache2.conf > /etc/apache2/apache2.conf\"")
  91. self.__run_command("sudo mv /etc/apache2/ports.conf /etc/apache2/ports.conf.orig")
  92. self.__run_command("sudo sh -c \"cat ../config/ports.conf > /etc/apache2/ports.conf\"")
  93. self.__run_command("sudo /etc/init.d/apache2 stop")
  94. #
  95. # Nginx
  96. #
  97. self.__run_command("curl http://nginx.org/download/nginx-1.2.7.tar.gz | tar xvz")
  98. self.__run_command("./configure", cwd="nginx-1.2.7")
  99. self.__run_command("make", cwd="nginx-1.2.7")
  100. self.__run_command("sudo make install", cwd="nginx-1.2.7")
  101. #
  102. # Gunicorn
  103. #
  104. self.__run_command("sudo easy_install -U 'gunicorn==0.17.2'")
  105. self.__run_command("sudo easy_install -U 'eventlet==0.12.1'")
  106. self.__run_command("sudo pip install --upgrade 'gevent==0.13.8'")
  107. #
  108. # Resin
  109. #
  110. self.__run_command("sudo cp -r /usr/lib/jvm/java-1.7.0-openjdk-amd64/include /usr/lib/jvm/java-1.7.0-openjdk-amd64/jre/bin/")
  111. self.__run_command("curl http://www.caucho.com/download/resin-4.0.34.tar.gz | tar xvz")
  112. self.__run_command("./configure --prefix=`pwd`", cwd="resin-4.0.34")
  113. self.__run_command("make", cwd="resin-4.0.34")
  114. self.__run_command("make install", cwd="resin-4.0.34")
  115. self.__run_command("mv conf/resin.properties conf/resin.properties.orig", cwd="resin-4.0.34")
  116. self.__run_command("cat ../config/resin.properties > resin-4.0.34/conf/resin.properties")
  117. #
  118. # Passenger
  119. #
  120. self.__run_command("git clone https://github.com/FooBarWidget/passenger.git")
  121. self.__run_command("git checkout 65d36dbbadd399f65d81f5febadce9b0c6c1a430", cwd="passenger")
  122. subprocess.call(["bash", "-c", "cd installs/passenger && source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem build passenger.gemspec"])
  123. subprocess.call(["bash", "-c", "cd installs/passenger && source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install passenger-3.9.5.rc3.gem"])
  124. ##############################
  125. # Tomcat
  126. # We don't use tomcat in our tests yet, but this is here to remind us of how we
  127. # installed the apr connector
  128. ##############################
  129. self.__run_command("curl http://apache.cs.utah.edu/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.tar.gz | tar xvz")
  130. #wget http://apache.cs.utah.edu/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.tar.gz
  131. #tar -xvzf apache-tomcat-7.0.35.tar.gz
  132. #rm apache-tomcat-7.0.35.tar.gz
  133. # use the native APR
  134. # http://evgeny-goldin.com/blog/ubuntu-installing-apr-tomcat/
  135. #wget http://apache.claz.org/apr/apr-1.4.6.tar.gz
  136. #tar xvf apr-1.4.6.tar.gz
  137. #cd apr-1.4.6
  138. #./configure
  139. #make
  140. #sudo make install
  141. #cd ..
  142. #rm apr-1.4.6.tar.gz
  143. #wget http://apache.tradebit.com/pub/tomcat/tomcat-connectors/native/1.1.24/source/tomcat-native-1.1.24-src.tar.gz
  144. #tar xvf tomcat-native-1.1.24-src.tar.gz
  145. #cd tomcat-native-1.1.24-src/jni/native
  146. #./configure --with-apr=/usr/local/apr
  147. #make
  148. #sudo make install
  149. #cd ../../..
  150. #rm tomcat-native-1.1.24-src.tar.gz
  151. ##############################################################
  152. #
  153. # Frameworks
  154. #
  155. ##############################################################
  156. ##############################
  157. # Django
  158. ##############################
  159. self.__run_command("curl http://www.djangoproject.com/m/releases/1.4/Django-1.4.tar.gz | tar xvz")
  160. self.__run_command("sudo rm -rf /usr/local/lib/python2.7/site-packages/django")
  161. self.__run_command("sudo python setup.py install", cwd="Django-1.4")
  162. self.__run_command("sudo easy_install -U 'ujson==1.30'")
  163. ##############################
  164. # Grails
  165. ##############################
  166. self.__run_command("wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.1.zip")
  167. self.__run_command("unzip -o grails-2.1.1.zip")
  168. self.__run_command("rm grails-2.1.1.zip")
  169. ##############################
  170. # Flask
  171. ##############################
  172. self.__run_command("sudo pip install flask flask-sqlalchemy")
  173. ##############################
  174. # Play
  175. ##############################
  176. self.__run_command("wget http://downloads.typesafe.com/play/2.1.0/play-2.1.0.zip")
  177. self.__run_command("unzip -o play-2.1.0.zip")
  178. self.__run_command("rm play-2.1.0.zip")
  179. ##############################
  180. # Vert.x
  181. ##############################
  182. self.__run_command("curl http://vertx.io/downloads/vert.x-1.3.1.final.tar.gz | tar xvz")
  183. ##############################
  184. # WebGO
  185. ##############################
  186. self.__run_command("go/bin/go get github.com/hoisie/web")
  187. ##############################
  188. # Yesod
  189. ##############################
  190. self.__run_command("cabal update")
  191. self.__run_command("cabal install yesod persistent-mysql")
  192. ##############################################################
  193. #
  194. # System Tools
  195. #
  196. ##############################################################
  197. ##############################
  198. # Maven
  199. ##############################
  200. self.__run_command("sudo apt-get install maven2", send_yes=True)
  201. ##############################
  202. # Leiningen
  203. ##############################
  204. self.__run_command("mkdir -p bin")
  205. self.__run_command("wget https://raw.github.com/technomancy/leiningen/stable/bin/lein")
  206. self.__run_command("mv lein bin/lein")
  207. self.__run_command("chmod +x bin/lein")
  208. ############################################################
  209. # End __install_server_software
  210. ############################################################
  211. ############################################################
  212. # __install_client_software
  213. ############################################################
  214. def __install_client_software(self):
  215. subprocess.call(self.benchmarker.sftp_string(batch_file="config/client_sftp_batch"), shell=True)
  216. remote_script = """
  217. ##############################
  218. # Prerequisites
  219. ##############################
  220. yes | sudo apt-get update
  221. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev
  222. ##############################
  223. # MySQL
  224. ##############################
  225. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  226. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  227. yes | sudo apt-get install mysql-server
  228. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  229. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  230. sudo mv my.cnf /etc/mysql/my.cnf
  231. sudo restart mysql
  232. # Insert data
  233. mysql -uroot -psecret < create.sql
  234. ##############################
  235. # Weighttp
  236. ##############################
  237. git clone git://git.lighttpd.net/weighttp
  238. cd weighttp
  239. ./waf configure
  240. ./waf build
  241. sudo ./waf install
  242. cd ~
  243. ##############################
  244. # wrk
  245. ##############################
  246. git clone https://github.com/wg/wrk.git
  247. cd wrk
  248. make
  249. sudo cp wrk /usr/local/bin
  250. cd ~
  251. ##############################
  252. # MongoDB
  253. ##############################
  254. yes | sudo apt-get install mongodb
  255. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  256. sudo mv mongodb.conf /etc/mongodb.conf
  257. sudo restart mongodb
  258. """
  259. p = subprocess.Popen(self.benchmarker.ssh_string.split(" "), stdin=subprocess.PIPE)
  260. p.communicate(remote_script)
  261. ############################################################
  262. # End __parse_results
  263. ############################################################
  264. ############################################################
  265. # __run_command
  266. ############################################################
  267. def __run_command(self, command, send_yes=False, cwd=None):
  268. try:
  269. cwd = os.path.join(self.install_dir, cwd)
  270. except AttributeError:
  271. cwd = self.install_dir
  272. if send_yes:
  273. subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd).communicate("yes")
  274. else:
  275. subprocess.call(command, shell=True, cwd=cwd)
  276. ############################################################
  277. # End __run_command
  278. ############################################################
  279. ############################################################
  280. # __init__(benchmarker)
  281. ############################################################
  282. def __init__(self, benchmarker):
  283. self.benchmarker = benchmarker
  284. self.install_dir = "installs"
  285. try:
  286. os.mkdir(self.install_dir)
  287. except OSError:
  288. pass
  289. ############################################################
  290. # End __init__
  291. ############################################################