 			callback?(arguments...)
 		)
 
+	_exitHandler: (code, signal) ->
+		@process = null
+
 	_start: (callback) ->
 		if not @process
 			options =

			@process = null
			@emit('stop')
			callback?(arguments...)
			
		spawn('pkill', ['-TERM', '-P', @process.pid], @options).on('exit', handler).on('error', handler)

	_update: (callback) ->
		shouldRestartApp = Boolean(@process)
		tasks = [
			# Stop the application if running
			(callback) =>
				if shouldRestartApp
					@_stop(callback)
				else
					callback()
			
			# Pull new commits
			(callback) =>
				spawn('git', ['pull', 'origin', 'master'], @options).on('exit', callback).on('error', callback)

			# Save the new commit hash
			(callback) =>

					state.set('gitHash', hash.trim())
				)

			# Prune npm dependencies
			(callback) =>
				spawn('npm', ['prune'], @options).on('exit', callback).on('error', callback)

			# Install npm dependencies
			(callback) =>
				spawn('npm', ['install'], @options).on('exit', callback).on('error', callback)

			# Start the app
			(callback) =>
				@_start(callback)
		]
		@emit('pre-update')
		async.series(tasks, =>
			@emit('post-update')
			callback?(arguments...)
		)

	# These methods shouldn't be called in parallel, queue them if they conflict
	['start', 'stop', 'init', 'update'].forEach((method) ->
		Application::[method] = (callback) ->
