added start-fc-epl-monitor.sh.
[oweals/finalsclub.git] / util / boot.sh
1 #!/bin/bash
2
3 cd /root
4
5 if test ! -e "reset.sh" ; then
6 cat > "reset.sh" << FIN
7 #!/bin/bash
8 curl https://s3.amazonaws.com/finalsclub.org/boot.sh | sh
9 FIN
10 chmod 500 reset.sh
11 fi
12
13
14 echo "Booting" `date` 
15
16 yes | yum --nogpgcheck install gcc-c++
17 yes | yum --nogpgcheck install openssl-devel
18 yes | yum --nogpgcheck install make
19 yes | yum --nogpgcheck install git
20 yes | yum --nogpgcheck install sqlite-devel
21
22 yes | yum --nogpgcheck install mysql-server
23 # /etc/init.d/mysqld start
24 # /usr/bin/mysqladmin -u root password 'foobarbazquX'
25
26 # install mongodb
27 mongover="1.8.2"
28 if test ! -e mongodb.tgz ; then
29         curl http://fastdl.mongodb.org/linux/mongodb-linux-i686-$mongover.tgz > mongodb-linux-i686-$mongover.tgz
30         tar xzf mongodb-linux-i686-$mongover.tgz
31         cd mongodb-linux-i686-$mongover/bin
32         chmod a+rx *
33         chmod uo-w *
34         cp -f * /usr/local/bin
35         mkdir -p /data/db
36         /usr/local/bin/mongod -v --rest --replSet finalsclubset &> /var/log/mongod.log &
37
38         ## optional arbiter start command
39         ## mkdir -p /data/arbiterdb
40         ## /usr/local/bin/mongod -v --dbpath /data/arbiterdb --port 27021 --rest --replSet finalsclubset &> /var/log/mongod-arbiter.log &
41 fi
42
43
44 # install node
45 nodever="v0.4.10"
46 if test ! -e node-$nodever ; then
47         curl http://nodejs.org/dist/node-$nodever.tar.gz > node-$nodever.tar.gz
48         tar xzvf node-$nodever.tar.gz
49         cd node-$nodever
50         ./configure
51         make
52         make install
53 fi
54
55 # install npm
56 if test ! -e npm ; then
57         git clone http://github.com/isaacs/npm.git
58         cd npm
59         sudo make install
60         cd ..
61 fi
62
63 npm install nodemon -g
64 npm install forever -g
65
66 ## make it easier for root to run node
67 cd /usr/bin
68 ln -sf /usr/local/bin/node .
69 ln -sf /usr/local/bin/forever .
70
71
72
73 ## haproxy install (optional) 
74 # assumes this script is running as root
75 mkdir /usr/local/haproxy
76 cd /usr/local/haproxy
77 wget http://haproxy.1wt.eu/download/1.4/bin/haproxy-1.4.17-pcre-40kses-linux-i586.notstripped.gz
78 gunzip haproxy-1.4.17-pcre-40kses-linux-i586.notstripped.gz
79 ln -sf haproxy-1.4.17-pcre-40kses-linux-i586.notstripped haproxy
80 chmod 770 haproxy*
81 wget https://s3.amazonaws.com/finalsclub.org/haproxy.cfg 
82 chmod 660 haproxy.cfg
83
84 ## command to start haproxy (from /usr/local/haproxy dir)
85 #  sudo /usr/local/haproxy/haproxy -f /usr/local/haproxy/haproxy.cfg -p /var/run/haproxy.pid &
86
87
88 ## init the reboot-restart.sh script, but don't run it.
89 cd ~
90 wget https://s3.amazonaws.com/finalsclub.org/reboot-restart.sh
91 chmod 755 reboot-restart.sh
92 echo "/root/reboot-restart.sh &> /var/log/fc-reboot-restart.log.txt &" >> /etc/rc.local
93         
94
95 curl https://s3.amazonaws.com/finalsclub.org/start.sh | sudo -u ec2-user sh
96