Control FCGI processes through management

 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)
		

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.