installer.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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 == 'database':
  14. self.__install_database_software()
  15. if self.benchmarker.install == 'all' or self.benchmarker.install == 'client':
  16. self.__install_client_software()
  17. ############################################################
  18. # End install_software
  19. ############################################################
  20. ############################################################
  21. # __install_server_software
  22. ############################################################
  23. def __install_server_software(self):
  24. print("\nINSTALL: Installing server software\n")
  25. #######################################
  26. # Prerequisites
  27. #######################################
  28. self.__run_command("sudo apt-get update", True)
  29. self.__run_command("sudo apt-get upgrade", True)
  30. 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 mlton", True)
  31. self.__run_command("sudo add-apt-repository ppa:ubuntu-toolchain-r/test", True)
  32. self.__run_command("sudo apt-get update", True)
  33. self.__run_command("sudo apt-get install gcc-4.8 g++-4.8", True)
  34. self.__run_command("cp ../config/benchmark_profile ../../.bash_profile")
  35. self.__run_command("cat ../config/benchmark_profile >> ../../.profile")
  36. self.__run_command("cat ../config/benchmark_profile >> ../../.bashrc")
  37. self.__run_command("source ../../.profile")
  38. self.__run_command("sudo sh -c \"echo '* - nofile 65535' >> /etc/security/limits.conf\"")
  39. ##############################################################
  40. # System Tools
  41. ##############################################################
  42. #
  43. # Leiningen
  44. #
  45. self.__run_command("mkdir -p bin")
  46. self.__download("https://raw.github.com/technomancy/leiningen/stable/bin/lein")
  47. self.__run_command("mv lein bin/lein")
  48. self.__run_command("chmod +x bin/lein")
  49. #
  50. # Maven
  51. #
  52. self.__run_command("sudo apt-get install maven -qq")
  53. self.__run_command("mvn -version")
  54. #######################################
  55. # Languages
  56. #######################################
  57. self._install_python()
  58. #
  59. # Dart
  60. #
  61. self.__download("https://storage.googleapis.com/dart-editor-archive-integration/latest/dartsdk-linux-64.tar.gz")
  62. self.__run_command("tar xzf dartsdk-linux-64.tar.gz")
  63. #
  64. # Erlang
  65. #
  66. self.__run_command("sudo cp ../config/erlang.list /etc/apt/sources.list.d/erlang.list")
  67. self.__download("http://binaries.erlang-solutions.com/debian/erlang_solutions.asc")
  68. self.__run_command("sudo apt-key add erlang_solutions.asc")
  69. self.__run_command("sudo apt-get update")
  70. self.__run_command("sudo apt-get install esl-erlang", True)
  71. #
  72. # nodejs
  73. #
  74. self.__download("http://nodejs.org/dist/v0.10.8/node-v0.10.8-linux-x64.tar.gz")
  75. self.__run_command("tar xzf node-v0.10.8-linux-x64.tar.gz")
  76. #
  77. # Java
  78. #
  79. self.__run_command("sudo apt-get install openjdk-7-jdk", True)
  80. self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
  81. #
  82. # Ruby/JRuby
  83. #
  84. self.__run_command("curl -L get.rvm.io | bash -s head")
  85. self.__run_command("echo rvm_auto_reload_flag=2 >> ~/.rvmrc")
  86. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm install 2.0.0-p0")
  87. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler")
  88. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.8")
  89. self.__bash_from_string("source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.8 do gem install bundler")
  90. #
  91. # go
  92. #
  93. self.__download("http://go.googlecode.com/files/go1.2rc3.linux-amd64.tar.gz");
  94. self.__run_command("tar xzf go1.2rc3.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, retry=True)
  101. self.__download("http://cpanmin.us", "cpanminus.pl")
  102. self.__run_command("perl cpanminus.pl --sudo App::cpanminus", retry=True)
  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", retry=True)
  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", retry=True)
  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.3", 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. # Racket
  160. #
  161. self.__run_command("sudo apt-get install racket", True)
  162. #
  163. # Ur/Web
  164. #
  165. self.__download("http://www.impredicative.com/ur/urweb-20130421.tgz")
  166. self.__run_command("tar xzf urweb-20130421.tgz")
  167. self.__run_command("./configure", cwd="urweb-20130421")
  168. self.__run_command("make", cwd="urweb-20130421")
  169. self.__run_command("sudo make install", cwd="urweb-20130421")
  170. #######################################
  171. # Webservers
  172. #######################################
  173. #
  174. # Nginx
  175. #
  176. self.__download("http://nginx.org/download/nginx-1.4.1.tar.gz")
  177. self.__run_command("tar xzf nginx-1.4.1.tar.gz")
  178. self.__run_command("./configure", cwd="nginx-1.4.1")
  179. self.__run_command("make", cwd="nginx-1.4.1")
  180. self.__run_command("sudo make install", cwd="nginx-1.4.1")
  181. #
  182. # Openresty (nginx with openresty stuff)
  183. #
  184. self.__download("http://openresty.org/download/ngx_openresty-1.2.7.5.tar.gz")
  185. self.__run_command("tar xzf ngx_openresty-1.2.7.5.tar.gz")
  186. self.__run_command("./configure --with-luajit --with-http_postgres_module", cwd="ngx_openresty-1.2.7.5")
  187. self.__run_command("make", cwd="ngx_openresty-1.2.7.5")
  188. self.__run_command("sudo make install", cwd="ngx_openresty-1.2.7.5")
  189. #
  190. # Resin
  191. #
  192. 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/")
  193. self.__download("http://www.caucho.com/download/resin-4.0.36.tar.gz")
  194. self.__run_command("tar xzf resin-4.0.36.tar.gz")
  195. self.__run_command("./configure --prefix=`pwd`", cwd="resin-4.0.36")
  196. self.__run_command("make", cwd="resin-4.0.36")
  197. self.__run_command("make install", cwd="resin-4.0.36")
  198. self.__run_command("mv conf/resin.properties conf/resin.properties.orig", cwd="resin-4.0.36")
  199. self.__run_command("cat ../config/resin.properties > resin-4.0.36/conf/resin.properties")
  200. self.__run_command("mv conf/resin.xml conf/resin.xml.orig", cwd="resin-4.0.36")
  201. self.__run_command("cat ../config/resin.xml > resin-4.0.36/conf/resin.xml")
  202. ##############################################################
  203. # Frameworks
  204. ##############################################################
  205. #
  206. # Grails
  207. #
  208. self.__download("http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.3.3.zip")
  209. self.__run_command("unzip -o grails-2.3.3.zip")
  210. self.__run_command("rm grails-2.3.3.zip")
  211. #
  212. # Play 2
  213. #
  214. self.__download("http://downloads.typesafe.com/play/2.2.0/play-2.2.0.zip")
  215. self.__run_command("unzip -o play-2.2.0.zip")
  216. self.__run_command("rm play-2.2.0.zip")
  217. #
  218. # Play 1
  219. #
  220. self.__download("http://downloads.typesafe.com/releases/play-1.2.5.zip")
  221. self.__run_command("unzip -o play-1.2.5.zip")
  222. self.__run_command("rm play-1.2.5.zip")
  223. self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
  224. # siena
  225. self.__run_command("yes | play-1.2.5/play1 install siena")
  226. #
  227. # TreeFrog Framework
  228. #
  229. self.__run_command("sudo apt-get install qt4-qmake libqt4-dev libqt4-sql-mysql g++", True)
  230. self.__download("http://downloads.sourceforge.net/project/treefrog/src/treefrog-1.7.2.tar.gz")
  231. self.__run_command("tar xzf treefrog-1.7.2.tar.gz")
  232. self.__run_command("rm treefrog-1.7.2.tar.gz")
  233. self.__run_command("./configure", cwd="treefrog-1.7.2")
  234. self.__run_command("make", cwd="treefrog-1.7.2/src")
  235. self.__run_command("sudo make install", cwd="treefrog-1.7.2/src")
  236. self.__run_command("make", cwd="treefrog-1.7.2/tools")
  237. self.__run_command("sudo make install", cwd="treefrog-1.7.2/tools")
  238. #
  239. # Vert.x
  240. #
  241. self.__download("http://dl.bintray.com/vertx/downloads/vert.x-2.1M2.tar.gz?direct=true", "vert.x-2.1M2.tar.gz")
  242. self.__run_command("tar xzf vert.x-2.1M2.tar.gz")
  243. #
  244. # Yesod
  245. #
  246. self.__run_command("cabal update", retry=True)
  247. self.__run_command("cabal install yesod persistent-mysql", retry=True)
  248. #
  249. # Jester
  250. #
  251. self.__run_command("git clone git://github.com/dom96/jester.git jester/jester", retry=True)
  252. print("\nINSTALL: Finished installing server software\n")
  253. ############################################################
  254. # End __install_server_software
  255. ############################################################
  256. def _install_python(self):
  257. # .profile is not loaded yet. So we should use full path.
  258. pypy_bin = "~/FrameworkBenchmarks/installs/pypy/bin"
  259. python_bin = "~/FrameworkBenchmarks/installs/py2/bin"
  260. python3_bin= "~/FrameworkBenchmarks/installs/py3/bin"
  261. def easy_install(pkg, two=True, three=False, pypy=False):
  262. cmd = "/easy_install -ZU '" + pkg + "'"
  263. if two: self.__run_command(python_bin + cmd, retry=True)
  264. if three: self.__run_command(python3_bin + cmd, retry=True)
  265. if pypy: self.__run_command(pypy_bin + cmd, retry=True)
  266. self.__download("http://bitbucket.org/pypy/pypy/downloads/pypy-2.1-linux64.tar.bz2")
  267. self.__run_command("tar xjf pypy-2.1-linux64.tar.bz2")
  268. self.__run_command('ln -sf pypy-2.1 pypy')
  269. self.__download("http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz")
  270. self.__run_command("tar xzf Python-2.7.5.tgz")
  271. self.__download("http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tar.xz")
  272. self.__run_command("tar xJf Python-3.3.2.tar.xz")
  273. self.__run_command("./configure --prefix=$HOME/FrameworkBenchmarks/installs/py2 --disable-shared CC=gcc-4.8", cwd="Python-2.7.5")
  274. self.__run_command("./configure --prefix=$HOME/FrameworkBenchmarks/installs/py3 --disable-shared CC=gcc-4.8", cwd="Python-3.3.2")
  275. self.__run_command("make -j2", cwd="Python-2.7.5")
  276. self.__run_command("make install", cwd="Python-2.7.5")
  277. self.__run_command("make -j2", cwd="Python-3.3.2")
  278. self.__run_command("make install", cwd="Python-3.3.2")
  279. self.__download("https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py")
  280. self.__run_command(pypy_bin + "/pypy ez_setup.py")
  281. self.__run_command(python_bin + "/python ez_setup.py")
  282. self.__run_command(python3_bin + "/python3 ez_setup.py")
  283. easy_install('pip==1.4.1', two=True, three=True, pypy=True)
  284. easy_install('MySQL-python==1.2.4', two=True, three=False, pypy=True)
  285. easy_install('https://github.com/clelland/MySQL-for-Python-3/archive/master.zip', two=False, three=True, pypy=False)
  286. easy_install('PyMySQL==0.5', pypy=True)
  287. easy_install('PyMySQL3==0.5', two=False, three=True)
  288. easy_install('psycopg2==2.5.1', three=True)
  289. easy_install('simplejson==3.3.0', two=True, three=True, pypy=False)
  290. easy_install('ujson==1.33', three=True)
  291. easy_install('https://github.com/downloads/surfly/gevent/gevent-1.0rc2.tar.gz', three=True)
  292. easy_install('uwsgi', three=True) # uwsgi is released too often to stick on single version.
  293. # Gunicorn
  294. easy_install('gunicorn==17.5', two=True, three=True, pypy=True)
  295. # meinheld HEAD supports gunicorn worker on Python 3
  296. easy_install('https://github.com/mopemope/meinheld/archive/master.zip', two=True, three=True, pypy=True)
  297. # Tornado
  298. easy_install('tornado==3.1', two=True, three=True, pypy=True)
  299. easy_install('motor==0.1.1', two=True, three=True, pypy=True)
  300. easy_install('pymongo==2.5.2', two=True, three=True, pypy=True)
  301. # Django
  302. easy_install("https://www.djangoproject.com/download/1.6b2/tarball/", two=True, three=True, pypy=True)
  303. # Flask
  304. easy_install('Werkzeug==0.9.3', two=True, three=True, pypy=True)
  305. easy_install('flask==0.10.1', two=True, three=True, pypy=True)
  306. easy_install('sqlalchemy==0.8.2', two=True, three=True, pypy=True)
  307. easy_install('Jinja2==2.7', two=True, three=True, pypy=True)
  308. easy_install('Flask-SQLAlchemy==1.0', two=True, three=True, pypy=True)
  309. # Bottle
  310. easy_install('bottle==0.11.6', two=True, three=True, pypy=True)
  311. easy_install('bottle-sqlalchemy==0.4', two=True, three=True, pypy=True)
  312. # Falcon
  313. easy_install('Cython==0.19.1', two=True, three=True, pypy=True)
  314. easy_install('falcon==0.1.6post3', two=True, three=True, pypy=True)
  315. ############################################################
  316. # __install_error
  317. ############################################################
  318. def __install_error(self, message):
  319. print("\nINSTALL ERROR: %s\n" % message)
  320. if self.benchmarker.install_error_action == 'abort':
  321. sys.exit("Installation aborted.")
  322. ############################################################
  323. # End __install_error
  324. ############################################################
  325. ############################################################
  326. # __install_database_software
  327. ############################################################
  328. def __install_database_software(self):
  329. print("\nINSTALL: Installing database software\n")
  330. self.__run_command("cd .. && " + self.benchmarker.database_sftp_string(batch_file="config/database_sftp_batch"), True)
  331. remote_script = """
  332. ##############################
  333. # Prerequisites
  334. ##############################
  335. yes | sudo apt-get update
  336. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev postgresql
  337. sudo sh -c "echo '* - nofile 65535' >> /etc/security/limits.conf"
  338. sudo mkdir -p /ssd
  339. sudo mkdir -p /ssd/log
  340. ##############################
  341. # MySQL
  342. ##############################
  343. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  344. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  345. yes | sudo apt-get install mysql-server
  346. sudo stop mysql
  347. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  348. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  349. sudo mv my.cnf /etc/mysql/my.cnf
  350. sudo cp -R -p /var/lib/mysql /ssd/
  351. sudo cp -R -p /var/log/mysql /ssd/log
  352. sudo cp usr.sbin.mysqld /etc/apparmor.d/
  353. sudo /etc/init.d/apparmor reload
  354. sudo start mysql
  355. # Insert data
  356. mysql -uroot -psecret < create.sql
  357. ##############################
  358. # Postgres
  359. ##############################
  360. sudo useradd benchmarkdbuser -p benchmarkdbpass
  361. sudo -u postgres psql template1 < create-postgres-database.sql
  362. sudo -u benchmarkdbuser psql hello_world < create-postgres.sql
  363. sudo -u benchmarkdbuser psql hello_world < create-postgres-urweb.sql
  364. sudo -u postgres -H /etc/init.d/postgresql stop
  365. sudo mv postgresql.conf /etc/postgresql/9.1/main/postgresql.conf
  366. sudo mv pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf
  367. sudo cp -R -p /var/lib/postgresql/9.1/main /ssd/postgresql
  368. sudo -u postgres -H /etc/init.d/postgresql start
  369. sudo mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  370. ##############################
  371. # MongoDB
  372. ##############################
  373. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  374. sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
  375. sudo apt-get update
  376. yes | sudo apt-get remove mongodb-clients
  377. yes | sudo apt-get install mongodb-10gen
  378. sudo stop mongodb
  379. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  380. sudo mv mongodb.conf /etc/mongodb.conf
  381. sudo cp -R -p /var/lib/mongodb /ssd/
  382. sudo cp -R -p /var/log/mongodb /ssd/log/
  383. sudo start mongodb
  384. """
  385. print("\nINSTALL: %s" % self.benchmarker.database_ssh_string)
  386. p = subprocess.Popen(self.benchmarker.database_ssh_string.split(" "), stdin=subprocess.PIPE)
  387. p.communicate(remote_script)
  388. returncode = p.returncode
  389. if returncode != 0:
  390. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.database_ssh_string))
  391. print("\nINSTALL: Finished installing database software\n")
  392. ############################################################
  393. # End __install_database_software
  394. ############################################################
  395. ############################################################
  396. # __install_client_software
  397. ############################################################
  398. def __install_client_software(self):
  399. print("\nINSTALL: Installing client software\n")
  400. remote_script = """
  401. ##############################
  402. # Prerequisites
  403. ##############################
  404. yes | sudo apt-get update
  405. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev postgresql
  406. sudo sh -c "echo '* - nofile 65535' >> /etc/security/limits.conf"
  407. sudo mkdir -p /ssd
  408. sudo mkdir -p /ssd/log
  409. ##############################
  410. # wrk
  411. ##############################
  412. git clone https://github.com/wg/wrk.git
  413. cd wrk
  414. make
  415. sudo cp wrk /usr/local/bin
  416. cd ~
  417. git clone https://github.com/wg/wrk.git wrk-pipeline
  418. cd wrk-pipeline
  419. git checkout pipeline
  420. make
  421. sudo cp wrk /usr/local/bin/wrk-pipeline
  422. cd ~
  423. """
  424. print("\nINSTALL: %s" % self.benchmarker.client_ssh_string)
  425. p = subprocess.Popen(self.benchmarker.client_ssh_string.split(" "), stdin=subprocess.PIPE)
  426. p.communicate(remote_script)
  427. returncode = p.returncode
  428. if returncode != 0:
  429. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.client_ssh_string))
  430. print("\nINSTALL: Finished installing client software\n")
  431. ############################################################
  432. # End __install_client_software
  433. ############################################################
  434. ############################################################
  435. # __run_command
  436. ############################################################
  437. def __run_command(self, command, send_yes=False, cwd=None, retry=False):
  438. try:
  439. cwd = os.path.join(self.install_dir, cwd)
  440. except AttributeError:
  441. cwd = self.install_dir
  442. if retry:
  443. max_attempts = 5
  444. else:
  445. max_attempts = 1
  446. attempt = 1
  447. delay = 0
  448. print("\nINSTALL: %s (cwd=%s)" % (command, cwd))
  449. while True:
  450. error_message = ""
  451. try:
  452. # Execute command.
  453. if send_yes:
  454. process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd)
  455. process.communicate("yes")
  456. returncode = process.returncode
  457. if returncode:
  458. raise subprocess.CalledProcessError(returncode, command)
  459. else:
  460. subprocess.check_call(command, shell=True, cwd=cwd)
  461. break # Exit loop if successful.
  462. except:
  463. exceptionType, exceptionValue, exceptionTraceBack = sys.exc_info()
  464. error_message = "".join(traceback.format_exception_only(exceptionType, exceptionValue))
  465. print error_message
  466. # Exit if there are no more attempts left.
  467. attempt += 1
  468. if attempt > max_attempts:
  469. break
  470. # Delay before next attempt.
  471. if delay == 0:
  472. delay = 5
  473. else:
  474. delay = delay * 2
  475. print("Attempt %s/%s starting in %s seconds." % (attempt, max_attempts, delay))
  476. time.sleep(delay)
  477. if error_message:
  478. self.__install_error(error_message)
  479. ############################################################
  480. # End __run_command
  481. ############################################################
  482. ############################################################
  483. # __bash_from_string
  484. # Runs bash -c "command" in install_dir.
  485. ############################################################
  486. def __bash_from_string(self, command):
  487. self.__run_command('bash -c "%s"' % command)
  488. ############################################################
  489. # End __bash_from_string
  490. ############################################################
  491. ############################################################
  492. # __download
  493. # Downloads a file from a URI.
  494. ############################################################
  495. def __download(self, uri, filename=""):
  496. if filename:
  497. filename_option = "-O %s " % filename
  498. else:
  499. filename_option = ""
  500. command = "wget -nv --no-check-certificate --trust-server-names %s%s" % (filename_option, uri)
  501. self.__run_command(command, retry=True)
  502. ############################################################
  503. # End __download
  504. ############################################################
  505. ############################################################
  506. # __init__(benchmarker)
  507. ############################################################
  508. def __init__(self, benchmarker):
  509. self.benchmarker = benchmarker
  510. self.install_dir = "installs"
  511. try:
  512. os.mkdir(self.install_dir)
  513. except OSError:
  514. pass
  515. ############################################################
  516. # End __init__
  517. ############################################################
  518. # vim: sw=2