installer.py 25 KB

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