Various updates; Add logAxis patch for graphite; Add namespaces to summary scripts.
[myops.git] / web / setup.sh
1 #/bin/bash
2
3 # todo: ssl support is not default for apache.
4 #      + update scripts to allow both https/http.
5 #      + add log axis patch. 
6
7
8 ########################################3
9
10 if [ -z "$SETUP_IP" ] ; then
11         export IP=`ip addr show eth0 | grep -E "eth0$|eth0:[[:digit:]]+$" | tr '/' ' ' | awk '{print $2}'`
12 else
13         export IP=$SETUP_IP
14 fi
15 if [ -z "$SETUP_HOST" ] ; then
16         if ! rpm -q bind-utils > /dev/null ; then
17                 yum install -y bind-utils
18         fi
19         export HOST=`host $IP | cut -d ' ' -f 5 | tr [A-Z] [a-z] | sed -e 's/\.$//g'`
20 else 
21         export HOST=$SETUP_HOST
22 fi
23
24 echo "---------------------------------------------------------------"
25 echo "setup.sh will configure your system using the following values:"
26 echo "IP:       $IP"
27 echo "HOSTNAME: $HOST"
28 echo ""
29 echo "You can manually set the IP and HOST, by setting shell variables:"
30 echo "export SETUP_IP="
31 echo "export SETUP_HOST="
32 echo "Proceed? (yes/no):"
33 while read userinput ; do 
34         if [[ -z "$userinput" ]] ; then
35                 echo "Assuming this is correct."
36                 break
37         fi
38         if [[ "$userinput" = "yes" || "$userinput" = "y" ]] ; then
39                 break
40         fi
41         if [[ "$userinput" = "no" || "$userinput" = "n" ]] ; then
42                 exit
43         fi
44 done
45
46 if ! rpm -q bzr &> /dev/null ;  then 
47         echo "bzr is not installed"
48         exit    
49 fi
50
51 if [ ! -d graphite ] ; then 
52         # just picked latest revno on 6/27/2011 for a static config
53         echo "bzr branch -r revno:409 lp:graphite"
54         bzr branch -r revno:409 lp:graphite
55         ./check-dependencies.py 
56 fi
57
58 if [ ! -d deps ] ; then
59         cd graphite/
60         mkdir deps
61         pushd deps/
62
63     wget http://myops.planet-lab.org/files/graphite-web-0.9.8.tar.gz
64     wget http://myops.planet-lab.org/files/carbon-0.9.8.tar.gz
65     wget http://myops.planet-lab.org/files/whisper-0.9.8.tar.gz
66     wget http://myops.planet-lab.org/files/python-txamqp_0.3.orig.tar.gz
67
68         tar -xvf python-txamqp_0.3.orig.tar.gz 
69         tar -zxvf whisper-0.9.8.tar.gz 
70         tar -zxvf carbon-0.9.8.tar.gz 
71         tar -zxvf graphite-web-0.9.8.tar.gz 
72
73         pushd python-txamqp-0.3/
74         python setup.py install
75         popd
76
77         pushd whisper-0.9.8
78         python setup.py install
79         popd
80
81         pushd carbon-0.9.8
82         python setup.py install
83         popd
84
85         pushd graphite-web-0.9.8
86         python setup.py install
87         cp examples/example-graphite-vhost.conf /etc/httpd/conf.d/graphite-vhost.conf
88
89         sed -i -e 's|WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi|WSGIScriptAlias /graphite /opt/graphite/conf/graphite.wsgi|g' /etc/httpd/conf.d/graphite-vhost.conf
90         echo "WSGISocketPrefix /var/run/" >> /etc/httpd/conf.d/graphite-vhost.conf
91         echo "RedirectMatch ^/graphite$ /graphite/" >> /etc/httpd/conf.d/graphite-vhost.conf
92
93         # move /opt/graphite/webapp refs to /var/www/html
94         ln -s /opt/graphite/webapp/content/ /var/www/html/
95         ln -s /opt/graphite/webapp/graphite/ /var/www/html/
96         ln -s /opt/graphite/webapp/graphite_web-0.9.8-py2.6.egg-info /var/www/html/
97         sed -i -e 's|DocumentRoot ".*|DocumentRoot "/var/www/html"|g' /etc/httpd/conf.d/graphite-vhost.conf
98         sed -i -e 's|Alias /content/ .*|Alias /content/ /var/www/html/content/|g' /etc/httpd/conf.d/graphite-vhost.conf
99         cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi
100         cp /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
101         cp /opt/graphite/webapp/graphite/render/graphTemplates.conf /opt/graphite/conf
102         cp /usr/share/myops/web/view/storage-schemas.conf /opt/graphite/conf/
103
104         popd
105
106         popd # deps
107         ./check-dependencies.py 
108
109 fi
110
111 # NOTE: TEMP hack for testing...
112 #sed -i -e 's/2003/3003/g' -e 's/2004/3004/g' -e 's/7002/6002/g' /opt/graphite/conf/carbon.conf
113 #sed -i -e 's/2003/3003/g' /usr/bin/sar2graphite.py
114 #sed -i -e 's/2003/3003/g' /usr/share/myops/web/collect/server/*.py
115
116 # setup db for graphite application
117 cd /opt/graphite/webapp/graphite
118 /usr/bin/yes "no" | python manage.py syncdb
119
120 # start carbon cache
121 cd /opt/graphite/bin
122 chown -R apache.apache  /opt/graphite/storage/
123 ./carbon-cache.py start
124
125 # restart on reboot
126 if ! grep carbon-cache /etc/rc.local ; then
127
128         cat <<EOF >> /etc/rc.local
129 cd /opt/graphite/bin
130 ./carbon-cache.py start
131 EOF
132
133 fi
134
135
136 sed -i -e 's/HOSTNAME/'$HOST'/g' /var/www/html/PlanetLabConf/sysstat.cron
137 sed -i -e 's/HOSTNAME/'$HOST'/g' /etc/cron.d/sysstat.cron
138 sed -i -e 's/HOSTNAME/'$HOST'/g' /usr/share/myops/web/collect/server/load-graphite.py
139 sed -i -e 's/HOSTNAME/'$HOST'/g' /var/www/html/view/urllist.txt
140 sed -i -e 's/HOSTNAME/'$HOST'/g' /etc/cron.hourly/load_all_couchdb.sh
141
142 # QUERY/COUCHAPP
143
144 wget http://python-distribute.org/distribute_setup.py
145 python distribute_setup.py
146 easy_install pip
147
148 #OMFG, couchapp install requires gcc...
149 yum groupinstall -y Development\ Tools
150 # for ONE .c file!
151
152 pip install couchapp
153
154 sed -i -e 's/;bind_address = 127.0.0.1/bind_address = '$IP'/g' /etc/couchdb/local.ini
155 export PASSWORD=couchpass$RANDOM
156 sed -i -e 's/;admin = .*/admin = '$PASSWORD'/g' /etc/couchdb/local.ini
157
158 service couchdb restart
159 chkconfig couchdb on
160
161 # give couch server time to boot up
162 sleep 10
163 pushd /usr/share/myops/web/query
164 echo "couchapp push . http://admin:$PASSWORD@$HOST:5984/myops"
165 couchapp push . http://admin:$PASSWORD@$HOST:5984/myops
166
167 # COLLECT; probably need a better way to set IPADDR...
168 sed -i -e 's/IPADDR/'$IP'/g' /usr/share/myops/web/collect/client/collect.sh
169 sed -i -e 's/IPADDR/'$IP'/g' /usr/share/myops/web/collect/client/upload.sh
170 sed -i -e 's/IPADDR/'$IP'/g' /usr/share/myops/web/collect/client/update.sh
171 sed -i -e 's/IPADDR/'$IP'/g' /usr/share/myops/web/collect/server/load_couch.py
172
173 ln /usr/share/myops/web/collect/client/update.sh /var/www/html/PlanetLabConf/myops_update_sh
174
175 /usr/share/myops/web/collect/server/build.sh
176
177 if [ ! -f /etc/httpd/conf.d/php.conf ] ; then
178         # enable php scripts
179         cp /usr/share/myops/web/collect/server/php.conf /etc/httpd/conf.d/php.conf
180 fi
181
182 mkdir -p /var/www/html/uploadlogs/raw
183 chown -R apache.apache /var/www/html/uploadlogs
184
185 chkconfig crond on
186 service crond start
187
188 chkconfig httpd on
189 service httpd start
190
191 # NOTE: there are other logging servers...  :-/
192 chkconfig sysklogd on
193 service sysklogd start