712ad8361eac5590e260f7744c54bb7b1cc58ce5
[yardstick.git] / api / api-prepare.sh
1 #!/bin/bash
2
3 # yardstick output config
4 output_config='/etc/yardstick/yardstick.conf'
5
6 if [[ ! -e "${output_config}" ]];then
7     gateway_ip=$(ip route | grep default | awk '{print $3}')
8     echo "${gateway_ip}"
9
10     install -d /etc/yardstick -m 0755 -o root
11
12     cat << EOF >> "${output_config}"
13 [DEFAULT]
14 debug = True
15 dispatcher = influxdb
16
17 [dispatcher_file]
18 file_path = /tmp/yardstick.out
19
20 [dispatcher_http]
21 timeout = 5
22 # target = http://127.0.0.1:8000/results
23
24 [dispatcher_influxdb]
25 timeout = 5
26 target = http://${gateway_ip}:8086
27 db_name = yardstick
28 username = root
29 password = root
30 EOF
31 fi
32
33 # nginx config
34 nginx_config='/etc/nginx/conf.d/yardstick.conf'
35
36 if [[ ! -e "${nginx_config}" ]];then
37
38     cat << EOF >> "${nginx_config}"
39 server {
40     listen 5000;
41     server_name localhost;
42     index  index.htm index.html;
43     location / {
44         include uwsgi_params;
45         uwsgi_pass unix:///home/opnfv/repos/yardstick/api/yardstick.sock;
46     }
47 }
48 EOF
49 fi
50
51 # nginx service start when boot
52 cat << EOF >> /root/.bashrc
53
54 nginx_status=\$(service nginx status | grep not)
55 if [ -n "\${nginx_status}" ];then
56     service nginx restart
57     uwsgi -i /home/opnfv/repos/yardstick/api/yardstick.ini
58 fi
59 EOF