Making nginx and uwsgi service start when run docker by using supervisor 47/25447/1
authorchenjiankun <chenjiankun1@huawei.com>
Sat, 3 Dec 2016 15:04:36 +0000 (15:04 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Sat, 3 Dec 2016 15:04:36 +0000 (15:04 +0000)
JIRA: YARDSTICK-444

We need web service start when docker run.
But now we add command in bashrc, so the web service start only if we
login in docker container.
So I use supervisor to make the web service start when docker run.

Change-Id: Ic77eb0e130ae7dbd82039c312649fed76b128513
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/api-prepare.sh
docker/Dockerfile
install.sh

index c05dbb5..fade8cc 100755 (executable)
@@ -24,14 +24,26 @@ server {
     }
 }
 EOF
+echo "daemon off;" >> /etc/nginx/nginx.conf
 fi
 
 # nginx service start when boot
-cat << EOF >> /root/.bashrc
+supervisor_config='/etc/supervisor/conf.d/yardstick.conf'
 
-nginx_status=\$(service nginx status | grep not)
-if [ -n "\${nginx_status}" ];then
-    service nginx restart
-    uwsgi -i /home/opnfv/repos/yardstick/api/yardstick.ini
-fi
+if [[ ! -e "${supervisor_config}" ]];then
+    cat << EOF > "${supervisor_config}"
+[supervisord]
+nodaemon = true
+
+[program:yardstick_nginx]
+user = root
+command = service nginx restart
+autorestart = true
+
+[program:yardstick_uwsgi]
+user = root
+directory = /home/opnfv/repos/yardstick/api
+command = uwsgi -i yardstick.ini
+autorestart = true
 EOF
+fi
index 048804d..3dd9401 100644 (file)
@@ -48,6 +48,7 @@ RUN apt-get update && apt-get install -y \
     nginx \
     uwsgi \
     uwsgi-plugin-python \
+    supervisor \
     python-setuptools && \
     easy_install -U setuptools
 
@@ -73,3 +74,4 @@ ADD http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img /home/op
 ADD http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img /home/opnfv/images/
 
 COPY ./exec_tests.sh /usr/local/bin/
+CMD ["/usr/bin/supervisord"]
index afb7351..e9b6035 100755 (executable)
@@ -16,6 +16,7 @@ apt-get update && apt-get install -y \
     nginx \
     uwsgi \
     uwsgi-plugin-python \
+    supervisor \
     python-setuptools && \
     easy_install -U setuptools