installer.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. import subprocess
  2. import os
  3. class Installer:
  4. ############################################################
  5. # install_software
  6. ############################################################
  7. def install_software(self):
  8. self.__install_server_software()
  9. self.__install_client_software()
  10. ############################################################
  11. # End install_software
  12. ############################################################
  13. ############################################################
  14. # __install_server_software
  15. ############################################################
  16. def __install_server_software(self):
  17. #######################################
  18. # Prerequisites
  19. #######################################
  20. self.__run_command("sudo apt-get update", True)
  21. self.__run_command("sudo apt-get upgrade", True)
  22. 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", True)
  23. self.__run_command("cp ../config/benchmark_profile ../../.bash_profile")
  24. self.__run_command("sudo sh -c \"echo '* soft nofile 8192' >> /etc/security/limits.conf\"")
  25. #######################################
  26. # Languages
  27. #######################################
  28. #
  29. # Erlang
  30. #
  31. self.__run_command("sudo cp ../config/erlang.list /etc/apt/sources.list.d/erlang.list")
  32. self.__run_command("wget -O - http://binaries.erlang-solutions.com/debian/erlang_solutions.asc | sudo apt-key add -")
  33. self.__run_command("sudo apt-get update")
  34. self.__run_command("sudo apt-get install esl-erlang", True)
  35. #
  36. # Python
  37. #
  38. self.__run_command("curl http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz | tar xvz")
  39. self.__run_command("./configure", cwd="Python-2.7.3")
  40. self.__run_command("sudo make install", cwd="Python-2.7.3")
  41. self.__run_command("curl http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz | tar xvz")
  42. self.__run_command("sudo python setup.py install", cwd="setuptools-0.6c11")
  43. self.__run_command("curl http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz | tar xvz")
  44. self.__run_command("sudo python setup.py install", cwd="pip-1.1")
  45. self.__run_command("sudo pip install MySQL-python==1.2.4")
  46. self.__run_command("sudo pip install simplejson==3.0.7")
  47. #
  48. # nodejs
  49. #
  50. self.__run_command("curl http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-x64.tar.gz | tar xvz")
  51. #
  52. # Java
  53. #
  54. self.__run_command("sudo apt-get install openjdk-7-jdk", True)
  55. self.__run_command("sudo apt-get remove --purge openjdk-6-jre openjdk-6-jre-headless", True)
  56. #
  57. # Ruby/JRuby
  58. #
  59. self.__run_command("curl -L get.rvm.io | bash -s head")
  60. self.__run_command("echo rvm_auto_reload_flag=2 >> ~/.rvmrc")
  61. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install 2.0.0-p0"])
  62. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem install bundler"])
  63. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm install jruby-1.7.3"])
  64. subprocess.call(["bash", "-c", "source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do gem install bundler"])
  65. # We need a newer version of jruby-rack
  66. self.__run_command("git clone git://github.com/jruby/jruby-rack.git")
  67. subprocess.call(["bash", "-c", "cd installs/jruby-rack && source ~/.rvm/scripts/'rvm' && rvm jruby-1.7.3 do bundle install"])
  68. 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"])
  69. 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"])
  70. #
  71. # go
  72. #
  73. self.__run_command("curl http://go.googlecode.com/files/go1.1beta1.linux-amd64.tar.gz | tar xvz")
  74. #
  75. # php
  76. #
  77. self.__run_command("wget --trust-server-names http://www.php.net/get/php-5.4.13.tar.gz/from/us1.php.net/mirror")
  78. self.__run_command("tar xvf php-5.4.13.tar.gz")
  79. 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")
  80. self.__run_command("make", cwd="php-5.4.13")
  81. self.__run_command("sudo make install", cwd="php-5.4.13")
  82. self.__run_command("printf \"\\n\" | sudo pecl install apc-beta", cwd="php-5.4.13")
  83. self.__run_command("sudo cp ../config/php.ini /usr/local/lib/php.ini")
  84. self.__run_command("sudo cp ../config/php-fpm.conf /usr/local/lib/php-fpm.conf")
  85. self.__run_command("rm php-5.4.13.tar.gz")
  86. # Composer
  87. self.__run_command("curl -sS https://getcomposer.org/installer | php -- --install-dir=bin")
  88. # Phalcon
  89. self.__run_command("git clone git://github.com/phalcon/cphalcon.git")
  90. self.__run_command("sudo ./install", cwd="cphalcon/build")
  91. #
  92. # Haskell
  93. #
  94. self.__run_command("sudo apt-get install ghc cabal-install", True)
  95. #
  96. # RingoJs
  97. #
  98. self.__run_command("wget http://www.ringojs.org/downloads/ringojs_0.9-1_all.deb")
  99. self.__run_command("sudo apt-get install jsvc")
  100. self.__run_command("sudo dpkg -i ringojs_0.9-1_all.deb")
  101. self.__run_command("rm ringojs_0.9-1_all.deb")
  102. self.__run_command("sudo ringo-admin install oberhamsi/sql-ringojs-client")
  103. self.__run_command("sudo ringo-admin install ringo/stick")
  104. self.__run_command("sudo ringo-admin install oberhamsi/reinhardt")
  105. self.__run_command("sudo ringo-admin install grob/ringo-sqlstore")
  106. #
  107. # Perl
  108. #
  109. self.__run_command("sudo cpan install Plack", send_yes=True)
  110. self.__run_command("sudo cpan install Starman")
  111. self.__run_command("sudo cpan install DBD::mysql")
  112. self.__run_command("sudo cpan install DBI")
  113. self.__run_command("sudo cpan install Dancer")
  114. self.__run_command("sudo cpan install Dancer::Plugin::Database")
  115. self.__run_command("sudo cpan install JSON", send_yes=True)
  116. self.__run_command("sudo cpan install Kelp", send_yes=True)
  117. self.__run_command("sudo cpan install Mojolicious", send_yes=True)
  118. self.__run_command("sudo cpan install Mojolicious:Plugin:Database", send_yes=True)
  119. #######################################
  120. # Webservers
  121. #######################################
  122. #
  123. # Apache
  124. #
  125. self.__run_command("sudo apt-get install apache2 libapache2-mod-php5", True)
  126. self.__run_command("sudo mv /etc/apache2/apache2.conf /etc/apache2/apache2.conf.orig")
  127. self.__run_command("sudo sh -c \"cat ../config/apache2.conf > /etc/apache2/apache2.conf\"")
  128. self.__run_command("sudo mv /etc/apache2/ports.conf /etc/apache2/ports.conf.orig")
  129. self.__run_command("sudo sh -c \"cat ../config/ports.conf > /etc/apache2/ports.conf\"")
  130. self.__run_command("sudo /etc/init.d/apache2 stop")
  131. #
  132. # Nginx
  133. #
  134. self.__run_command("curl http://nginx.org/download/nginx-1.2.7.tar.gz | tar xvz")
  135. self.__run_command("./configure", cwd="nginx-1.2.7")
  136. self.__run_command("make", cwd="nginx-1.2.7")
  137. self.__run_command("sudo make install", cwd="nginx-1.2.7")
  138. #
  139. # Openresty (nginx with openresty stuff)
  140. #
  141. self.__run_command("curl http://openresty.org/download/ngx_openresty-1.2.7.5.tar.gz | tar xvz")
  142. self.__run_command("./configure --with-luajit", cwd="ngx_openresty-1.2.7.5")
  143. self.__run_command("make", cwd="ngx_openresty-1.2.7.5")
  144. self.__run_command("sudo make install", cwd="ngx_openresty-1.2.7.5")
  145. #
  146. # Gunicorn
  147. #
  148. self.__run_command("sudo easy_install -U 'gunicorn==0.17.2'")
  149. self.__run_command("sudo easy_install -U 'eventlet==0.12.1'")
  150. self.__run_command("sudo pip install --upgrade 'gevent==0.13.8'")
  151. #
  152. # Resin
  153. #
  154. 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/")
  155. self.__run_command("curl http://www.caucho.com/download/resin-4.0.34.tar.gz | tar xvz")
  156. self.__run_command("./configure --prefix=`pwd`", cwd="resin-4.0.34")
  157. self.__run_command("make", cwd="resin-4.0.34")
  158. self.__run_command("make install", cwd="resin-4.0.34")
  159. self.__run_command("mv conf/resin.properties conf/resin.properties.orig", cwd="resin-4.0.34")
  160. self.__run_command("cat ../config/resin.properties > resin-4.0.34/conf/resin.properties")
  161. #
  162. # Passenger
  163. #
  164. self.__run_command("git clone https://github.com/FooBarWidget/passenger.git")
  165. self.__run_command("git checkout 65d36dbbadd399f65d81f5febadce9b0c6c1a430", cwd="passenger")
  166. subprocess.call(["bash", "-c", "cd installs/passenger && source ~/.rvm/scripts/'rvm' && rvm 2.0.0-p0 do gem build passenger.gemspec"])
  167. 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"])
  168. ##############################
  169. # Tomcat
  170. # We don't use tomcat in our tests yet, but this is here to remind us of how we
  171. # installed the apr connector
  172. ##############################
  173. 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")
  174. #wget http://apache.cs.utah.edu/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.tar.gz
  175. #tar -xvzf apache-tomcat-7.0.35.tar.gz
  176. #rm apache-tomcat-7.0.35.tar.gz
  177. # use the native APR
  178. # http://evgeny-goldin.com/blog/ubuntu-installing-apr-tomcat/
  179. #wget http://apache.claz.org/apr/apr-1.4.6.tar.gz
  180. #tar xvf apr-1.4.6.tar.gz
  181. #cd apr-1.4.6
  182. #./configure
  183. #make
  184. #sudo make install
  185. #cd ..
  186. #rm apr-1.4.6.tar.gz
  187. #wget http://apache.tradebit.com/pub/tomcat/tomcat-connectors/native/1.1.24/source/tomcat-native-1.1.24-src.tar.gz
  188. #tar xvf tomcat-native-1.1.24-src.tar.gz
  189. #cd tomcat-native-1.1.24-src/jni/native
  190. #./configure --with-apr=/usr/local/apr
  191. #make
  192. #sudo make install
  193. #cd ../../..
  194. #rm tomcat-native-1.1.24-src.tar.gz
  195. ##############################################################
  196. #
  197. # Frameworks
  198. #
  199. ##############################################################
  200. ##############################
  201. # Django
  202. ##############################
  203. self.__run_command("curl http://www.djangoproject.com/m/releases/1.4/Django-1.4.tar.gz | tar xvz")
  204. self.__run_command("sudo rm -rf /usr/local/lib/python2.7/site-packages/django")
  205. self.__run_command("sudo python setup.py install", cwd="Django-1.4")
  206. self.__run_command("sudo easy_install -U 'ujson==1.30'")
  207. ##############################
  208. # Grails
  209. ##############################
  210. self.__run_command("wget http://dist.springframework.org.s3.amazonaws.com/release/GRAILS/grails-2.1.1.zip")
  211. self.__run_command("unzip -o grails-2.1.1.zip")
  212. self.__run_command("rm grails-2.1.1.zip")
  213. ##############################
  214. # Flask
  215. ##############################
  216. self.__run_command("sudo pip install flask flask-sqlalchemy")
  217. ##############################
  218. # Play 2
  219. ##############################
  220. self.__run_command("wget http://downloads.typesafe.com/play/2.1.1/play-2.1.1.zip")
  221. self.__run_command("unzip -o play-2.1.1.zip")
  222. self.__run_command("rm play-2.1.1.zip")
  223. ##############################
  224. # Play 1
  225. ##############################
  226. self.__run_command("wget http://downloads.typesafe.com/releases/play-1.2.5.zip")
  227. self.__run_command("unzip -o play-1.2.5.zip")
  228. self.__run_command("rm play-1.2.5.zip")
  229. self.__run_command("mv play-1.2.5/play play-1.2.5/play1")
  230. # siena
  231. self.__run_command("play-1.2.5/play1 install siena", send_yes=True)
  232. ##############################
  233. # Vert.x
  234. ##############################
  235. self.__run_command("curl http://vertx.io/downloads/vert.x-1.3.1.final.tar.gz | tar xvz")
  236. ##############################
  237. # Yesod
  238. ##############################
  239. self.__run_command("cabal update")
  240. self.__run_command("cabal install yesod persistent-mysql")
  241. ##############################################################
  242. #
  243. # System Tools
  244. #
  245. ##############################################################
  246. ##############################
  247. # Maven
  248. ##############################
  249. self.__run_command("sudo apt-get install maven2", send_yes=True)
  250. ##############################
  251. # Leiningen
  252. ##############################
  253. self.__run_command("mkdir -p bin")
  254. self.__run_command("wget https://raw.github.com/technomancy/leiningen/stable/bin/lein")
  255. self.__run_command("mv lein bin/lein")
  256. self.__run_command("chmod +x bin/lein")
  257. ############################################################
  258. # End __install_server_software
  259. ############################################################
  260. ############################################################
  261. # __install_client_software
  262. ############################################################
  263. def __install_client_software(self):
  264. subprocess.call(self.benchmarker.sftp_string(batch_file="config/client_sftp_batch"), shell=True)
  265. remote_script = """
  266. ##############################
  267. # Prerequisites
  268. ##############################
  269. yes | sudo apt-get update
  270. yes | sudo apt-get install build-essential git libev-dev libpq-dev libreadline6-dev
  271. sudo sh -c "echo '* soft nofile 8192' >> /etc/security/limits.conf"
  272. ##############################
  273. # MySQL
  274. ##############################
  275. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  276. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  277. yes | sudo apt-get install mysql-server
  278. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  279. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  280. sudo mv my.cnf /etc/mysql/my.cnf
  281. sudo restart mysql
  282. # Insert data
  283. mysql -uroot -psecret < create.sql
  284. ##############################
  285. # Weighttp
  286. ##############################
  287. git clone git://git.lighttpd.net/weighttp
  288. cd weighttp
  289. ./waf configure
  290. ./waf build
  291. sudo ./waf install
  292. cd ~
  293. ##############################
  294. # wrk
  295. ##############################
  296. git clone https://github.com/wg/wrk.git
  297. cd wrk
  298. make
  299. sudo cp wrk /usr/local/bin
  300. cd ~
  301. ##############################
  302. # MongoDB
  303. ##############################
  304. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
  305. sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list
  306. sudo apt-get update
  307. yes | sudo apt-get install mongodb-10gen
  308. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  309. sudo mv mongodb.conf /etc/mongodb.conf
  310. sudo restart mongodb
  311. """
  312. p = subprocess.Popen(self.benchmarker.ssh_string.split(" "), stdin=subprocess.PIPE)
  313. p.communicate(remote_script)
  314. ############################################################
  315. # End __parse_results
  316. ############################################################
  317. ############################################################
  318. # __run_command
  319. ############################################################
  320. def __run_command(self, command, send_yes=False, cwd=None):
  321. try:
  322. cwd = os.path.join(self.install_dir, cwd)
  323. except AttributeError:
  324. cwd = self.install_dir
  325. if send_yes:
  326. subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd).communicate("yes")
  327. else:
  328. subprocess.call(command, shell=True, cwd=cwd)
  329. ############################################################
  330. # End __run_command
  331. ############################################################
  332. ############################################################
  333. # __init__(benchmarker)
  334. ############################################################
  335. def __init__(self, benchmarker):
  336. self.benchmarker = benchmarker
  337. self.install_dir = "installs"
  338. try:
  339. os.mkdir(self.install_dir)
  340. except OSError:
  341. pass
  342. ############################################################
  343. # End __init__
  344. ############################################################