mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 10:01:55 +00:00
Handle forced updates and empty repos
This commit is contained in:
parent
81dc5233da
commit
9791c3e036
@ -45,6 +45,9 @@ class Application extends EventEmitter
|
|||||||
callback?(arguments...)
|
callback?(arguments...)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_exitHandler: (code, signal) ->
|
||||||
|
@process = null
|
||||||
|
|
||||||
_start: (callback) ->
|
_start: (callback) ->
|
||||||
if not @process
|
if not @process
|
||||||
options =
|
options =
|
||||||
@ -52,6 +55,8 @@ class Application extends EventEmitter
|
|||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
|
|
||||||
@process = spawn('sudo', ['-u', @user, 'foreman', 'start'], options)
|
@process = spawn('sudo', ['-u', @user, 'foreman', 'start'], options)
|
||||||
|
@process.on('exit', @_exitHandler.bind(@))
|
||||||
|
@process.on('error', @_exitHandler.bind(@))
|
||||||
@emit('start')
|
@emit('start')
|
||||||
callback?()
|
callback?()
|
||||||
|
|
||||||
@ -61,22 +66,25 @@ class Application extends EventEmitter
|
|||||||
@process = null
|
@process = null
|
||||||
@emit('stop')
|
@emit('stop')
|
||||||
callback?(arguments...)
|
callback?(arguments...)
|
||||||
|
|
||||||
spawn('pkill', ['-TERM', '-P', @process.pid], @options).on('exit', handler).on('error', handler)
|
spawn('pkill', ['-TERM', '-P', @process.pid], @options).on('exit', handler).on('error', handler)
|
||||||
|
|
||||||
_update: (callback) ->
|
_update: (callback) ->
|
||||||
shouldRestartApp = Boolean(@process)
|
|
||||||
tasks = [
|
tasks = [
|
||||||
# Stop the application if running
|
# Stop the application if running
|
||||||
(callback) =>
|
(callback) =>
|
||||||
if shouldRestartApp
|
if @process
|
||||||
@_stop(callback)
|
@_stop(callback)
|
||||||
else
|
else
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
# Pull new commits
|
# Fetch new commits
|
||||||
(callback) =>
|
(callback) =>
|
||||||
spawn('git', ['pull', 'origin', 'master'], @options).on('exit', callback).on('error', callback)
|
spawn('git', ['fetch'], @options).on('exit', callback).on('error', callback)
|
||||||
|
|
||||||
|
# Reset our master branch to origin/master
|
||||||
|
(callback) =>
|
||||||
|
spawn('git', ['reset', '--hard', 'origin/master'], @options).on('exit', callback).on('error', callback)
|
||||||
|
|
||||||
# Save the new commit hash
|
# Save the new commit hash
|
||||||
(callback) =>
|
(callback) =>
|
||||||
@ -90,23 +98,24 @@ class Application extends EventEmitter
|
|||||||
state.set('gitHash', hash.trim())
|
state.set('gitHash', hash.trim())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Prune npm dependencies
|
||||||
|
(callback) =>
|
||||||
|
spawn('npm', ['prune'], @options).on('exit', callback).on('error', callback)
|
||||||
|
|
||||||
# Install npm dependencies
|
# Install npm dependencies
|
||||||
(callback) =>
|
(callback) =>
|
||||||
spawn('npm', ['install'], @options).on('exit', callback).on('error', callback)
|
spawn('npm', ['install'], @options).on('exit', callback).on('error', callback)
|
||||||
|
|
||||||
# Start the app
|
# Start the app
|
||||||
(callback) =>
|
(callback) =>
|
||||||
if shouldRestartApp
|
@_start(callback)
|
||||||
@_start(callback)
|
|
||||||
else
|
|
||||||
callback()
|
|
||||||
]
|
]
|
||||||
@emit('pre-update')
|
@emit('pre-update')
|
||||||
async.series(tasks, =>
|
async.series(tasks, =>
|
||||||
@emit('post-update')
|
@emit('post-update')
|
||||||
callback?(arguments...)
|
callback?(arguments...)
|
||||||
)
|
)
|
||||||
|
|
||||||
# These methods shouldn't be called in parallel, queue them if they conflict
|
# These methods shouldn't be called in parallel, queue them if they conflict
|
||||||
['start', 'stop', 'init', 'update'].forEach((method) ->
|
['start', 'stop', 'init', 'update'].forEach((method) ->
|
||||||
Application::[method] = (callback) ->
|
Application::[method] = (callback) ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user