Skip to content

Commit

Permalink
add ensure_inited command to sbin/rsted
Browse files Browse the repository at this point in the history
also add flup to pip-requirements
  • Loading branch information
anru committed Jun 12, 2013
1 parent 0c97330 commit f00e995
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/python
# all the imports

import os, sys
Expand Down
1 change: 1 addition & 0 deletions pip-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
flup
flask
redis
rst2pdf
Expand Down
2 changes: 1 addition & 1 deletion pwl/fastcgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def runfastcgi(argset=[], **kwargs):
import flup
except ImportError, e:
print >> sys.stderr, 'ERROR: %s' % e
print >> sys.stderr, ' Unable to load the flup package. In order to run pyzzle'
print >> sys.stderr, ' Unable to load the flup package. In order to run rsted'
print >> sys.stderr, ' as a FastCGI application, you will need to get flup from'
print >> sys.stderr, " http://www.saddi.com/software/flup/ If you've already"
print >> sys.stderr, ' installed flup, then make sure you have it in your PYTHONPATH.'
Expand Down
10 changes: 5 additions & 5 deletions rsted.fcgi
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ from os.path import join as J
from pwl.fastcgi import runfastcgi
from application import app

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

if not os.path.isdir(run_path):
os.mkdir(run_path)
if not os.path.isdir(full_run_path):
os.mkdir(full_run_path)

# default options
fcgi_opts = {
'daemonize': 'yes',
'pidfile': os.path.join(run_path, 'fastcgi.pid'),
'pidfile': os.path.join(full_run_path, app.config.get('PID_FILE', 'fastcgi.pid')),
'method': 'prefork',
'socket': os.path.join(run_path, 'rsted.sock'),
'socket': os.path.join(full_run_path, app.config.get('SOCKET_FILE', 'rsted.sock')),
'workdir': app.config.root_path,
'maxrequests': 100,
}
Expand Down
33 changes: 28 additions & 5 deletions sbin/rsted
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/python

import os, sys
from os.path import join as J
Expand All @@ -11,7 +11,7 @@ sys.path.insert(0, root_path)
from pwl.utils.daemon import BaseDaemon
from application import app

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

try:
action = sys.argv[1]
Expand All @@ -23,7 +23,7 @@ class RstedDaemon(BaseDaemon):
NO_WRITE_PID = True

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

def print_status(self):
pidexists = os.path.exists(self.pidfile)
Expand All @@ -33,7 +33,26 @@ class RstedDaemon(BaseDaemon):
count = int(os.popen("ps --pid %d --no-heading| wc -l" % pid).read().strip())
running = count > 0
print "Running: %s" % ('Yes' if running else 'No')


def is_running(self):
pidexists = os.path.exists(self.pidfile)
if pidexists:
pid = self.readpid()
count = int(os.popen("ps --pid %d --no-heading| wc -l" % pid).read().strip())
return count > 0
return False

def ensure_started(self):
if not self.is_running():
self.delpid()
self.start()

chmod_socket = app.config.get('CHMOD_SOCKET')
socket_file = os.path.join(run_path, app.config.get('SOCKET_FILE', 'rsted.sock'))

if chmod_socket:
chmod_socket = str(chmod_socket)
os.popen("chmod %s %s" % (chmod_socket, socket_file))

pidfile = J(run_path, 'fastcgi.pid')
daemon = RstedDaemon(pidfile)
Expand All @@ -46,6 +65,10 @@ elif action == 'restart':
daemon.restart()
elif action == 'status':
daemon.print_status()

elif action == 'check':
if not daemon.is_running():
sys.exit(1)
elif action == 'ensure_started':
daemon.ensure_started()


5 changes: 5 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# configuration
DEBUG = True

RUN_PATH = 'var/run'
PID_FILE = 'fastcgi.pid'
SOCKET_FILE = 'rsted.sock'
CHMOD_SOCKET = '0777' # you can override this in settings_local.py if you wish

try:
from settings_local import *
except ImportError:
Expand Down

0 comments on commit f00e995

Please sign in to comment.