installer.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. import subprocess
  2. import os
  3. import time
  4. class Installer:
  5. ############################################################
  6. # install_software
  7. ############################################################
  8. def install_software(self):
  9. if self.benchmarker.install == 'all' or self.benchmarker.install == 'server':
  10. self.__install_server_software()
  11. if self.benchmarker.install == 'all' or self.benchmarker.install == 'client':
  12. self.__install_client_software()
  13. ############################################################
  14. # End install_software
  15. ############################################################
  16. ############################################################
  17. # __install_server_software
  18. ############################################################
  19. def __install_server_software(self):
  20. #######################################
  21. # Prerequisites
  22. #######################################
  23. self.__run_command("sudo apt-get update", True)
  24. self.__run_command("sudo apt-get upgrade", True)
  25. 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", True)
  26. self.__run_command("sudo add-apt-repository ppa:ubuntu-toolchain-r/test", True)
  27. self.__run_command("sudo apt-get update", True)
  28. self.__run_command("sudo apt-get install gcc-4.8 g++-4.8", True)
  29. self.__run_command("cp ../config/benchmark_profile ../../.bash_profile")
  30. self.__run_command("sudo sh -c \"echo '* - nofile 8192' >> /etc/security/limits.conf\"")
  31. #######################################
  32. # Languages
  33. #######################################
  34. #
  35. # Dart
  36. #
  37. self.__run_command("curl https://storage.googleapis.com/dart-editor-archive-integration/latest/dartsdk-linux-64.tar.gz | tar xvz")
  38. #
  39. # Erlang
  40. #
  41. self.__run_command("sudo cp ../config/erlang.list /etc/apt/sources.list.d/erlang.list")
  42. self.__run_command("wget -O - http://binaries.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -")
  43. self.__run_command("sudo apt-get update")
  44. self.__run_command("sudo apt-get install esl-erlang", True)
  45. #
  46. # Python
  47. #
  48. self.__run_command("curl -L http://bitbucket.org/pypy/pypy/downloads/pypy-2.0-linux64.tar.bz2 | tar xvj")
  49. self.__run_command("curl http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz | tar xvz")
  50. self.__run_command("./configure", cwd="Python-2.7.4")
  51. self.__run_command("make -j", cwd="Python-2.7.4")
  52. self.__run_command("sudo make install", cwd="Python-2.7.4")
  53. self.__run_command("curl https://pypi.python.org/packages/source/d/distribute/distribute-0.6.38.tar.gz | tar xvz")
  54. # run pypy before python. (`setup.py install` fails after `sudo setup.py install`)
  55. self.__run_command("../pypy-2.0/bin/pypy setup.py install", cwd="distribute-0.6.38")
  56. self.__run_command("sudo python setup.py install", cwd="distribute-0.6.38")
  57. self.__run_command("curl https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz | tar xvz")
  58. self.__run_command("../pypy-2.0/bin/pypy setup.py install", cwd="pip-1.3.1")
  59. self.__run_command("sudo python setup.py install", cwd="pip-1.3.1")
  60. self.__run_command("sudo pip install MySQL-python==1.2.4")
  61. self.__run_command("sudo pip install simplejson==3.0.7")
  62. self.__run_command("curl http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.tar.gz | tar xvz")
  63. self.__run_command("sudo python setup.py install", cwd="psycopg2-2.5")
  64. self.__run_command("git clone https://github.com/iiilx/django-psycopg2-pool.git")
  65. self.__run_command("sudo python setup.py install", cwd="django-psycopg2-pool")
  66. self.__run_command("sudo pip install --upgrade numpy==1.7.1")
  67. self.__run_command("pypy-2.0/bin/pip install PyMySQL==0.5")
  68. #
  69. # nodejs
  70. #
  71. self.__run_command("curl http://nodejs.org/dist/v0.10.8/node-v0.10.8-linux-x64.tar.gz | tar xvz")
  72. #
  73. # Java
  74. #
  75. self.__run_command("sudo apt-get install openjdk-7-jdk", True)
  76. self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
  77. #
  78. # Ruby/JRuby
  79. #
  80. self.__run_command("curl -L get.rvm.io | bash -s head")
  81. self.__run_command("echo rvm_auto_reload_flag=2 >> ~/.rvmrc")
  82. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install 2.0.0-p0"])
  83. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler"])
  84. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.4"])
  85. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do gem install bundler"])
  86. # We need a newer version of jruby-rack
  87. self.__run_command("git clone git://github.com/jruby/jruby-rack.git")
  88. subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do bundle install"])
  89. subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do jruby -S bundle exec rake clean gem SKIP_SPECS=true"])
  90. subprocess.call(["bash", "-c", "cd installs/jruby-rack/target && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.4 do gem install jruby-rack-1.2.0.SNAPSHOT.gem"])
  91. #
  92. # go
  93. #
  94. self.__run_command("curl http://go.googlecode.com/files/go1.1.linux-amd64.tar.gz | tar xvz")
  95. #
  96. # Perl
  97. #
  98. # Sometimes this HTTP server returns 404, so retry a few times until it works, but don't retry forever
  99. tries = 0
  100. while True:
  101. self.__run_command("curl 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 | tar xvz");
  102. if os.path.exists(os.path.join('installs', 'ActivePerl-5.16.3.1603-x86_64-linux-glibc-2.3.5-296746')):
  103. break
  104. tries += 1
  105. if tries >= 30:
  106. raise Exception('Could not download ActivePerl after many retries')
  107. time.sleep(5)
  108. 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)
  109. self.__run_command("curl -L http://cpanmin.us | perl - --sudo App::cpanminus")
  110. 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")
  111. #
  112. # php
  113. #
  114. self.__run_command("wget --trust-server-names http://www.php.net/get/php-5.4.13.tar.gz/from/us1.php.net/mirror")
  115. self.__run_command("tar xvf php-5.4.13.tar.gz")
  116. 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", cwd="php-5.4.13")
  117. self.__run_command("make", cwd="php-5.4.13")
  118. self.__run_command("sudo make install", cwd="php-5.4.13")
  119. self.__run_command("printf \"\\n\" | sudo pecl install apc-beta", cwd="php-5.4.13")
  120. self.__run_command("sudo cp ../config/php.ini /usr/local/lib/php.ini")
  121. self.__run_command("sudo cp ../config/php-fpm.conf /usr/local/lib/php-fpm.conf")
  122. self.__run_command("rm php-5.4.13.tar.gz")
  123. # Composer
  124. self.__run_command("curl -sS https://getcomposer.org/installer | php -- --install-dir=bin")
  125. # Phalcon
  126. self.__run_command("git clone git://github.com/phalcon/cphalcon.git")
  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.__run_command("wget 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. self.__run_command("sudo ringo-admin install oberhamsi/sql-ringojs-client")
  142. self.__run_command("sudo ringo-admin install ringo/stick")
  143. self.__run_command("sudo ringo-admin install oberhamsi/reinhardt")
  144. self.__run_command("sudo ringo-admin install grob/ringo-sqlstore")
  145. self.__run_command("sudo ringo-admin install amigrave/ringo-mongodb")
  146. #
  147. # Mono
  148. #
  149. self.__run_command("git clone git://github.com/mono/mono")
  150. self.__run_command("git checkout mono-3.0.10", cwd="mono")
  151. self.__run_command("./autogen.sh --prefix=/usr/local", cwd="mono")
  152. self.__run_command("make get-monolite-latest", cwd="mono")
  153. self.__run_command("make EXTERNAL_MCS=${PWD}/mcs/class/lib/monolite/gmcs.exe", cwd="mono")
  154. self.__run_command("sudo make install", cwd="mono")
  155. self.__run_command("mozroots --import --sync")
  156. self.__run_command("git clone git://github.com/mono/xsp")
  157. self.__run_command("git checkout 3.0", cwd="xsp")
  158. self.__run_command("./autogen.sh --prefix=/usr/local", cwd="xsp")
  159. self.__run_command("make", cwd="xsp")
  160. self.__run_command("sudo make install", cwd="xsp")
  161. #
  162. # Nimrod
  163. #
  164. self.__run_command("wget http://www.nimrod-code.org/download/nimrod_0.9.2.zip")
  165. self.__run_command("unzip nimrod_0.9.2.zip")
  166. self.__run_command("chmod +x build.sh", cwd="nimrod")
  167. self.__run_command("./build.sh", cwd="nimrod")
  168. self.__run_command("chmod +x install.sh", cwd="nimrod")
  169. self.__run_command("sudo ./install.sh /usr/bin", cwd="nimrod")
  170. #######################################
  171. # Webservers
  172. #######################################
  173. #
  174. # Nginx
  175. #
  176. self.__run_command("curl http://nginx.org/download/nginx-1.4.1.tar.gz | tar xvz")
  177. self.__run_command("./configure", cwd="nginx-1.4.1")
  178. self.__run_command("make", cwd="nginx-1.4.1")
  179. self.__run_command("sudo make install", cwd="nginx-1.4.1")
  180. #
  181. # Openresty (nginx with openresty stuff)
  182. #
  183. self.__run_command("curl http://openresty.org/download/ngx_openresty-1.2.7.5.tar.gz | tar xvz")
  184. self.__run_command("./configure --with-luajit", 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. # Gunicorn
  189. #
  190. self.__run_command("sudo easy_install -U 'gunicorn==0.17.4'")
  191. self.__run_command("sudo pip install --upgrade meinheld")
  192. self.__run_command("sudo easy_install -U 'eventlet==0.12.1'")
  193. self.__run_command("sudo pip install --upgrade 'gevent==0.13.8'")
  194. #
  195. # Resin
  196. #
  197. 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/")
  198. self.__run_command("curl http://www.caucho.com/download/resin-4.0.36.tar.gz | tar xvz")
  199. self.__run_command("./configure --prefix=`pwd`", cwd="resin-4.0.36")
  200. self.__run_command("make", cwd="resin-4.0.36")
  201. self.__run_command("make install", cwd="resin-4.0.36")
  202. self.__run_command("mv conf/resin.properties conf/resin.properties.orig", cwd="resin-4.0.36")
  203. self.__run_command("cat ../config/resin.properties > resin-4.0.36/conf/resin.properties")
  204. ##############################################################
  205. #
  206. # Frameworks
  207. #
  208. ##############################################################
  209. ##############################
  210. # Tornado
  211. ##############################
  212. packages = "tornado==3.0.1 motor==0.1 pymongo==2.5"
  213. self.__run_command("sudo pip install " + packages)
  214. self.__run_command("pypy-2.0/bin/pip install " + packages)
  215. ##############################
  216. # Django
  217. ##############################
  218. self.__run_command("curl http://www.djangoproject.com/m/releases/1.4/Django-1.4.tar.gz | tar xvz")
  219. self.__run_command("sudo rm -rf /usr/local/lib/python2.7/site-packages/django")
  220. self.__run_command("sudo python setup.py install", cwd="Django-1.4")
  221. self.__run_command("sudo easy_install -U 'ujson==1.30'")
  222. ##############################
  223. # Grails
  224. ##############################
  225. self.__run_command("wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.1.zip")
  226. self.__run_command("unzip -o grails-2.1.1.zip")
  227. self.__run_command("rm grails-2.1.1.zip")
  228. ##############################
  229. # Flask
  230. ##############################
  231. packages = "flask==0.9 flask-sqlalchemy==0.16 sqlalchemy==0.8.1 jinja2==2.6 werkzeug==0.8.3"
  232. self.__run_command("sudo pip install " + packages)
  233. self.__run_command("pypy-2.0/bin/pip install " + packages)
  234. ##############################
  235. # Bottle
  236. ##############################
  237. self.__run_command("sudo pip install bottle bottle-sqlalchemy")
  238. ##############################
  239. # Play 2
  240. ##############################
  241. self.__run_command("wget http://downloads.typesafe.com/play/2.1.2-RC1/play-2.1.2-RC1.zip")
  242. self.__run_command("unzip -o play-2.1.2-RC1.zip")
  243. self.__run_command("rm play-2.1.2-RC1.zip")
  244. ##############################
  245. # Play 1
  246. ##############################
  247. self.__run_command("wget http://downloads.typesafe.com/releases/play-1.2.5.zip")
  248. self.__run_command("unzip -o play-1.2.5.zip")
  249. self.__run_command("rm play-1.2.5.zip")
  250. self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
  251. # siena
  252. self.__run_command("play-1.2.5/play1 install siena", send_yes=True)
  253. ##############################
  254. # Vert.x
  255. ##############################
  256. self.__run_command("curl http://vert-x.github.io/vertx-downloads/downloads/vert.x-1.3.1.final.tar.gz | tar xvz")
  257. ##############################
  258. # Yesod
  259. ##############################
  260. self.__run_command("cabal update")
  261. self.__run_command("cabal install yesod persistent-mysql")
  262. ##############################
  263. # Jester
  264. ##############################
  265. self.__run_command("git clone git://github.com/dom96/jester.git jester/jester")
  266. ##############################################################
  267. #
  268. # System Tools
  269. #
  270. ##############################################################
  271. ##############################
  272. # Maven
  273. ##############################
  274. # self.__run_command("sudo apt-get install maven2", send_yes=True)
  275. self.__run_command("curl www.us.apache.org/dist/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz | tar xvz")
  276. ##############################
  277. # Leiningen
  278. ##############################
  279. self.__run_command("mkdir -p bin")
  280. self.__run_command("wget https://raw.github.com/technomancy/leiningen/stable/bin/lein")
  281. self.__run_command("mv lein bin/lein")
  282. self.__run_command("chmod +x bin/lein")
  283. ############################################################
  284. # End __install_server_software
  285. ############################################################
  286. ############################################################
  287. # __install_client_software
  288. ############################################################
  289. def __install_client_software(self):
  290. subprocess.call(self.benchmarker.sftp_string(batch_file="config/client_sftp_batch"), shell=True)
  291. remote_script = """
  292. ##############################
  293. # Prerequisites
  294. ##############################
  295. yes | sudo apt-get update
  296. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev postgresql
  297. sudo sh -c "echo '* - nofile 8192' >> /etc/security/limits.conf"
  298. sudo mkdir -p /ssd
  299. sudo mkdir -p /ssd/log
  300. ##############################
  301. # MySQL
  302. ##############################
  303. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  304. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  305. yes | sudo apt-get install mysql-server
  306. sudo stop mysql
  307. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  308. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  309. sudo mv my.cnf /etc/mysql/my.cnf
  310. sudo cp -R -p /var/lib/mysql /ssd/
  311. sudo cp -R -p /var/log/mysql /ssd/log
  312. sudo cp usr.sbin.mysqld /etc/apparmor.d/
  313. sudo /etc/init.d/apparmor reload
  314. sudo start mysql
  315. # Insert data
  316. mysql -uroot -psecret < create.sql
  317. ##############################
  318. # Postgres
  319. ##############################
  320. sudo useradd benchmarkdbuser -p benchmarkdbpass
  321. sudo -u postgres psql template1 < create-postgres-database.sql
  322. sudo -u benchmarkdbuser psql hello_world < create-postgres.sql
  323. sudo -u postgres -H /etc/init.d/postgresql stop
  324. sudo mv postgresql.conf /etc/postgresql/9.1/main/postgresql.conf
  325. sudo mv pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf
  326. sudo cp -R -p /var/lib/postgresql/9.1/main /ssd/postgresql
  327. sudo -u postgres -H /etc/init.d/postgresql start
  328. ##############################
  329. # wrk
  330. ##############################
  331. git clone https://github.com/wg/wrk.git
  332. cd wrk
  333. make
  334. sudo cp wrk /usr/local/bin
  335. cd ~
  336. git clone https://github.com/wg/wrk.git wrk-pipeline
  337. cd wrk-pipeline
  338. git checkout pipeline
  339. make
  340. sudo cp wrk /usr/local/bin/wrk-pipeline
  341. cd ~
  342. ##############################
  343. # MongoDB
  344. ##############################
  345. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  346. sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
  347. sudo apt-get update
  348. yes | sudo apt-get install mongodb-10gen
  349. sudo stop mongodb
  350. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  351. sudo mv mongodb.conf /etc/mongodb.conf
  352. sudo cp -R -p /var/lib/mongodb /ssd/
  353. sudo cp -R -p /var/log/mongodb /ssd/log/
  354. sudo start mongodb
  355. """
  356. p = subprocess.Popen(self.benchmarker.ssh_string.split(" "), stdin=subprocess.PIPE)
  357. p.communicate(remote_script)
  358. ############################################################
  359. # End __parse_results
  360. ############################################################
  361. ############################################################
  362. # __run_command
  363. ############################################################
  364. def __run_command(self, command, send_yes=False, cwd=None):
  365. try:
  366. cwd = os.path.join(self.install_dir, cwd)
  367. except AttributeError:
  368. cwd = self.install_dir
  369. if send_yes:
  370. subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd).communicate("yes")
  371. else:
  372. subprocess.call(command, shell=True, cwd=cwd)
  373. ############################################################
  374. # End __run_command
  375. ############################################################
  376. ############################################################
  377. # __init__(benchmarker)
  378. ############################################################
  379. def __init__(self, benchmarker):
  380. self.benchmarker = benchmarker
  381. self.install_dir = "installs"
  382. try:
  383. os.mkdir(self.install_dir)
  384. except OSError:
  385. pass
  386. ############################################################
  387. # End __init__
  388. ############################################################