 	log: ->
 	err: ->
 }
+
+needToExit = false
+handleExit = () ->
+	needToExit = true
+	console.log('Got signal.  Shutting down.')
+
+process.on 'SIGINT', handleExit
+process.on 'SIGHUP', handleExit
 
 finished_docs_path = "/tmp/finished-docs-3"
 all_docs_path = "/tmp/all-docs-3"

	markDocAsProcessed doc_id, (err)->
		fs.appendFile unmigrated_docs_path, "#{doc_id}\n", callback

printProgress = ->
	count = Object.keys(finished_docs).length
	console.log "completed", count

checkIfDocHasBeenProccessed = (doc_id, callback)->
	callback(null, finished_docs[doc_id])

processNext = (doc_id, callback)->
	if !doc_id? or doc_id.length == 0
		return callback()
	checkIfDocHasBeenProccessed doc_id, (err, hasBeenProcessed)->
		if hasBeenProcessed
			console.log "#{doc_id} already processed, skipping"
			return callback()
		console.log "#{doc_id} processing"
		PackManager._packDocHistory doc_id, {}, (err) ->
			markDocAsProcessed doc_id, callback

updateIndexes = (callback) ->
	async.series [

mongojs = require("mongojs")
ObjectId = mongojs.ObjectId
db = mongojs(Settings.mongo.url, ['docs','docHistory', 'docHistoryStats'])
_ = require("underscore")
async = require("async")
exec = require("child_process").exec
BSON = db.bson.BSON
