installer.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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.2.linux-amd64.tar.gz");
  94. self.__run_command("tar xzf go1.2.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. # Min version: ac1be85e91ad --- HTML5 directive
  165. self.__run_command("hg clone -rac1be85e91ad http://hg.impredicative.com/urweb")
  166. self.__run_command("./autogen.sh", cwd="urweb")
  167. self.__run_command("./configure", cwd="urweb")
  168. self.__run_command("make", cwd="urweb")
  169. self.__run_command("sudo make install", cwd="urweb")
  170. #
  171. # HHVM
  172. #
  173. self.__run_command("wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -")
  174. self.__run_command("echo deb http://dl.hhvm.com/ubuntu precise main | sudo tee /etc/apt/sources.list.d/hhvm.list")
  175. self.__run_command("sudo apt-get update")
  176. self.__run_command("sudo apt-get install hhvm")
  177. #######################################
  178. # Webservers
  179. #######################################
  180. #
  181. # Nginx
  182. #
  183. self.__download("http://nginx.org/download/nginx-1.4.1.tar.gz")
  184. self.__run_command("tar xzf nginx-1.4.1.tar.gz")
  185. self.__run_command("./configure", cwd="nginx-1.4.1")
  186. self.__run_command("make", cwd="nginx-1.4.1")
  187. self.__run_command("sudo make install", cwd="nginx-1.4.1")
  188. #
  189. # Openresty (nginx with openresty stuff)
  190. #
  191. self.__download("http://openresty.org/download/ngx_openresty-1.2.7.5.tar.gz")
  192. self.__run_command("tar xzf ngx_openresty-1.2.7.5.tar.gz")
  193. self.__run_command("./configure --with-luajit --with-http_postgres_module", cwd="ngx_openresty-1.2.7.5")
  194. self.__run_command("make", cwd="ngx_openresty-1.2.7.5")
  195. self.__run_command("sudo make install", cwd="ngx_openresty-1.2.7.5")
  196. #
  197. # Resin
  198. #
  199. 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/")
  200. self.__download("http://www.caucho.com/download/resin-4.0.36.tar.gz")
  201. self.__run_command("tar xzf resin-4.0.36.tar.gz")
  202. self.__run_command("./configure --prefix=`pwd`", cwd="resin-4.0.36")
  203. self.__run_command("make", cwd="resin-4.0.36")
  204. self.__run_command("make install", cwd="resin-4.0.36")
  205. self.__run_command("mv conf/resin.properties conf/resin.properties.orig", cwd="resin-4.0.36")
  206. self.__run_command("cat ../config/resin.properties > resin-4.0.36/conf/resin.properties")
  207. self.__run_command("mv conf/resin.xml conf/resin.xml.orig", cwd="resin-4.0.36")
  208. self.__run_command("cat ../config/resin.xml > resin-4.0.36/conf/resin.xml")
  209. ##############################################################
  210. # Frameworks
  211. ##############################################################
  212. #
  213. # Grails
  214. #
  215. self.__download("http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.3.3.zip")
  216. self.__run_command("unzip -o grails-2.3.3.zip")
  217. self.__run_command("rm grails-2.3.3.zip")
  218. #
  219. # Play 2
  220. #
  221. self.__download("http://downloads.typesafe.com/play/2.2.0/play-2.2.0.zip")
  222. self.__run_command("unzip -o play-2.2.0.zip")
  223. self.__run_command("rm play-2.2.0.zip")
  224. #
  225. # Play 1
  226. #
  227. self.__download("http://downloads.typesafe.com/releases/play-1.2.5.zip")
  228. self.__run_command("unzip -o play-1.2.5.zip")
  229. self.__run_command("rm play-1.2.5.zip")
  230. self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
  231. # siena
  232. self.__run_command("yes | play-1.2.5/play1 install siena")
  233. #
  234. # TreeFrog Framework
  235. #
  236. self.__run_command("sudo apt-get install qt4-qmake libqt4-dev libqt4-sql-mysql g++", True)
  237. self.__download("http://downloads.sourceforge.net/project/treefrog/src/treefrog-1.7.4.tar.gz")
  238. self.__run_command("tar xzf treefrog-1.7.4.tar.gz")
  239. self.__run_command("rm treefrog-1.7.4.tar.gz")
  240. self.__run_command("./configure", cwd="treefrog-1.7.4")
  241. self.__run_command("make", cwd="treefrog-1.7.4/src")
  242. self.__run_command("sudo make install", cwd="treefrog-1.7.4/src")
  243. self.__run_command("make", cwd="treefrog-1.7.4/tools")
  244. self.__run_command("sudo make install", cwd="treefrog-1.7.4/tools")
  245. #
  246. # Vert.x
  247. #
  248. self.__download("http://dl.bintray.com/vertx/downloads/vert.x-2.1M2.tar.gz?direct=true", "vert.x-2.1M2.tar.gz")
  249. self.__run_command("tar xzf vert.x-2.1M2.tar.gz")
  250. #
  251. # Yesod
  252. #
  253. self.__run_command("cabal update", retry=True)
  254. self.__run_command("cabal install yesod persistent-mysql", retry=True)
  255. #
  256. # Jester
  257. #
  258. self.__run_command("git clone git://github.com/dom96/jester.git jester/jester", retry=True)
  259. #
  260. # Onion
  261. #
  262. self.__run_command("git clone [email protected]:davidmoreno/onion.git")
  263. self.__run_command("mkdir build", cwd="onion")
  264. self.__run_command("cmake ..", cwd="onion/build")
  265. self.__run_command("make", cwd="onion/build")
  266. print("\nINSTALL: Finished installing server software\n")
  267. ############################################################
  268. # End __install_server_software
  269. ############################################################
  270. def _install_python(self):
  271. # .profile is not loaded yet. So we should use full path.
  272. pypy_bin = "~/FrameworkBenchmarks/installs/pypy/bin"
  273. python_bin = "~/FrameworkBenchmarks/installs/py2/bin"
  274. python3_bin= "~/FrameworkBenchmarks/installs/py3/bin"
  275. def easy_install(pkg, two=True, three=False, pypy=False):
  276. cmd = "/easy_install -ZU '" + pkg + "'"
  277. if two: self.__run_command(python_bin + cmd, retry=True)
  278. if three: self.__run_command(python3_bin + cmd, retry=True)
  279. if pypy: self.__run_command(pypy_bin + cmd, retry=True)
  280. self.__download("https://bitbucket.org/pypy/pypy/downloads/pypy-2.2-linux64.tar.bz2")
  281. self.__run_command("tar xjf pypy-2.2-linux64.tar.bz2")
  282. self.__run_command('ln -sf pypy-2.2-linux64 pypy')
  283. self.__download("http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz")
  284. self.__run_command("tar xzf Python-2.7.6.tgz")
  285. self.__download("http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tar.xz")
  286. self.__run_command("tar xJf Python-3.3.2.tar.xz")
  287. self.__run_command("./configure --prefix=$HOME/FrameworkBenchmarks/installs/py2 --disable-shared CC=gcc-4.8", cwd="Python-2.7.6")
  288. self.__run_command("./configure --prefix=$HOME/FrameworkBenchmarks/installs/py3 --disable-shared CC=gcc-4.8", cwd="Python-3.3.2")
  289. self.__run_command("make -j2", cwd="Python-2.7.6")
  290. self.__run_command("make install", cwd="Python-2.7.6")
  291. self.__run_command("make -j2", cwd="Python-3.3.2")
  292. self.__run_command("make install", cwd="Python-3.3.2")
  293. self.__download("https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py")
  294. self.__run_command(pypy_bin + "/pypy ez_setup.py")
  295. self.__run_command(python_bin + "/python ez_setup.py")
  296. self.__run_command(python3_bin + "/python3 ez_setup.py")
  297. easy_install('pip==1.4.1', two=True, three=True, pypy=True)
  298. easy_install('MySQL-python==1.2.4', two=True, three=False, pypy=True)
  299. easy_install('https://github.com/clelland/MySQL-for-Python-3/archive/master.zip', two=False, three=True, pypy=False)
  300. easy_install('PyMySQL==0.6.1', two=True, three=True, pypy=True)
  301. easy_install('psycopg2==2.5.1', three=True)
  302. easy_install('simplejson==3.3.1', two=True, three=True, pypy=False)
  303. easy_install('ujson==1.33', three=True)
  304. easy_install('gevent==1.0')
  305. easy_install('uwsgi', three=True) # uwsgi is released too often to stick on single version.
  306. # Gunicorn
  307. easy_install('gunicorn==18', two=True, three=True, pypy=True)
  308. # meinheld HEAD supports gunicorn worker on Python 3
  309. easy_install('https://github.com/mopemope/meinheld/archive/master.zip', two=True, three=True, pypy=True)
  310. # Tornado
  311. easy_install('tornado==3.1', two=True, three=True, pypy=True)
  312. easy_install('motor==0.1.2', two=True, three=True, pypy=True)
  313. easy_install('pymongo==2.5.2', two=True, three=True, pypy=True)
  314. # Django
  315. easy_install("https://www.djangoproject.com/download/1.6/tarball/", two=True, three=True, pypy=True)
  316. # Flask
  317. easy_install('Werkzeug==0.9.4', two=True, three=True, pypy=True)
  318. easy_install('flask==0.10.1', two=True, three=True, pypy=True)
  319. easy_install('sqlalchemy==0.8.3', two=True, three=False, pypy=True)
  320. # SQLAlchemy 0.9 supports C extension for Python 3
  321. easy_install('https://bitbucket.org/zzzeek/sqlalchemy/downloads/SQLAlchemy-0.9.0b1.tar.gz', two=False, three=True)
  322. easy_install('Jinja2==2.7.1', two=True, three=True, pypy=True)
  323. easy_install('Flask-SQLAlchemy==1.0', two=True, three=True, pypy=True)
  324. # Bottle
  325. easy_install('bottle==0.11.6', two=True, three=True, pypy=True)
  326. easy_install('bottle-sqlalchemy==0.4', two=True, three=True, pypy=True)
  327. # Falcon
  328. easy_install('Cython==0.19.2', two=True, three=True, pypy=True)
  329. easy_install('falcon==0.1.7', two=True, three=True, pypy=True)
  330. ############################################################
  331. # __install_error
  332. ############################################################
  333. def __install_error(self, message):
  334. print("\nINSTALL ERROR: %s\n" % message)
  335. if self.benchmarker.install_error_action == 'abort':
  336. sys.exit("Installation aborted.")
  337. ############################################################
  338. # End __install_error
  339. ############################################################
  340. ############################################################
  341. # __install_database_software
  342. ############################################################
  343. def __install_database_software(self):
  344. print("\nINSTALL: Installing database software\n")
  345. self.__run_command("cd .. && " + self.benchmarker.database_sftp_string(batch_file="config/database_sftp_batch"), True)
  346. remote_script = """
  347. ##############################
  348. # Prerequisites
  349. ##############################
  350. yes | sudo apt-get update
  351. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev postgresql
  352. sudo sh -c "echo '* - nofile 65535' >> /etc/security/limits.conf"
  353. sudo mkdir -p /ssd
  354. sudo mkdir -p /ssd/log
  355. ##############################
  356. # MySQL
  357. ##############################
  358. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  359. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  360. yes | sudo apt-get install mysql-server
  361. sudo stop mysql
  362. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  363. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  364. sudo mv my.cnf /etc/mysql/my.cnf
  365. sudo cp -R -p /var/lib/mysql /ssd/
  366. sudo cp -R -p /var/log/mysql /ssd/log
  367. sudo cp usr.sbin.mysqld /etc/apparmor.d/
  368. sudo /etc/init.d/apparmor reload
  369. sudo start mysql
  370. # Insert data
  371. mysql -uroot -psecret < create.sql
  372. ##############################
  373. # Postgres
  374. ##############################
  375. sudo useradd benchmarkdbuser -p benchmarkdbpass
  376. sudo -u postgres psql template1 < create-postgres-database.sql
  377. sudo -u benchmarkdbuser psql hello_world < create-postgres.sql
  378. sudo -u postgres -H /etc/init.d/postgresql stop
  379. sudo mv postgresql.conf /etc/postgresql/9.1/main/postgresql.conf
  380. sudo mv pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf
  381. sudo cp -R -p /var/lib/postgresql/9.1/main /ssd/postgresql
  382. sudo -u postgres -H /etc/init.d/postgresql start
  383. sudo mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  384. ##############################
  385. # MongoDB
  386. ##############################
  387. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  388. sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
  389. sudo apt-get update
  390. yes | sudo apt-get remove mongodb-clients
  391. yes | sudo apt-get install mongodb-10gen
  392. sudo stop mongodb
  393. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  394. sudo mv mongodb.conf /etc/mongodb.conf
  395. sudo cp -R -p /var/lib/mongodb /ssd/
  396. sudo cp -R -p /var/log/mongodb /ssd/log/
  397. sudo start mongodb
  398. """
  399. print("\nINSTALL: %s" % self.benchmarker.database_ssh_string)
  400. p = subprocess.Popen(self.benchmarker.database_ssh_string.split(" "), stdin=subprocess.PIPE)
  401. p.communicate(remote_script)
  402. returncode = p.returncode
  403. if returncode != 0:
  404. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.database_ssh_string))
  405. print("\nINSTALL: Finished installing database software\n")
  406. ############################################################
  407. # End __install_database_software
  408. ############################################################
  409. ############################################################
  410. # __install_client_software
  411. ############################################################
  412. def __install_client_software(self):
  413. print("\nINSTALL: Installing client software\n")
  414. remote_script = """
  415. ##############################
  416. # Prerequisites
  417. ##############################
  418. yes | sudo apt-get update
  419. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev postgresql
  420. sudo sh -c "echo '* - nofile 65535' >> /etc/security/limits.conf"
  421. sudo mkdir -p /ssd
  422. sudo mkdir -p /ssd/log
  423. ##############################
  424. # wrk
  425. ##############################
  426. git clone https://github.com/wg/wrk.git
  427. cd wrk
  428. make
  429. sudo cp wrk /usr/local/bin
  430. cd ~
  431. git clone https://github.com/wg/wrk.git wrk-pipeline
  432. cd wrk-pipeline
  433. git checkout pipeline
  434. make
  435. sudo cp wrk /usr/local/bin/wrk-pipeline
  436. cd ~
  437. """
  438. print("\nINSTALL: %s" % self.benchmarker.client_ssh_string)
  439. p = subprocess.Popen(self.benchmarker.client_ssh_string.split(" "), stdin=subprocess.PIPE)
  440. p.communicate(remote_script)
  441. returncode = p.returncode
  442. if returncode != 0:
  443. self.__install_error("status code %s running subprocess '%s'." % (returncode, self.benchmarker.client_ssh_string))
  444. print("\nINSTALL: Finished installing client software\n")
  445. ############################################################
  446. # End __install_client_software
  447. ############################################################
  448. ############################################################
  449. # __run_command
  450. ############################################################
  451. def __run_command(self, command, send_yes=False, cwd=None, retry=False):
  452. try:
  453. cwd = os.path.join(self.install_dir, cwd)
  454. except AttributeError:
  455. cwd = self.install_dir
  456. if retry:
  457. max_attempts = 5
  458. else:
  459. max_attempts = 1
  460. attempt = 1
  461. delay = 0
  462. print("\nINSTALL: %s (cwd=%s)" % (command, cwd))
  463. while True:
  464. error_message = ""
  465. try:
  466. # Execute command.
  467. if send_yes:
  468. process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd)
  469. process.communicate("yes")
  470. returncode = process.returncode
  471. if returncode:
  472. raise subprocess.CalledProcessError(returncode, command)
  473. else:
  474. subprocess.check_call(command, shell=True, cwd=cwd)
  475. break # Exit loop if successful.
  476. except:
  477. exceptionType, exceptionValue, exceptionTraceBack = sys.exc_info()
  478. error_message = "".join(traceback.format_exception_only(exceptionType, exceptionValue))
  479. print error_message
  480. # Exit if there are no more attempts left.
  481. attempt += 1
  482. if attempt > max_attempts:
  483. break
  484. # Delay before next attempt.
  485. if delay == 0:
  486. delay = 5
  487. else:
  488. delay = delay * 2
  489. print("Attempt %s/%s starting in %s seconds." % (attempt, max_attempts, delay))
  490. time.sleep(delay)
  491. if error_message:
  492. self.__install_error(error_message)
  493. ############################################################
  494. # End __run_command
  495. ############################################################
  496. ############################################################
  497. # __bash_from_string
  498. # Runs bash -c "command" in install_dir.
  499. ############################################################
  500. def __bash_from_string(self, command):
  501. self.__run_command('bash -c "%s"' % command)
  502. ############################################################
  503. # End __bash_from_string
  504. ############################################################
  505. ############################################################
  506. # __download
  507. # Downloads a file from a URI.
  508. ############################################################
  509. def __download(self, uri, filename=""):
  510. if filename:
  511. filename_option = "-O %s " % filename
  512. else:
  513. filename_option = ""
  514. command = "wget -nv --no-check-certificate --trust-server-names %s%s" % (filename_option, uri)
  515. self.__run_command(command, retry=True)
  516. ############################################################
  517. # End __download
  518. ############################################################
  519. ############################################################
  520. # __init__(benchmarker)
  521. ############################################################
  522. def __init__(self, benchmarker):
  523. self.benchmarker = benchmarker
  524. self.install_dir = "installs"
  525. try:
  526. os.mkdir(self.install_dir)
  527. except OSError:
  528. pass
  529. ############################################################
  530. # End __init__
  531. ############################################################
  532. # vim: sw=2