Note that there are some explanatory texts on larger screens.

plurals
  1. PObest way to setup a webhook to restart apache for a django server
    text
    copied!<p>I first tried to use django and then django-webhooks to call a shell script that restarts the server. This didn't work, because the webpage hangs when the server restart is called, as django is reloaded. </p> <p>Then I used fastcgi and python alone to create a URL that calls the shell script. I know the python script works when I run it on the server, but not when it is run from the URL. </p> <p>Apache is setup as:</p> <pre><code>&lt;VirtualHost *:80&gt; ServerName webhooks.myserver.com DocumentRoot /home/ubuntu/web/common/www &lt;Directory /&gt; Options FollowSymLinks +ExecCGI AllowOverride All &lt;/Directory&gt; &lt;Files post.py&gt; SetHandler fastcgi-script &lt;/Files&gt; FastCgiServer /home/ubuntu/web/common/www/post.py -processes 2 -socket /tmp/fcgi.sock &lt;/VirtualHost&gt;</code></pre> <p>The python code called by apache is:</p> <pre><code>#!/usr/bin/python import fcgi, warnings, os, subprocess BASE_DIR = os.getcwd() def app(environ, start_response): cmd = "sudo %s/../deploy/postwebhook.sh &gt;&gt; /var/log/votizen/webhooks_run.log 2&gt;&gt; /var/log/votizen/webhooks_error.log &" % BASE_DIR warnings.warn("Running cmd=%s" % cmd) bufsize = -1 PIPE = subprocess.PIPE subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) warnings.warn("Post deployment webhook completed") start_response('200 OK', [('Content-Type', 'text/html')]) return('Hello World!') fcgi.WSGIServer(app, bindAddress = '/tmp/fcgi.sock').run()</code></pre> <p>And the shell script is:</p> <pre><code>#!/bin/bash # restart the apache server echo ' ' echo 'post webhooks started' date '+%H:%M:%S %d-%m-%y' apache2ctl -t; sudo /etc/init.d/apache2 stop; sudo /etc/init.d/apache2 start # todo: check if apache failed # copy media files for apps echo "moving SC to S3" python /home/ubuntu/web/corporate/manage.py sync_media_s3 -p sc date '+%H:%M:%S %d-%m-%y' echo 'post webhooks completed'</code></pre> <p>I'm not seeing any errors in the apache logs and the access log shows that the triggering URL is being called. However, I only see the python warnings the first time the URL is called after a restart and it never actually restarts the server.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload