mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-22 10:21:01 +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?()
|
||||||
|
|
||||||
@ -65,18 +70,21 @@ class Application extends EventEmitter
|
|||||||
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,16 +98,17 @@ 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, =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user