Checking in changes made in-place on the server to be merged
[oweals/finalsclub.git] / util / boot.sh
1 #!/bin/bash
2
3
4 ################################################################
5 ##  Finals Club instance set up notes by Joe Snow 11/19/2011
6 ################################################################
7 ##  these are the steps I take to create a new fc instance
8 ##  log into aws, launch new AMI instance
9 ##  ssh into machine
10 ##  sudo to root
11 ##  download and run boot.sh (this file -- either from s3 or ssh), this can take 10 minutes
12 ##  NOTE: start.sh usually fails due to env vars, etc..
13 ##  as ec2-user, run start.sh
14 ##  add arbiter db config, and mongo replicated set config, import mongo data using mongorestore command
15 ##    I usually create and grab the latest mongodb backup from S3 (created from existing live server)
16 ##  add dev public keys to /home/ec2-user/.ssh/authorized_keys
17 ##  update /home/ec2-user/.bashrc with AWS env vars
18 ##  add /home/ec2-user/fc/fcbackup/.fcbackup.env (populated with AWS env vars)
19 ##  restart fc app
20 ##  add crontab, using fc/util/crontab-example.txt as example as needed.
21 ##  update cloudwatch monitors for cpu, disk, etc..
22 ##  as root, start epl monitor script in /home/ec2-user/fc/util/start-fc-epl-monitor.sh
23 ##  check app health and switch DNS as desired
24 ################################################################
25
26 cd /root
27
28 if test ! -e "reset.sh" ; then
29 cat > "reset.sh" << FIN
30 #!/bin/bash
31 curl https://s3.amazonaws.com/finalsclub.org/boot.sh | sh
32 FIN
33 chmod 500 reset.sh
34 fi
35
36
37 echo "Booting" `date` 
38
39 yes | yum --nogpgcheck install gcc-c++
40 yes | yum --nogpgcheck install openssl-devel
41 yes | yum --nogpgcheck install make
42 yes | yum --nogpgcheck install git
43 yes | yum --nogpgcheck install sqlite-devel
44
45 yes | yum --nogpgcheck install mysql-server
46 # /etc/init.d/mysqld start
47 # /usr/bin/mysqladmin -u root password 'foobarbazquX'
48
49 # install mongodb
50 mongover="1.8.2"
51 if test ! -e mongodb.tgz ; then
52         curl http://fastdl.mongodb.org/linux/mongodb-linux-i686-$mongover.tgz > mongodb-linux-i686-$mongover.tgz
53         tar xzf mongodb-linux-i686-$mongover.tgz
54         cd mongodb-linux-i686-$mongover/bin
55         chmod a+rx *
56         chmod uo-w *
57         cp -f * /usr/local/bin
58         mkdir -p /data/db
59         /usr/local/bin/mongod -v --rest --replSet finalsclubset &> /var/log/mongod.log &
60
61         ## optional arbiter start command
62         ## mkdir -p /data/arbiterdb
63         ## /usr/local/bin/mongod -v --dbpath /data/arbiterdb --port 27021 --rest --replSet finalsclubset &> /var/log/mongod-arbiter.log &
64
65         #### NOTE: the replicated set name could change or increment, for example we might be using finalsclubset4 instead of finalsclubset
66
67         ## example to set up new clean replicated set
68         ## as ec2-user
69         ## mongo                                                                        ### start mongo cli util from bash prompt
70         ## > rs.initiate()                                                      ## init the replicated set (assumes you are starting a new clean replicated set)
71         ## > rs.addArb("ip-10-166-206-34:27021")        ## assumes arbiter instance was started previously on specified port, IP for example only, use same machineID
72         ## > rs.status()                                                        ## confirm both instances are in set
73 fi
74
75
76
77
78 # install node
79 nodever="v0.4.10"
80 if test ! -e node-$nodever ; then
81                 curl http://nodejs.org/dist/node-$nodever.tar.gz > node-$nodever.tar.gz
82                 tar xzvf node-$nodever.tar.gz
83                 cd node-$nodever
84                 ./configure
85                 make
86                 make install
87 fi
88
89 # install npm
90 if test ! -e npm ; then
91                 git clone http://github.com/isaacs/npm.git
92                 cd npm
93                 sudo make install
94                 cd ..
95 fi
96
97 npm install nodemon -g
98 npm install forever -g
99
100 ## make it easier for root to run node
101 cd /usr/bin
102 ln -sf /usr/local/bin/node .
103 ln -sf /usr/local/bin/forever .
104
105
106
107 ## haproxy install (optional) 
108 # assumes this script is running as root
109 mkdir /usr/local/haproxy
110 cd /usr/local/haproxy
111 wget http://haproxy.1wt.eu/download/1.4/bin/haproxy-1.4.17-pcre-40kses-linux-i586.notstripped.gz
112 gunzip haproxy-1.4.17-pcre-40kses-linux-i586.notstripped.gz
113 ln -sf haproxy-1.4.17-pcre-40kses-linux-i586.notstripped haproxy
114 chmod 770 haproxy*
115 wget https://s3.amazonaws.com/finalsclub.org/haproxy.cfg 
116 chmod 660 haproxy.cfg
117
118 ## command to start haproxy (from /usr/local/haproxy dir)
119 #  sudo /usr/local/haproxy/haproxy -f /usr/local/haproxy/haproxy.cfg -p /var/run/haproxy.pid &
120
121
122 ## init the reboot-restart.sh script, but don't run it.
123 cd ~
124 wget https://s3.amazonaws.com/finalsclub.org/reboot-restart.sh
125 chmod 755 reboot-restart.sh
126 echo "/root/reboot-restart.sh &> /var/log/fc-reboot-restart.log.txt &" >> /etc/rc.local
127         
128
129 ## NOTE: each time, I've had to run this step manually, as the ec2-user, after env vars have been set up
130 cd /home/ec2-user
131 curl https://s3.amazonaws.com/finalsclub.org/start.sh | sudo -u ec2-user sh
132