Login

Control FCGI processes through management

Author:
nipuL
Posted:
March 27, 2008
Language:
Python
Version:
.96
Score:
0 (after 0 ratings)

Add fcgi to settings.INSTALLED_APPS then you can start and stop FCGI through manage.py

python manage.py startfcgi

python manage.py stopfcgi

In settings define runfcgi arguments using FCGI_* in settings

For example:

FCGI_SOCKET='/var/tmp/project.sock' FCGI_PIDFILE='/var/run/project.pid'

One of FCGI_SOCKET or FCGI_HOST/FCGI_PORT will need to be defined, but if you forget they will error out.

FCGI_PIDFILE is required to be defined to allow the process to be terminated.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# fcgi/management/commands/startfcgi.py
from django.core.management.base import NoArgsCommand
from django.core.management.commands import runfcgi

class Command(NoArgsCommand):
	def handle_noargs(self, **options):
		args = self.get_args()
		if isinstance(args, str):
			return args
		return runfcgi.Command().execute(*args, **options)
		
	def get_args(self):
		from django.conf import settings
		if not getattr(settings, 'FCGI_PIDFILE', None):
			return 'FCGI_PIDFILE must be specified in your settings'
		return [
			'%s=%s'%(attr.split('_')[1].lower(), getattr(settings, attr))
			for attr in dir(settings) if attr.startswith('FCGI_')
		]

# fcgi/management/commands/stopfcgi.py
from django.core.management.base import NoArgsCommand

class Command(NoArgsCommand):
	def handle_noargs(self, **options):
		import os
		from django.conf import settings
		pidfile = getattr(settings, 'FCGI_PIDFILE', None)
		if not pidfile:
			return 'FCGI_PIDFILE must be specified in settings'
		os.kill(int(open(pidfile).read()), 15)
		

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

Please login first before commenting.