installer.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. import subprocess
  2. import os
  3. import time
  4. import traceback
  5. import sys
  6. class Installer:
  7. ############################################################
  8. # install_software
  9. ############################################################
  10. def install_software(self):
  11. if self.benchmarker.install == 'all' or self.benchmarker.install == 'server':
  12. self.__install_server_software()
  13. if self.benchmarker.install == 'all' or self.benchmarker.install == 'client':
  14. self.__install_client_software()
  15. ############################################################
  16. # End install_software
  17. ############################################################
  18. ############################################################
  19. # __install_server_software
  20. ############################################################
  21. def __install_server_software(self):
  22. print("\nINSTALL: Installing server software\n")
  23. #######################################
  24. # Prerequisites
  25. #######################################
  26. self.__run_command("sudo apt-get update", True)
  27. self.__run_command("sudo apt-get upgrade", True)
  28. 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 libevent-dev libgstreamer-plugins-base0.10-0 libgstreamer0.10-0 liborc-0.4-0 libwxbase2.8-0 libwxgtk2.8-0 libgnutls-dev libjson0-dev libmcrypt-dev libicu-dev cmake gettext curl libpq-dev mercurial", True)
  29. self.__run_command("sudo add-apt-repository ppa:ubuntu-toolchain-r/test", True)
  30. self.__run_command("sudo apt-get update", True)
  31. self.__run_command("sudo apt-get install gcc-4.8 g++-4.8", True)
  32. self.__run_command("cp ../config/benchmark_profile ../../.bash_profile")
  33. self.__run_command("sudo sh -c \"echo '* - nofile 16384' >> /etc/security/limits.conf\"")
  34. ##############################################################
  35. # System Tools
  36. ##############################################################
  37. #
  38. # Leiningen
  39. #
  40. self.__run_command("mkdir -p bin")
  41. self.__download("https://raw.github.com/technomancy/leiningen/stable/bin/lein")
  42. self.__run_command("mv lein bin/lein")
  43. self.__run_command("chmod +x bin/lein")
  44. #
  45. # Maven
  46. #
  47. self.__run_command("sudo apt-get install maven -qq")
  48. self.__run_command("mvn -version")
  49. #######################################
  50. # Languages
  51. #######################################
  52. self._install_python()
  53. #
  54. # Dart
  55. #
  56. self.__download("https://storage.googleapis.com/dart-editor-archive-integration/latest/dartsdk-linux-64.tar.gz")
  57. self.__run_command("tar xzf dartsdk-linux-64.tar.gz")
  58. #
  59. # Erlang
  60. #
  61. self.__run_command("sudo cp ../config/erlang.list /etc/apt/sources.list.d/erlang.list")
  62. self.__download("http://binaries.erlang-solutions.com/debian/erlang_solutions.asc")
  63. self.__run_command("sudo apt-key add erlang_solutions.asc")
  64. self.__run_command("sudo apt-get update")
  65. self.__run_command("sudo apt-get install esl-erlang", True)
  66. #
  67. # nodejs
  68. #
  69. self.__download("http://nodejs.org/dist/v0.10.8/node-v0.10.8-linux-x64.tar.gz")
  70. self.__run_command("tar xzf node-v0.10.8-linux-x64.tar.gz")
  71. #
  72. # Java
  73. #
  74. self.__run_command("sudo apt-get install openjdk-7-jdk", True)
  75. self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
  76. #
  77. # Ruby/JRuby
  78. #
  79. self.__run_command("curl -L get.rvm.io | bash -s head")
  80. self.__run_command("echo rvm_auto_reload_flag=2 >> ~/.rvmrc")
  81. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm install 2.0.0-p0")
  82. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler")
  83. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.4")
  84. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do gem install bundler")
  85. # We need a newer version of jruby-rack
  86. self.__run_command("git clone git://github.com/jruby/jruby-rack.git", retry=True);
  87. self.__bash_from_string("cd jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do bundle install")
  88. self.__bash_from_string("cd jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do jruby -S bundle exec rake clean gem SKIP_SPECS=true")
  89. self.__bash_from_string("cd jruby-rack/target && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do gem install jruby-rack-1.2.0.SNAPSHOT.gem")
  90. #
  91. # go
  92. #
  93. self.__download("http://go.googlecode.com/files/go1.1.1.linux-amd64.tar.gz");
  94. self.__run_command("tar xzf go1.1.1.linux-amd64.tar.gz")
  95. #
  96. # Perl
  97. #
  98. self.__download("http://downloads.activestate.com/ActivePerl/releases/5.16.3.1603/ActivePerl-5.16.3.1603-x86_64-linux-glibc-2.3.5-296746.tar.gz");
  99. self.__run_command("tar xzf ActivePerl-5.16.3.1603-x86_64-linux-glibc-2.3.5-296746.tar.gz");
  100. self.__run_command("sudo ./install.sh --license-accepted --prefix /opt/ActivePerl-5.16 --no-install-html", cwd="ActivePerl-5.16.3.1603-x86_64-linux-glibc-2.3.5-296746", send_yes=True)
  101. self.__download("http://cpanmin.us", "cpanminus.pl")
  102. self.__run_command("perl cpanminus.pl --sudo App::cpanminus")
  103. self.__run_command("cpanm -f -S DBI DBD::mysql Kelp Dancer Mojolicious Kelp::Module::JSON::XS Dancer::Plugin::Database Starman Plack JSON Web::Simple DBD::Pg JSON::XS EV HTTP::Parser::XS Monoceros EV IO::Socket::IP IO::Socket::SSL")
  104. #
  105. # php
  106. #
  107. self.__download("http://www.php.net/get/php-5.4.13.tar.gz/from/us1.php.net/mirror")
  108. self.__run_command("tar xzf php-5.4.13.tar.gz")
  109. self.__run_command("./configure --with-pdo-mysql --with-mysql --with-mcrypt --enable-intl --enable-mbstring --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-openssl", cwd="php-5.4.13")
  110. self.__run_command("make", cwd="php-5.4.13")
  111. self.__run_command("sudo make install", cwd="php-5.4.13")
  112. self.__run_command("printf \"\\n\" | sudo pecl install apc-beta", cwd="php-5.4.13")
  113. self.__run_command("sudo cp ../config/php.ini /usr/local/lib/php.ini")
  114. self.__run_command("sudo cp ../config/php-fpm.conf /usr/local/lib/php-fpm.conf")
  115. self.__run_command("rm php-5.4.13.tar.gz")
  116. # Composer
  117. self.__download("https://getcomposer.org/installer", "composer-installer.php")
  118. self.__run_command("php composer-installer.php --install-dir=bin")
  119. # Phalcon
  120. self.__run_command("git clone git://github.com/phalcon/cphalcon.git", retry=True)
  121. self.__run_command("sudo ./install", cwd="cphalcon/build")
  122. # YAF
  123. self.__run_command("sudo pecl install yaf")
  124. #
  125. # Haskell
  126. #
  127. self.__run_command("sudo apt-get install ghc cabal-install", True)
  128. #
  129. # RingoJs
  130. #
  131. self.__download("http://www.ringojs.org/downloads/ringojs_0.9-1_all.deb")
  132. self.__run_command("sudo apt-get install jsvc", True)
  133. self.__run_command("sudo dpkg -i ringojs_0.9-1_all.deb", True)
  134. self.__run_command("rm ringojs_0.9-1_all.deb")
  135. #
  136. # Mono
  137. #
  138. self.__run_command("git clone git://github.com/mono/mono", retry=True)
  139. self.__run_command("git checkout mono-3.2.1", cwd="mono")
  140. self.__run_command("./autogen.sh --prefix=/usr/local", cwd="mono")
  141. self.__run_command("make get-monolite-latest", cwd="mono")
  142. self.__run_command("make EXTERNAL_MCS=${PWD}/mcs/class/lib/monolite/gmcs.exe", cwd="mono")
  143. self.__run_command("sudo make install", cwd="mono")
  144. self.__run_command("mozroots --import --sync", retry=True)
  145. self.__run_command("git clone git://github.com/mono/xsp", retry=True)
  146. self.__run_command("./autogen.sh --prefix=/usr/local", cwd="xsp")
  147. self.__run_command("make", cwd="xsp")
  148. self.__run_command("sudo make install", cwd="xsp")
  149. #
  150. # Nimrod
  151. #
  152. self.__download("http://www.nimrod-code.org/download/nimrod_0.9.2.zip")
  153. self.__run_command("unzip nimrod_0.9.2.zip")
  154. self.__run_command("chmod +x build.sh", cwd="nimrod")
  155. self.__run_command("./build.sh", cwd="nimrod")
  156. self.__run_command("chmod +x install.sh", cwd="nimrod")
  157. self.__run_command("sudo ./install.sh /usr/bin", cwd="nimrod")
  158. #######################################
  159. # Webservers
  160. #######################################
  161. #
  162. # Nginx
  163. #
  164. self.__download("http://nginx.org/download/nginx-1.4.1.tar.gz")
  165. self.__run_command("tar xzf nginx-1.4.1.tar.gz")
  166. self.__run_command("./configure", cwd="nginx-1.4.1")
  167. self.__run_command("make", cwd="nginx-1.4.1")
  168. self.__run_command("sudo make install", cwd="nginx-1.4.1")
  169. #
  170. # Openresty (nginx with openresty stuff)
  171. #
  172. self.__download("http://openresty.org/download/ngx_openresty-1.2.7.5.tar.gz")
  173. self.__run_command("tar xzf ngx_openresty-1.2.7.5.tar.gz")
  174. self.__run_command("./configure --with-luajit", cwd="ngx_openresty-1.2.7.5")
  175. self.__run_command("make", cwd="ngx_openresty-1.2.7.5")
  176. self.__run_command("sudo make install", cwd="ngx_openresty-1.2.7.5")
  177. #
  178. # Resin
  179. #
  180. 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/")
  181. self.__download("http://www.caucho.com/download/resin-4.0.36.tar.gz")
  182. self.__run_command("tar xzf resin-4.0.36.tar.gz")
  183. self.__run_command("./configure --prefix=`pwd`", cwd="resin-4.0.36")
  184. self.__run_command("make", cwd="resin-4.0.36")
  185. self.__run_command("make install", cwd="resin-4.0.36")
  186. self.__run_command("mv conf/resin.properties conf/resin.properties.orig", cwd="resin-4.0.36")
  187. self.__run_command("cat ../config/resin.properties > resin-4.0.36/conf/resin.properties")
  188. self.__run_command("mv conf/resin.xml conf/resin.xml.orig", cwd="resin-4.0.36")
  189. self.__run_command("cat ../config/resin.xml > resin-4.0.36/conf/resin.xml")
  190. ##############################################################
  191. # Frameworks
  192. ##############################################################
  193. #
  194. # Grails
  195. #
  196. self.__download("http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.1.zip")
  197. self.__run_command("unzip -o grails-2.1.1.zip")
  198. self.__run_command("rm grails-2.1.1.zip")
  199. #
  200. # Play 2
  201. #
  202. self.__download("http://downloads.typesafe.com/play/2.1.2-RC1/play-2.1.2-RC1.zip")
  203. self.__run_command("unzip -o play-2.1.2-RC1.zip")
  204. self.__run_command("rm play-2.1.2-RC1.zip")
  205. #
  206. # Play 1
  207. #
  208. self.__download("http://downloads.typesafe.com/releases/play-1.2.5.zip")
  209. self.__run_command("unzip -o play-1.2.5.zip")
  210. self.__run_command("rm play-1.2.5.zip")
  211. self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
  212. # siena
  213. self.__run_command("yes | play-1.2.5/play1 install siena")
  214. #
  215. # TreeFrog Framework
  216. #
  217. self.__run_command("sudo apt-get install qt4-qmake libqt4-dev libqt4-sql-mysql g++", True)
  218. self.__download("http://downloads.sourceforge.net/project/treefrog/src/treefrog-1.6.tar.gz")
  219. self.__run_command("tar xzf treefrog-1.6.tar.gz")
  220. self.__run_command("rm treefrog-1.6.tar.gz")
  221. self.__run_command("./configure --enable-mongo", cwd="treefrog-1.6")
  222. self.__run_command("make", cwd="treefrog-1.6/src")
  223. self.__run_command("sudo make install", cwd="treefrog-1.6/src")
  224. self.__run_command("make", cwd="treefrog-1.6/tools")
  225. self.__run_command("sudo make install", cwd="treefrog-1.6/tools")
  226. #
  227. # Vert.x
  228. #
  229. self.__download("http://vertx.io/vertx-downloads/downloads/vert.x-1.3.1.final.tar.gz")
  230. self.__run_command("tar xzf vert.x-1.3.1.final.tar.gz")
  231. #
  232. # Yesod
  233. #
  234. self.__run_command("cabal update")
  235. self.__run_command("cabal install yesod persistent-mysql")
  236. #
  237. # Jester
  238. #
  239. self.__run_command("git clone git://github.com/dom96/jester.git jester/jester", retry=True)
  240. print("\nINSTALL: Finished installing server software\n")
  241. ############################################################
  242. # End __install_server_software
  243. ############################################################
  244. def _install_python(self):
  245. # .profile is not loaded yet. So we should use full path.
  246. pypy_bin = "~/FrameworkBenchmarks/installs/pypy/bin"
  247. python_bin = "~/FrameworkBenchmarks/installs/py2/bin"
  248. python3_bin= "~/FrameworkBenchmarks/installs/py3/bin"
  249. def easy_install(pkg, two=True, three=False, pypy=False):
  250. cmd = "/easy_install -ZU '" + pkg + "'"
  251. if two: self.__run_command(python_bin + cmd)
  252. if three: self.__run_command(python3_bin + cmd)
  253. if pypy: self.__run_command(pypy_bin + cmd)
  254. self.__download("http://bitbucket.org/pypy/pypy/downloads/pypy-2.1-linux64.tar.bz2")
  255. self.__run_command("tar xjf pypy-2.1-linux64.tar.bz2")
  256. self.__run_command('ln -sf pypy-2.1 pypy')
  257. self.__download("http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz")
  258. self.__run_command("tar xzf Python-2.7.5.tgz")
  259. self.__download("http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tar.xz")
  260. self.__run_command("tar xJf Python-3.3.2.tar.xz")
  261. self.__run_command("./configure --prefix=$HOME/FrameworkBenchmarks/installs/py2 --disable-shared CC=gcc-4.8", cwd="Python-2.7.5")
  262. self.__run_command("./configure --prefix=$HOME/FrameworkBenchmarks/installs/py3 --disable-shared CC=gcc-4.8", cwd="Python-3.3.2")
  263. self.__run_command("make -j2", cwd="Python-2.7.5")
  264. self.__run_command("make install", cwd="Python-2.7.5")
  265. self.__run_command("make -j2", cwd="Python-3.3.2")
  266. self.__run_command("make install", cwd="Python-3.3.2")
  267. self.__download("https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py")
  268. self.__run_command(pypy_bin + "/pypy ez_setup.py")
  269. self.__run_command(python_bin + "/python ez_setup.py")
  270. self.__run_command(python3_bin + "/python3 ez_setup.py")
  271. easy_install('pip==1.4.1', two=True, three=True, pypy=True)
  272. easy_install('MySQL-python==1.2.4', two=True, three=False, pypy=True)
  273. easy_install('https://github.com/clelland/MySQL-for-Python-3/archive/master.zip', two=False, three=True, pypy=False)
  274. easy_install('PyMySQL==0.5', pypy=True)
  275. easy_install('PyMySQL3==0.5', two=False, three=True)
  276. easy_install('psycopg2==2.5.1', three=True)
  277. easy_install('simplejson==3.3.0', two=True, three=True, pypy=False)
  278. easy_install('ujson==1.33', three=True)
  279. easy_install('https://github.com/downloads/surfly/gevent/gevent-1.0rc2.tar.gz', three=True)
  280. easy_install('uwsgi', three=True) # uwsgi is released too often to stick on single version.
  281. # Gunicorn
  282. easy_install('gunicorn==17.5', two=True, three=True, pypy=True)
  283. # meinheld HEAD supports gunicorn worker on Python 3
  284. easy_install('https://github.com/mopemope/meinheld/archive/master.zip', two=True, three=True, pypy=True)
  285. # Tornado
  286. easy_install('tornado==3.1', two=True, three=True, pypy=True)
  287. easy_install('motor==0.1.1', two=True, three=True, pypy=True)
  288. easy_install('pymongo==2.5.2', two=True, three=True, pypy=True)
  289. # Django
  290. easy_install("https://www.djangoproject.com/download/1.6b2/tarball/", two=True, three=True, pypy=True)
  291. # Flask
  292. easy_install('Werkzeug==0.9.3', two=True, three=True, pypy=True)
  293. easy_install('flask==0.10.1', two=True, three=True, pypy=True)
  294. easy_install('sqlalchemy==0.8.2', two=True, three=True, pypy=True)
  295. easy_install('Jinja2==2.7', two=True, three=True, pypy=True)
  296. easy_install('Flask-SQLAlchemy==1.0', two=True, three=True, pypy=True)
  297. # Bottle
  298. easy_install('bottle==0.11.6', two=True, three=True, pypy=True)
  299. easy_install('bottle-sqlalchemy==0.4', two=True, three=True, pypy=True)
  300. ############################################################
  301. # __install_error
  302. ############################################################
  303. def __install_error(self, message):
  304. print("\nINSTALL ERROR: %s\n" % message)
  305. if self.benchmarker.install_error_action == 'abort':
  306. sys.exit("Installation aborted.")
  307. ############################################################
  308. # End __install_error
  309. ############################################################
  310. ############################################################
  311. # __install_client_software
  312. ############################################################
  313. def __install_client_software(self):
  314. print("\nINSTALL: Installing client software\n")
  315. self.__run_command("cd .. && " + self.benchmarker.sftp_string(batch_file="config/client_sftp_batch"), True)
  316. remote_script = """
  317. ##############################
  318. # Prerequisites
  319. ##############################
  320. yes | sudo apt-get update
  321. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev postgresql
  322. sudo sh -c "echo '* - nofile 16384' >> /etc/security/limits.conf"
  323. sudo mkdir -p /ssd
  324. sudo mkdir -p /ssd/log
  325. ##############################
  326. # MySQL
  327. ##############################
  328. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  329. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  330. yes | sudo apt-get install mysql-server
  331. sudo stop mysql
  332. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  333. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  334. sudo mv my.cnf /etc/mysql/my.cnf
  335. sudo cp -R -p /var/lib/mysql /ssd/
  336. sudo cp -R -p /var/log/mysql /ssd/log
  337. sudo cp usr.sbin.mysqld /etc/apparmor.d/
  338. sudo /etc/init.d/apparmor reload
  339. sudo start mysql
  340. # Insert data
  341. mysql -uroot -psecret < create.sql
  342. ##############################
  343. # Postgres
  344. ##############################
  345. sudo useradd benchmarkdbuser -p benchmarkdbpass
  346. sudo -u postgres psql template1 < create-postgres-database.sql
  347. sudo -u benchmarkdbuser psql hello_world < create-postgres.sql
  348. sudo -u postgres -H /etc/init.d/postgresql stop
  349. sudo mv postgresql.conf /etc/postgresql/9.1/main/postgresql.conf
  350. sudo mv pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf
  351. sudo cp -R -p /var/lib/postgresql/9.1/main /ssd/postgresql
  352. sudo -u postgres -H /etc/init.d/postgresql start
  353. sudo mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  354. ##############################
  355. # wrk
  356. ##############################
  357. git clone https://github.com/wg/wrk.git
  358. cd wrk
  359. make
  360. sudo cp wrk /usr/local/bin
  361. cd ~
  362. git clone https://github.com/wg/wrk.git wrk-pipeline
  363. cd wrk-pipeline
  364. git checkout pipeline
  365. make
  366. sudo cp wrk /usr/local/bin/wrk-pipeline
  367. cd ~
  368. ##############################
  369. # MongoDB
  370. ##############################
  371. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  372. sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
  373. sudo apt-get update
  374. yes | sudo apt-get install mongodb-10gen
  375. sudo stop mongodb
  376. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  377. sudo mv mongodb.conf /etc/mongodb.conf
  378. sudo cp -R -p /var/lib/mongodb /ssd/
  379. sudo cp -R -p /var/log/mongodb /ssd/log/
  380. sudo start mongodb
  381. """
  382. print("\nINSTALL: %s" % self.benchmarker.ssh_string)
  383. p = subprocess.Popen(self.benchmarker.ssh_string.split(" "), stdin=subprocess.PIPE)
  384. p.communicate(remote_script)
  385. returncode = p.returncode
  386. if returncode != 0:
  387. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.ssh_string))
  388. print("\nINSTALL: Finished installing client software\n")
  389. ############################################################
  390. # End __install_client_software
  391. ############################################################
  392. ############################################################
  393. # __run_command
  394. ############################################################
  395. def __run_command(self, command, send_yes=False, cwd=None, retry=False):
  396. try:
  397. cwd = os.path.join(self.install_dir, cwd)
  398. except AttributeError:
  399. cwd = self.install_dir
  400. if retry:
  401. max_attempts = 5
  402. else:
  403. max_attempts = 1
  404. attempt = 1
  405. delay = 0
  406. print("\nINSTALL: %s (cwd=%s)" % (command, cwd))
  407. while True:
  408. error_message = ""
  409. try:
  410. # Execute command.
  411. if send_yes:
  412. process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd)
  413. process.communicate("yes")
  414. returncode = process.returncode
  415. if returncode:
  416. raise subprocess.CalledProcessError(returncode, command)
  417. else:
  418. subprocess.check_call(command, shell=True, cwd=cwd)
  419. break # Exit loop if successful.
  420. except:
  421. exceptionType, exceptionValue, exceptionTraceBack = sys.exc_info()
  422. error_message = "".join(traceback.format_exception_only(exceptionType, exceptionValue))
  423. print error_message
  424. # Exit if there are no more attempts left.
  425. attempt += 1
  426. if attempt > max_attempts:
  427. break
  428. # Delay before next attempt.
  429. if delay == 0:
  430. delay = 5
  431. else:
  432. delay = delay * 2
  433. print("Attempt %s/%s starting in %s seconds." % (attempt, max_attempts, delay))
  434. time.sleep(delay)
  435. if error_message:
  436. self.__install_error(error_message)
  437. ############################################################
  438. # End __run_command
  439. ############################################################
  440. ############################################################
  441. # __bash_from_string
  442. # Runs bash -c "command" in install_dir.
  443. ############################################################
  444. def __bash_from_string(self, command):
  445. self.__run_command('bash -c "%s"' % command)
  446. ############################################################
  447. # End __bash_from_string
  448. ############################################################
  449. ############################################################
  450. # __download
  451. # Downloads a file from a URI.
  452. ############################################################
  453. def __download(self, uri, filename=""):
  454. if filename:
  455. filename_option = "-O %s " % filename
  456. else:
  457. filename_option = ""
  458. command = "wget -nv --no-check-certificate --trust-server-names %s%s" % (filename_option, uri)
  459. self.__run_command(command, retry=True)
  460. ############################################################
  461. # End __download
  462. ############################################################
  463. ############################################################
  464. # __init__(benchmarker)
  465. ############################################################
  466. def __init__(self, benchmarker):
  467. self.benchmarker = benchmarker
  468. self.install_dir = "installs"
  469. try:
  470. os.mkdir(self.install_dir)
  471. except OSError:
  472. pass
  473. ############################################################
  474. # End __init__
  475. ############################################################
  476. # vim: sw=2