 							app = remoteApps[appId]
 							# Restore the complete environment so that it's persisted in the DB
 							app.env = JSON.stringify(remoteAppEnvs[appId])
-							forceThisApp = remoteAppEnvs[appId]['RESIN_SUPERVISOR_OVERRIDE_LOCK'] == '1' || remoteAppEnvs[appId]['RESIN_OVERRIDE_LOCK'] == '1'
+							forceThisApp =
+								remoteAppEnvs[appId]['RESIN_SUPERVISOR_OVERRIDE_LOCK'] == '1' ||
+								remoteAppEnvs[appId]['RESIN_OVERRIDE_LOCK'] == '1'
 							strategy = remoteAppEnvs[appId]['RESIN_SUPERVISOR_UPDATE_STRATEGY']
 							timeout = remoteAppEnvs[appId]['RESIN_SUPERVISOR_HANDOVER_TIMEOUT']
-							updateUsingStrategy(strategy, apps[appId], app, needsDownload, force || forceThisApp, timeout)
+							updateUsingStrategy strategy, {
+								localApp: localApps[appId]
+								app
+								needsDownload
+								force: force || forceThisApp
+								timeout
+							}
 					.catch(wrapAsError)
 		.filter(_.isError)
 		.then (failures) ->
+			_.each(failures, (err) -> console.error('Error:', err, err.stack))
 			throw new Error(joinErrorMessages(failures)) if failures.length > 0
 		.then ->
 			updateStatus.failed = 0

	return err if _.isError(err)
	return new Error(err.message ? err)

selectAndKill = (appId) ->
	knex('app').select().where({ appId })
	.then ([ app ]) ->
		if !app?
			throw new Error('App not found')
		kill(app)

# Wait for app to signal it's ready to die, or timeout to complete (if it is defined and not-empty)
waitToKill = (app, timeout) ->
	startTime = Date.now()
	pollInterval = 100
	timeout = parseInt(timeout)
	checkFileOrTimeout = ->
		fs.statAsync(killmePath(app))
		.catch (err) ->
			throw err if isNaN(timeout) or (Date.now() - startTime) < timeout
		.then ->
			fs.unlinkAsync(killmePath(app)).catch(_.noop)
	checkFileOrTimeout()
	.catch ->
		Promise.delay(pollInterval).then(checkFileOrTimeout)

UPDATE_IDLE = 0
UPDATE_UPDATING = 1

	allAppIds = _.union(localAppIds, remoteAppIds)
	return { toBeRemoved, toBeDownloaded, toBeInstalled, toBeUpdated, appsWithChangedEnvs, allAppIds }

getConfig = (key) ->
	knex('config').select('value').where({ key }).get(0).get('value')

application.update = update = (force) ->
	if updateStatus.state isnt UPDATE_IDLE
		# Mark an update required after the current.
