Skip to content
This repository was archived by the owner on Oct 21, 2018. It is now read-only.

Commit f00e995

Browse files
committed
add ensure_inited command to sbin/rsted
also add flup to pip-requirements
1 parent 0c97330 commit f00e995

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/python
22
# all the imports
33

44
import os, sys

pip-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
flup
12
flask
23
redis
34
rst2pdf

pwl/fastcgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def runfastcgi(argset=[], **kwargs):
123123
import flup
124124
except ImportError, e:
125125
print >> sys.stderr, 'ERROR: %s' % e
126-
print >> sys.stderr, ' Unable to load the flup package. In order to run pyzzle'
126+
print >> sys.stderr, ' Unable to load the flup package. In order to run rsted'
127127
print >> sys.stderr, ' as a FastCGI application, you will need to get flup from'
128128
print >> sys.stderr, " http://www.saddi.com/software/flup/ If you've already"
129129
print >> sys.stderr, ' installed flup, then make sure you have it in your PYTHONPATH.'

rsted.fcgi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ from os.path import join as J
55
from pwl.fastcgi import runfastcgi
66
from application import app
77

8-
run_path = J(app.config.root_path, 'var/run')
8+
full_run_path = J(app.config.root_path, app.config.get('RUN_PATH', 'var/run'))
99

10-
if not os.path.isdir(run_path):
11-
os.mkdir(run_path)
10+
if not os.path.isdir(full_run_path):
11+
os.mkdir(full_run_path)
1212

1313
# default options
1414
fcgi_opts = {
1515
'daemonize': 'yes',
16-
'pidfile': os.path.join(run_path, 'fastcgi.pid'),
16+
'pidfile': os.path.join(full_run_path, app.config.get('PID_FILE', 'fastcgi.pid')),
1717
'method': 'prefork',
18-
'socket': os.path.join(run_path, 'rsted.sock'),
18+
'socket': os.path.join(full_run_path, app.config.get('SOCKET_FILE', 'rsted.sock')),
1919
'workdir': app.config.root_path,
2020
'maxrequests': 100,
2121
}

sbin/rsted

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/python
22

33
import os, sys
44
from os.path import join as J
@@ -11,7 +11,7 @@ sys.path.insert(0, root_path)
1111
from pwl.utils.daemon import BaseDaemon
1212
from application import app
1313

14-
run_path = J(app.config.root_path, 'var/run')
14+
run_path = J(app.config.root_path, app.config.get('RUN_PATH', 'var/run'))
1515

1616
try:
1717
action = sys.argv[1]
@@ -23,7 +23,7 @@ class RstedDaemon(BaseDaemon):
2323
NO_WRITE_PID = True
2424

2525
def run(self):
26-
os.system(J(app.config.root_path, 'rsted.fcgi'))
26+
os.system('python ' + J(app.config.root_path, 'rsted.fcgi'))
2727

2828
def print_status(self):
2929
pidexists = os.path.exists(self.pidfile)
@@ -33,7 +33,26 @@ class RstedDaemon(BaseDaemon):
3333
count = int(os.popen("ps --pid %d --no-heading| wc -l" % pid).read().strip())
3434
running = count > 0
3535
print "Running: %s" % ('Yes' if running else 'No')
36-
36+
37+
def is_running(self):
38+
pidexists = os.path.exists(self.pidfile)
39+
if pidexists:
40+
pid = self.readpid()
41+
count = int(os.popen("ps --pid %d --no-heading| wc -l" % pid).read().strip())
42+
return count > 0
43+
return False
44+
45+
def ensure_started(self):
46+
if not self.is_running():
47+
self.delpid()
48+
self.start()
49+
50+
chmod_socket = app.config.get('CHMOD_SOCKET')
51+
socket_file = os.path.join(run_path, app.config.get('SOCKET_FILE', 'rsted.sock'))
52+
53+
if chmod_socket:
54+
chmod_socket = str(chmod_socket)
55+
os.popen("chmod %s %s" % (chmod_socket, socket_file))
3756

3857
pidfile = J(run_path, 'fastcgi.pid')
3958
daemon = RstedDaemon(pidfile)
@@ -46,6 +65,10 @@ elif action == 'restart':
4665
daemon.restart()
4766
elif action == 'status':
4867
daemon.print_status()
49-
68+
elif action == 'check':
69+
if not daemon.is_running():
70+
sys.exit(1)
71+
elif action == 'ensure_started':
72+
daemon.ensure_started()
5073

5174

settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# configuration
33
DEBUG = True
44

5+
RUN_PATH = 'var/run'
6+
PID_FILE = 'fastcgi.pid'
7+
SOCKET_FILE = 'rsted.sock'
8+
CHMOD_SOCKET = '0777' # you can override this in settings_local.py if you wish
9+
510
try:
611
from settings_local import *
712
except ImportError:

0 commit comments

Comments
 (0)