reworking l-s startup (#175)

* reworking l-s startup

it was failing to retry when starting with an invalid configuration

* changed startup routine

* start supervisor after update
This commit is contained in:
Fabio Cigliano 2018-09-27 22:49:11 +12:00 committed by Josh Harvey
parent 256538a0e2
commit 87a4e87a0b
2 changed files with 20 additions and 14 deletions

View file

@ -62,6 +62,8 @@ perl -i -pe 's/command=.*/command=$ENV{NPM_BIN}\/lamassu-admin-server/g' /etc/su
decho "updating lamassu-server" decho "updating lamassu-server"
supervisorctl update lamassu-server >> ${LOG_FILE} 2>&1 supervisorctl update lamassu-server >> ${LOG_FILE} 2>&1
supervisorctl update lamassu-admin-server >> ${LOG_FILE} 2>&1 supervisorctl update lamassu-admin-server >> ${LOG_FILE} 2>&1
supervisorctl start lamassu-server >> ${LOG_FILE} 2>&1
supervisorctl start lamassu-admin-server >> ${LOG_FILE} 2>&1
decho "updating backups conf" decho "updating backups conf"
BACKUP_CMD=${NPM_BIN}/lamassu-backup-pg BACKUP_CMD=${NPM_BIN}/lamassu-backup-pg

View file

@ -27,18 +27,22 @@ function run () {
logger.error('[%d] Retrying in 10s...', count) logger.error('[%d] Retrying in 10s...', count)
} }
const runner = () => runOnce() const runner = () =>
.then(() => clearInterval(handler)) settingsLoader.loadLatest()
.catch(errorHandler) .then(settings => {
clearInterval(handler)
return loadSanctions(settings)
.then(() => startServer(settings))
})
.catch(errorHandler)
return loadSanctions() handler = setInterval(runner, 10000)
.then(() => { handler = setInterval(runner, 10000) }) return runner()
.then(runner)
} }
function loadSanctions () { function loadSanctions (settings) {
return settingsLoader.loadLatest() return Promise.resolve()
.then(settings => { .then(() => {
const config = configManager.unscoped(settings.config) const config = configManager.unscoped(settings.config)
if (!config.sanctionsVerificationActive) return if (!config.sanctionsVerificationActive) return
@ -51,9 +55,9 @@ function loadSanctions () {
}) })
} }
function runOnce () { function startServer (settings) {
return settingsLoader.loadLatest() return Promise.resolve()
.then(settings => { .then(() => {
poller.start(settings) poller.start(settings)
const httpsServerOptions = { const httpsServerOptions = {
@ -74,12 +78,12 @@ function runOnce () {
if (options.devMode) logger.info('In dev mode') if (options.devMode) logger.info('In dev mode')
server.listen(port, () => { server.listen(port, () => {
console.log('lamassu-server listening on port ' + logger.info('lamassu-server listening on port ' +
port + ' ' + (devMode ? '(http)' : '(https)')) port + ' ' + (devMode ? '(http)' : '(https)'))
}) })
localServer.listen(localPort, 'localhost', () => { localServer.listen(localPort, 'localhost', () => {
console.log('lamassu-server listening on local port ' + localPort) logger.info('lamassu-server listening on local port ' + localPort)
}) })
}) })
} }