Skip to content

Commit

Permalink
Merge pull request #61 from telefonicaid/feature/CLAUDIA-5625_supervisor
Browse files Browse the repository at this point in the history
Instructions and scripts to run with supervisor.
  • Loading branch information
Fernando López Aguilar committed Dec 10, 2015
2 parents 6c74bc5 + 1504c08 commit 8409713
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
45 changes: 44 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,50 @@ in that folder.

mkdir -m /var/log/fiware-facts

Top_.
Running with supervisor
-----------------------

Optionally you can add a new layer to manage gunicorn proccess with a supervisor.
Just install supervisor on your system:

::

sudo apt-get install supervisor

Copy the file ``utils/facts_start`` to ``/etc/fiware.d``.
Make this script executable:

::

sudo chmod a+x /etc/fiware.d/facts_start

Copy the file ``utils/fiware-facts.conf`` to ``/etc/supervisor/conf.d``.

Start fiware-facts using supervisor:

::

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start fiware-facts

To stop fiware-facts just execute:

::

sudo supervisorctl stop fiware-facts

NOTE:
Supervisor provides an “event listener” to subscribe to “event notifications”.
The purpose of the event notification/subscription system is to provide a mechanism for
arbitrary code to be run (e.g. send an email, make an HTTP request, etc)
when some condition is satisfied. That condition usually has to do with subprocess state.
For instance, you may want to notify someone via email when a process crashes and is restarted by Supervisor.
For more information check also the `Supervisor Documentation`__

__ `Supervisor Documentation`_

Top_.

API Overview
============
Expand Down Expand Up @@ -397,3 +439,4 @@ License
.. _Fiware-Facts: https://github.com/telefonicaid/fiware-facts
.. _stackoverflow: http://stackoverflow.com/questions/ask
.. _`FIWARE Q&A`: https://ask.fiware.org
.. _Supervisor Documentation: http://supervisord.org/events.html
47 changes: 47 additions & 0 deletions utils/facts_start
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
# -*- encoding: utf-8 -*-
#
# Copyright 2014 Telefónica Investigación y Desarrollo, S.A.U
#
# This file is part of FI-WARE project.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with [email protected]
#
# File to execute fiware-facts component
#
NAME="fiware_facts" # Name of the application
SOCKFILE=/var/run/gunicorn.sock # we will communicate using this unix socket
USER=root # the user to run as
GROUP=root # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_WSGI_MODULE=facts.server:app # WSGI module name
LOCAL_IP=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'`

echo "Starting $NAME as `whoami`"

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

exec gunicorn ${DJANGO_WSGI_MODULE} \
-b $LOCAL_IP:5000 \
--bind=unix:$SOCKFILE \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-file=-
6 changes: 6 additions & 0 deletions utils/fiware-facts.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[program:fiware-facts]
command = /etc/fiware.d/facts_start ; Command to start app
user = root ; User to run as
stdout_logfile = /var/log/fiware-facts/gunicorn_supervisor.log ; Where to write log messages
redirect_stderr = true ; Save stderr in the same log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8 ; Set UTF-8 as default encoding

0 comments on commit 8409713

Please sign in to comment.