Permalink
Browse files

Simplified the search update script quite a bit by using sudo -u <apa…

…che user> instead of changing ownership of Whoosh directories.
  • Loading branch information...
1 parent 85876e4 commit 360f1e23149ec75d9ec9123ea682fb30c38abcc0 mattdeboard committed May 8, 2011
Showing with 25 additions and 39 deletions.
  1. +25 −39 srchupdate.py
View
@@ -13,45 +13,31 @@ def update():
format='%(asctime)s %(levelname)s:%(message)s',
datefmt='%m/%d/%Y %H:%M:%S')
logging.info('Starting index update.')
- try:
- mattwhoosh = subprocess.Popen(['sudo', 'chown', '-R',
- 'matt:matt', whoosh_dir],
- stdout=subprocess.PIPE,
- stderr=suprocess.STDOUT)
- update_index = subprocess.Popen([domain_dir+'bin/python',
- appdir+'manage.py', 'update_index'],
- stdout=subprocess.PIPE,
- stderr=suprocess.STDOUT)
- apachewhsh = subprocess.Popen(['sudo', 'chown', '-R',
- 'www-data:www-data', whoosh_dir],
- stdout=subprocess.PIPE,
- stderr=suprocess.STDOUT)
- apachereload = subprocess.Popen(['sudo',
- '/etc/init.d/apache2',
- 'force-reload'],
- stdout=subprocess.PIPE,
- stderr=suprocess.STDOUT)
- if sum([int(mattwhoosh), int(update_index), int(apachewhsh),
- int(apachereload)]) == 0:
- logging.info('Index successfully updated.')
- else:
- subs = [mattwhoosh, update_index, apachewhsh, apachereload]
- logging.error('**INDEX UPDATE FAILED**')
- logging.error('The following exit codes were returned:')
- logging.error('- mattwhoosh: %s' % mattwhoosh)
- logging.error('- update_index: %s' % update_index)
- logging.error('- apachewhsh: %s' % apachewhsh)
- logging.error('- apachereload: %s' % apachereload)
- for sub in subs:
- if sub.returncode:
- logging.error('Error information:')
- logging.error('stdout: %s' % sub.communicate()[0])
- logging.error('stderr: %s' % sub.communicate()[1])
-
- except:
- logging.error("Exception received: ",
- sys.exc_info()[0],
- sys.exc_info()[1])
+ update_index = subprocess.Popen(['sudo', '-u', 'www-data',
+ domain_dir+'bin/python',
+ appdir+'manage.py', 'update_index'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ update_index.wait()
+ apachereload = subprocess.Popen(['sudo',
+ '/etc/init.d/apache2',
+ 'force-reload'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ apachereload.wait()
+ if not any((update_index.returncode, apachereload.returncode)):
+ logging.info('Index successfully updated.')
+ else:
+ subs = [update_index, apachereload]
+ logging.error('**INDEX UPDATE FAILED**')
+ logging.error('The following exit codes were returned:')
+ logging.error('- update_index: %s' % update_index.returncode)
+ logging.error('- apachereload: %s' % apachereload.returncode)
+ for sub in subs:
+ if sub.returncode:
+ logging.error('Error information:')
+ logging.error('stdout: %s' % sub.communicate()[0])
+ logging.error('stderr: %s' % sub.communicate()[1])
if __name__ == '__main__':

0 comments on commit 360f1e2

Please sign in to comment.