Celery flower doesn't work under supervisor managment
<p>I have Ubuntu 14.04.4 LTS running as a vagrant environment under virtualbox. In this box I have this configuration:</p>

<ul>
<li><p>supervisor 3.0b2</p></li>
<li><p>python 3.4 under virtualenvironment</p></li>
<li><p>celery 3.1.23</p></li>
<li><p>flower 0.9.1</p></li>
</ul>

<p>A flower configuration under supervisor is:</p>

<pre><code>[program:flower]
command=/home/vagrant/.virtualenvs/meridian/bin/python /vagrant/meridian/meridian/manage.py celery flower --loglevel=INFO -conf=/vagrant/meridian/meridian/meridian/flowerconfig.py
directory=/vagrant/meridian/meridian
user=vagrant
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/flower-stdout.log
stderr_logfile=/var/log/supervisor/flower-stderr.log
priority=997
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
</code></pre>

<p>The flowerconfig.py is an empty file. So all the values are default. Host is localhost and port is 5555.</p>

<p>When I run flower from a command line:</p>

<blockquote>
  <p>vagrant@localhost> flower</p>
</blockquote>

<p>it is run as it should and I see the tasks result in my browser, visiting an address localhost:5555.</p>

<p>netstat shows me the ports that are listened:</p>

<blockquote>
  <p>vagrant@localhost> netstat -l | grep 5555</p>
</blockquote>

<pre><code>tcp        0      0 *:5555                  *:*                     LISTEN
tcp6       0      0 [::]:5555               [::]:*                  LISTEN
</code></pre>

<p>So, it is OK. </p>

<p>When I run flowe under supervisor in this way:</p>

<blockquote>
  <p>vagrant@localhost> sudo supervisorctl start flower</p>
</blockquote>

<p>it starts as it should. Netstat shows that port 5555 are listened. But a query from a browser just hangs. </p>

<p>Why flower doesn't reply under supervisor ?</p>

<p>I have found a solution. 
The problem was that I ran flower not under my virtual environment. I added a shell file "start_flower.sh":</p>

<pre><code>source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
source /home/vagrant/.virtualenvs/meridian/bin/activate
workon meridian
exec flower --conf=/vagrant/meridian/meridian/meridian/flowerconfig.py
</code></pre>

<p>and it started works as it should.</p>

<p>Then I rewrited supervisor's configuration for flower in this way:</p>

<pre><code>[program:flower]
command=bash -c "/vagrant/meridian/meridian/start_flower.sh"
directory=/vagrant/meridian/meridian
user=vagrant
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/flower-stdout.log
stderr_logfile=/var/log/supervisor/flower-stderr.log
priority=997
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=5
stopasgroup=true 
killasgroup=true
</code></pre>

<p>and now everything is good.</p>

<p>Note: I want to draw your attention to fact that I run flower in shell file with "exec":</p>

<pre><code>exec flower --conf=/vagrant/meridian/meridian/meridian/flowerconfig.py
</code></pre>

<p>I use this there because when I use that construction:</p>

<pre><code>flower --conf=/vagrant/meridian/meridian/meridian/flowerconfig.py
</code></pre>

<p>I had a problew - shell file process was terminated with:</p>

<pre><code>sudo supervisorctl stop flower
</code></pre>

<p>But flower process was working anyway!</p>

<p>So if you would face with such kind of problem always use 'exec'.
This is a good additional information for such cases:</p>

<p><a href="http://veithen.github.io/2014/11/16/sigterm-propagation.html" rel="nofollow">http://veithen.github.io/2014/11/16/sigterm-propagation.html</a></p>

python celery supervisord flower