#!/bin/bash #To initiate this script, remember to dos2unix if on windows, then run the following, #where $USER and $IP is the default username and IP of your remote Ubuntu 12.04 machine: #scp assemble.sh $USER@$IP:/home/$USER/ && ssh $USER@$IP 'bash ./assemble.sh' #NODE=http://nodejs.org/dist/v0.8.15/node-v0.8.15-linux-x64.tar.gz #binary NODE=http://nodejs.org/dist/v0.8.15/node-v0.8.15.tar.gz MONGO=http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.1.tgz REDIS=http://redis.googlecode.com/files/redis-2.6.6.tar.gz PHANTOM=http://phantomjs.googlecode.com/files/phantomjs-1.5.0-linux-x86_64-dynamic.tar.gz ZMQ=http://download.zeromq.org/zeromq-3.2.0-rc1.tar.gz IP=`curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'` USER=`whoami` echo "creating theory" cd ~ if [ -d theory ]; then echo "theory folder already exists" else mkdir theory fi echo "getting core" sudo apt-get update -y sudo apt-get install wget curl zsh git-core build-essential openssl libssl-dev upstart monit libtool autoconf uuid-dev lvm2 xfsprogs -y sudo apt-get install mdadm --no-install-recommends -y cd ~/theory if [ -e /usr/local/bin/node ]; then echo "node already installed." else #TODO: REPLACE THE FOLLOWING BUILD WITH NAVE INSTEAD, TO MAKE THINGS FAST! echo "installing node" wget -O node.tar.gz $NODE mkdir node tar -zxf node.tar.gz -C node --strip-components 1 cd node ./configure make sudo make install echo "node installed" fi cd ~/theory if [ -e /data/db ]; then echo "drives already configured" else #Mark's version echo "configuring drives" DRIVES=`sudo node -e "var proc = require('child_process'); proc.exec('lsblk -l',function(e,stdout){ stdout = stdout.split(/\n/g);var s=''; for(var i=1; i /proc/sys/net/ipv4/ip_local_port_range echo "fs.file-max = 999999 net.ipv4.tcp_rmem = 4096 4096 16777216 net.ipv4.tcp_wmem = 4096 4096 16777216" | sudo tee - a /etc/sysctl.conf sudo mv /etc/cron.weekly/apt-xapian-index /etc/cron.monthly/apt-xapian-index PWD=`pwd` echo "creating and initializing code" sudo ln -s $PWD /usr/local/bin/theory mkdir code echo "var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World'); }).listen(80);console.log('running at 80');" > code/init.js mkdir git cd git git init --bare PWD=`pwd` echo "====== DO LOCALLY ======" echo "git init" echo "git add ." echo "git commit -m 'init'" echo "git remote add web ssh://$USER@$IP$PWD" echo "git push web master" echo "====== END LOCAL ======" echo "#!/bin/sh sudo stop theory GIT_WORK_TREE=/usr/local/bin/theory/code git checkout -f sudo start theory echo 'deployed'" > hooks/post-receive chmod +x hooks/post-receive cd ~/theory sudo echo "limit nofile 999999 999999 description 'start theory' author 'theory' start on runlevel [2345] stop on shutdown respawn script sudo NODE_ENV=production /usr/local/bin/node /usr/local/bin/theory/code/init.js >> /var/log/theory.log 2>&1 end script" > theory.conf sudo mv theory.conf /etc/init/ sudo echo "set daemon 7 include /etc/monit/conf.d/* check system theory set httpd port 8080 and allow theory:symphony " > monitrc sudo mv monitrc /etc/monit/ sudo echo "check host theory_init with address 127.0.0.1 start program = '/sbin/start theory' stop program = '/sbin/stop theory' if failed port 80 protocol HTTP request / with timeout 2 seconds then restart " > theory sudo mv theory /etc/monit/conf.d/ sudo chown -fR ubuntu ~/theory sudo chown -fR $USER ~/theory fi sudo start theory echo "DONE :) $IP" # STUFF TO WORK ON: #SCALE ON: (in node) #os.freemem() / os.totalmem() 80% ~ 100% for a few days #node-aws auto controls