Merge "vnfdgen: replace yaml.load with yaml.safe_load"
[yardstick.git] / api / api-prepare.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 : ${YARDSTICK_REPO_DIR:='/home/opnfv/repos/yardstick'}
12
13 # generate uwsgi config file
14 mkdir -p /etc/yardstick
15 uwsgi_config='/etc/yardstick/yardstick.ini'
16 if [[ ! -e "${uwsgi_config}" ]];then
17
18     cat << EOF > "${uwsgi_config}"
19 [uwsgi]
20 master = true
21 debug = true
22 chdir = ${YARDSTICK_REPO_DIR}/api
23 module = server
24 plugins = python
25 processes = 10
26 threads = 5
27 async = true
28 max-requests = 5000
29 chmod-socket = 666
30 callable = app_wrapper
31 enable-threads = true
32 close-on-exec = 1
33 daemonize= /var/log/yardstick/uwsgi.log
34 socket = /var/run/yardstick.sock
35 EOF
36     if [[ "${YARDSTICK_VENV}" ]];then
37         echo "virtualenv = ${YARDSTICK_VENV}" >> "${uwsgi_config}"
38     fi
39 fi
40
41 # nginx config
42 nginx_config='/etc/nginx/conf.d/yardstick.conf'
43
44 if [[ ! -e "${nginx_config}" ]];then
45
46     cat << EOF > "${nginx_config}"
47 server {
48     listen 5000;
49     server_name localhost;
50     index  index.htm index.html;
51     location / {
52         include uwsgi_params;
53         uwsgi_pass unix:///var/run/yardstick.sock;
54     }
55 }
56 EOF
57 fi
58
59 # nginx service start when boot
60 supervisor_config='/etc/supervisor/conf.d/yardstick.conf'
61
62 if [[ ! -e "${supervisor_config}" ]];then
63     cat << EOF > "${supervisor_config}"
64 [supervisord]
65 nodaemon = true
66
67 [program:yardstick_nginx]
68 user = root
69 command = service nginx restart
70 autorestart = true
71
72 [program:yardstick_uwsgi]
73 user = root
74 directory = /etc/yardstick
75 command = uwsgi -i yardstick.ini
76 autorestart = true
77 EOF
78 fi
79
80 # create api log directory
81 mkdir -p /var/log/yardstick
82
83 # create yardstick.sock for communicating
84 touch /var/run/yardstick.sock