operation_general: fix logging to use %s
[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 fi
37
38 # nginx config
39 nginx_config='/etc/nginx/conf.d/yardstick.conf'
40
41 if [[ ! -e "${nginx_config}" ]];then
42
43     cat << EOF > "${nginx_config}"
44 server {
45     listen 5000;
46     server_name localhost;
47     index  index.htm index.html;
48     location / {
49         include uwsgi_params;
50         uwsgi_pass unix:///var/run/yardstick.sock;
51     }
52 }
53 EOF
54 fi
55
56 # nginx service start when boot
57 supervisor_config='/etc/supervisor/conf.d/yardstick.conf'
58
59 if [[ ! -e "${supervisor_config}" ]];then
60     cat << EOF > "${supervisor_config}"
61 [supervisord]
62 nodaemon = true
63
64 [program:yardstick_nginx]
65 user = root
66 command = service nginx restart
67 autorestart = true
68
69 [program:yardstick_uwsgi]
70 user = root
71 directory = /etc/yardstick
72 command = uwsgi -i yardstick.ini
73 autorestart = true
74 EOF
75 fi
76
77 # create api log directory
78 mkdir -p /var/log/yardstick
79
80 # create yardstick.sock for communicating
81 touch /var/run/yardstick.sock