installer.py 20 KB

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