2016-05-24 09:40:26 -07:00
'use strict' ;
exports = module . exports = {
2017-02-07 10:30:52 -08:00
start : start ,
2017-04-25 14:46:30 -07:00
stop : stop ,
createMailConfig : createMailConfig
2016-05-24 09:40:26 -07:00
} ;
2016-05-24 10:52:55 -07:00
var apps = require ( './apps.js' ) ,
2016-05-24 10:58:18 -07:00
assert = require ( 'assert' ) ,
2016-05-28 01:56:32 -07:00
async = require ( 'async' ) ,
2016-05-24 10:52:55 -07:00
config = require ( './config.js' ) ,
2016-05-24 09:40:26 -07:00
certificates = require ( './certificates.js' ) ,
debug = require ( 'debug' ) ( 'box:platform' ) ,
2016-05-24 10:52:55 -07:00
fs = require ( 'fs' ) ,
2016-06-14 15:49:24 -07:00
hat = require ( 'hat' ) ,
2016-05-24 13:10:18 -07:00
infra = require ( './infra_version.js' ) ,
2017-01-28 01:39:11 -08:00
nginx = require ( './nginx.js' ) ,
2016-10-13 13:13:09 -07:00
os = require ( 'os' ) ,
2016-05-24 09:40:26 -07:00
paths = require ( './paths.js' ) ,
2016-05-24 13:10:18 -07:00
safe = require ( 'safetydance' ) ,
2017-03-30 12:48:46 +02:00
semver = require ( 'semver' ) ,
2016-08-30 20:10:20 -07:00
settings = require ( './settings.js' ) ,
2016-05-24 13:16:31 -07:00
shell = require ( './shell.js' ) ,
2016-08-30 20:08:31 -07:00
subdomains = require ( './subdomains.js' ) ,
2017-04-24 13:50:24 -07:00
taskmanager = require ( './taskmanager.js' ) ,
2017-01-07 23:24:10 -08:00
user = require ( './user.js' ) ,
2016-07-24 23:19:11 -07:00
util = require ( 'util' ) ,
_ = require ( 'underscore' ) ;
2016-05-24 09:40:26 -07:00
2016-09-03 12:02:42 -07:00
var gPlatformReadyTimer = null ;
2016-05-24 16:28:59 -07:00
2016-08-31 07:46:00 -07:00
var NOOP _CALLBACK = function ( error ) { if ( error ) debug ( error ) ; } ;
2017-02-07 10:30:52 -08:00
function start ( callback ) {
assert . strictEqual ( typeof callback , 'function' ) ;
2016-09-03 11:46:57 -07:00
if ( process . env . BOX _ENV === 'test' && ! process . env . TEST _CREATE _INFRA ) return callback ( ) ;
2016-05-24 09:40:26 -07:00
debug ( 'initializing addon infrastructure' ) ;
2016-05-24 10:52:55 -07:00
2017-06-29 11:43:03 -05:00
// restart mail container if any of these keys change
2016-09-03 12:02:42 -07:00
settings . events . on ( settings . MAIL _CONFIG _KEY , function ( ) { startMail ( NOOP _CALLBACK ) ; } ) ;
2017-06-29 11:43:03 -05:00
settings . events . on ( settings . MAIL _RELAY _KEY , function ( ) { startMail ( NOOP _CALLBACK ) ; } ) ;
2016-08-31 07:46:00 -07:00
2017-01-17 23:18:02 -08:00
certificates . events . on ( certificates . EVENT _CERT _CHANGED , function ( domain ) {
2017-01-17 10:53:26 -08:00
if ( domain === '*.' + config . fqdn ( ) || domain === config . adminFqdn ( ) ) startMail ( NOOP _CALLBACK ) ;
} ) ;
2016-05-24 13:10:18 -07:00
var existingInfra = { version : 'none' } ;
2016-05-24 10:52:55 -07:00
if ( fs . existsSync ( paths . INFRA _VERSION _FILE ) ) {
2016-05-24 13:10:18 -07:00
existingInfra = safe . JSON . parse ( fs . readFileSync ( paths . INFRA _VERSION _FILE , 'utf8' ) ) ;
2016-06-20 11:59:43 -05:00
if ( ! existingInfra ) existingInfra = { version : 'corrupt' } ;
2016-05-24 10:52:55 -07:00
}
2016-07-24 23:19:11 -07:00
// short-circuit for the restart case
if ( _ . isEqual ( infra , existingInfra ) ) {
2016-05-24 13:10:18 -07:00
debug ( 'platform is uptodate at version %s' , infra . version ) ;
2017-03-15 20:31:15 -07:00
emitPlatformReady ( ) ;
2016-09-04 11:38:36 -07:00
return callback ( ) ;
2016-05-24 10:52:55 -07:00
}
2016-05-24 13:10:18 -07:00
debug ( 'Updating infrastructure from %s to %s' , existingInfra . version , infra . version ) ;
2016-05-24 10:52:55 -07:00
2016-05-28 01:56:32 -07:00
async . series ( [
2016-07-25 00:39:57 -07:00
stopContainers . bind ( null , existingInfra ) ,
startAddons . bind ( null , existingInfra ) ,
2016-05-28 01:56:32 -07:00
removeOldImages ,
2016-07-25 18:57:54 -07:00
startApps . bind ( null , existingInfra ) ,
2016-05-28 01:56:32 -07:00
fs . writeFile . bind ( fs , paths . INFRA _VERSION _FILE , JSON . stringify ( infra ) )
2016-07-24 22:59:47 -07:00
] , function ( error ) {
if ( error ) return callback ( error ) ;
2016-06-21 10:37:12 -05:00
2017-03-15 20:31:15 -07:00
emitPlatformReady ( ) ;
2016-07-24 22:59:47 -07:00
callback ( ) ;
} ) ;
2016-06-21 10:37:12 -05:00
}
2017-04-24 13:50:24 -07:00
function stop ( callback ) {
2016-06-21 10:37:12 -05:00
clearTimeout ( gPlatformReadyTimer ) ;
gPlatformReadyTimer = null ;
2017-02-07 10:30:52 -08:00
exports . events = null ;
2017-04-24 13:50:24 -07:00
taskmanager . pauseTasks ( callback ) ;
2016-06-21 10:37:12 -05:00
}
2017-03-15 20:31:15 -07:00
function emitPlatformReady ( ) {
2017-05-10 09:34:33 -07:00
// give some time for the platform to "settle". For example, mysql might still be initing the
2017-03-15 20:31:15 -07:00
// database dir and we cannot call service scripts until that's done.
2017-05-10 09:34:33 -07:00
// TODO: make this smarter to not wait for 15secs for the crash-restart case
2017-03-15 20:31:15 -07:00
gPlatformReadyTimer = setTimeout ( function ( ) {
debug ( 'emitting platform ready' ) ;
gPlatformReadyTimer = null ;
2017-04-24 13:50:24 -07:00
taskmanager . resumeTasks ( ) ;
2017-05-10 09:34:33 -07:00
} , 15000 ) ;
2017-03-15 20:31:15 -07:00
}
2016-05-28 01:56:32 -07:00
function removeOldImages ( callback ) {
2016-05-24 13:16:31 -07:00
debug ( 'removing old addon images' ) ;
for ( var imageName in infra . images ) {
2017-02-16 10:30:59 -08:00
if ( imageName === 'redis' ) continue ; // see #223
2016-05-24 13:16:31 -07:00
var image = infra . images [ imageName ] ;
2016-06-08 15:05:43 +02:00
debug ( 'cleaning up images of %j' , image ) ;
2016-05-24 13:16:31 -07:00
var cmd = 'docker images "%s" | tail -n +2 | awk \'{ print $1 ":" $2 }\' | grep -v "%s" | xargs --no-run-if-empty docker rmi' ;
shell . execSync ( 'removeOldImagesSync' , util . format ( cmd , image . repo , image . tag ) ) ;
}
2016-05-28 01:56:32 -07:00
callback ( ) ;
2016-05-24 13:16:31 -07:00
}
2016-07-25 00:39:57 -07:00
function stopContainers ( existingInfra , callback ) {
2016-05-24 10:52:55 -07:00
// TODO: be nice and stop addons cleanly (example, shutdown commands)
2016-07-25 00:39:57 -07:00
2017-03-30 12:48:46 +02:00
// always stop addons to restart them on any infra change, regardless of minor or major update
if ( existingInfra . version !== infra . version ) {
2016-07-25 09:38:31 -07:00
debug ( 'stopping all containers for infra upgrade' ) ;
2016-07-25 00:39:57 -07:00
shell . execSync ( 'stopContainers' , 'docker ps -qa | xargs --no-run-if-empty docker rm -f' ) ;
} else {
assert ( typeof infra . images , 'object' ) ;
var changedAddons = [ ] ;
for ( var imageName in infra . images ) {
2017-02-16 10:30:59 -08:00
if ( imageName === 'redis' ) continue ; // see #223
2016-07-25 09:38:31 -07:00
if ( infra . images [ imageName ] . tag !== existingInfra . images [ imageName ] . tag ) changedAddons . push ( imageName ) ;
2016-07-25 00:39:57 -07:00
}
2016-07-25 09:38:31 -07:00
debug ( 'stopping addons for incremental infra update: %j' , changedAddons ) ;
2016-09-03 11:24:12 -07:00
// ignore error if container not found (and fail later) so that this code works across restarts
shell . execSync ( 'stopContainers' , 'docker rm -f ' + changedAddons . join ( ' ' ) + ' || true' ) ;
2016-07-25 00:39:57 -07:00
}
2016-05-28 01:56:32 -07:00
callback ( ) ;
2016-05-24 10:52:55 -07:00
}
2016-05-24 10:58:18 -07:00
2016-06-14 15:49:24 -07:00
function startGraphite ( callback ) {
const tag = infra . images . graphite . tag ;
2017-03-29 15:51:53 +02:00
const dataDir = paths . PLATFORM _DATA _DIR ;
2016-06-14 15:49:24 -07:00
const cmd = ` docker run --restart=always -d --name="graphite" \
2016-06-14 20:46:29 -07:00
-- net cloudron \
-- net - alias graphite \
2016-06-14 15:49:24 -07:00
- m 75 m \
-- memory - swap 150 m \
2017-04-25 15:21:23 +00:00
-- dns 172.18 . 0.1 \
-- dns - search = . \
2016-06-14 15:49:24 -07:00
- p 127.0 . 0.1 : 2003 : 2003 \
- p 127.0 . 0.1 : 2004 : 2004 \
- p 127.0 . 0.1 : 8000 : 8000 \
- v "${dataDir}/graphite:/app/data" \
-- read - only - v / tmp - v / run "${tag}" ` ;
shell . execSync ( 'startGraphite' , cmd ) ;
callback ( ) ;
}
function startMysql ( callback ) {
const tag = infra . images . mysql . tag ;
2017-03-29 15:51:53 +02:00
const dataDir = paths . PLATFORM _DATA _DIR ;
2016-06-17 09:46:07 -05:00
const rootPassword = hat ( 8 * 128 ) ;
2016-10-13 13:13:09 -07:00
const memoryLimit = ( 1 + Math . round ( os . totalmem ( ) / ( 1024 * 1024 * 1024 ) / 4 ) ) * 256 ;
2016-06-14 15:49:24 -07:00
2017-03-29 15:51:53 +02:00
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/mysql_vars.sh' ,
2016-06-14 20:46:29 -07:00
'MYSQL_ROOT_PASSWORD=' + rootPassword + '\nMYSQL_ROOT_HOST=172.18.0.1' , 'utf8' ) ) {
2016-06-14 15:49:24 -07:00
return callback ( new Error ( 'Could not create mysql var file:' + safe . error . message ) ) ;
}
const cmd = ` docker run --restart=always -d --name="mysql" \
2016-06-14 20:46:29 -07:00
-- net cloudron \
-- net - alias mysql \
2016-10-13 13:13:09 -07:00
- m $ { memoryLimit } m \
-- memory - swap $ { memoryLimit * 2 } m \
2017-04-25 15:21:23 +00:00
-- dns 172.18 . 0.1 \
-- dns - search = . \
2016-06-14 15:49:24 -07:00
- v "${dataDir}/mysql:/var/lib/mysql" \
- v "${dataDir}/addons/mysql_vars.sh:/etc/mysql/mysql_vars.sh:ro" \
-- read - only - v / tmp - v / run "${tag}" ` ;
shell . execSync ( 'startMysql' , cmd ) ;
2017-05-10 09:34:33 -07:00
setTimeout ( callback , 5000 ) ;
2016-06-14 15:49:24 -07:00
}
function startPostgresql ( callback ) {
const tag = infra . images . postgresql . tag ;
2017-03-29 15:51:53 +02:00
const dataDir = paths . PLATFORM _DATA _DIR ;
2016-06-17 09:46:07 -05:00
const rootPassword = hat ( 8 * 128 ) ;
2016-10-13 13:13:09 -07:00
const memoryLimit = ( 1 + Math . round ( os . totalmem ( ) / ( 1024 * 1024 * 1024 ) / 4 ) ) * 256 ;
2016-06-14 15:49:24 -07:00
2017-03-29 15:51:53 +02:00
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/postgresql_vars.sh' , 'POSTGRESQL_ROOT_PASSWORD=' + rootPassword , 'utf8' ) ) {
2016-06-14 15:49:24 -07:00
return callback ( new Error ( 'Could not create postgresql var file:' + safe . error . message ) ) ;
}
const cmd = ` docker run --restart=always -d --name="postgresql" \
2016-06-14 20:46:29 -07:00
-- net cloudron \
-- net - alias postgresql \
2016-10-13 13:13:09 -07:00
- m $ { memoryLimit } m \
-- memory - swap $ { memoryLimit * 2 } m \
2017-04-25 15:21:23 +00:00
-- dns 172.18 . 0.1 \
-- dns - search = . \
2016-06-14 15:49:24 -07:00
- v "${dataDir}/postgresql:/var/lib/postgresql" \
- v "${dataDir}/addons/postgresql_vars.sh:/etc/postgresql/postgresql_vars.sh:ro" \
-- read - only - v / tmp - v / run "${tag}" ` ;
shell . execSync ( 'startPostgresql' , cmd ) ;
2017-05-10 09:34:33 -07:00
setTimeout ( callback , 5000 ) ;
2016-06-14 15:49:24 -07:00
}
function startMongodb ( callback ) {
const tag = infra . images . mongodb . tag ;
2017-03-29 16:39:52 +02:00
const dataDir = paths . PLATFORM _DATA _DIR ;
2016-06-17 09:46:07 -05:00
const rootPassword = hat ( 8 * 128 ) ;
2016-10-13 13:13:09 -07:00
const memoryLimit = ( 1 + Math . round ( os . totalmem ( ) / ( 1024 * 1024 * 1024 ) / 4 ) ) * 200 ;
2016-06-14 15:49:24 -07:00
2017-03-29 15:51:53 +02:00
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/mongodb_vars.sh' , 'MONGODB_ROOT_PASSWORD=' + rootPassword , 'utf8' ) ) {
2016-06-14 15:49:24 -07:00
return callback ( new Error ( 'Could not create mongodb var file:' + safe . error . message ) ) ;
}
const cmd = ` docker run --restart=always -d --name="mongodb" \
2016-06-14 20:46:29 -07:00
-- net cloudron \
-- net - alias mongodb \
2016-10-13 13:13:09 -07:00
- m $ { memoryLimit } m \
-- memory - swap $ { memoryLimit * 2 } m \
2017-04-25 15:21:23 +00:00
-- dns 172.18 . 0.1 \
-- dns - search = . \
2016-06-14 15:49:24 -07:00
- v "${dataDir}/mongodb:/var/lib/mongodb" \
- v "${dataDir}/addons/mongodb_vars.sh:/etc/mongodb_vars.sh:ro" \
-- read - only - v / tmp - v / run "${tag}" ` ;
shell . execSync ( 'startMongodb' , cmd ) ;
2017-05-10 09:34:33 -07:00
setTimeout ( callback , 5000 ) ;
2016-06-14 15:49:24 -07:00
}
2017-01-17 23:14:52 -08:00
function createMailConfig ( callback ) {
2017-01-18 08:43:11 -08:00
assert . strictEqual ( typeof callback , 'function' ) ;
2017-01-17 23:14:52 -08:00
const fqdn = config . fqdn ( ) ;
const mailFqdn = config . adminFqdn ( ) ;
const alertsFrom = 'no-reply@' + config . fqdn ( ) ;
2017-06-11 17:51:08 -07:00
debug ( 'createMailConfig: generating mail config' ) ;
2017-01-17 23:14:52 -08:00
user . getOwner ( function ( error , owner ) {
2017-02-28 18:17:17 -08:00
var alertsTo = config . provider ( ) === 'caas' ? [ 'support@cloudron.io' ] : [ ] ;
2017-07-05 11:31:51 -05:00
alertsTo . concat ( error ? [ ] : owner . email ) . join ( ',' ) ; // owner may not exist yet
2017-01-17 23:14:52 -08:00
2017-07-18 13:50:39 -07:00
settings . getAll ( function ( error , result ) {
2017-06-27 10:54:24 -05:00
if ( error ) return callback ( error ) ;
2017-07-18 13:50:39 -07:00
var catchAll = result [ settings . CATCH _ALL _ADDRESS _KEY ] . join ( ',' ) ;
2017-07-18 14:06:32 -07:00
var mailFromValidation = result [ settings . MAIL _FROM _VALIDATION _KEY ] ;
2017-01-17 23:14:52 -08:00
2017-06-11 17:51:08 -07:00
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/mail/mail.ini' ,
2017-07-18 17:38:21 -07:00
` mail_domain= ${ fqdn } \n mail_server_name= ${ mailFqdn } \n alerts_from= ${ alertsFrom } \n alerts_to= ${ alertsTo } \n catch_all= ${ catchAll } \n mail_from_validation= ${ mailFromValidation } \n ` , 'utf8' ) ) {
2017-06-11 17:51:08 -07:00
return callback ( new Error ( 'Could not create mail var file:' + safe . error . message ) ) ;
}
2017-07-18 13:50:39 -07:00
var relay = result [ settings . MAIL _RELAY _KEY ] ;
2017-06-27 10:54:24 -05:00
2017-07-18 13:50:39 -07:00
const enabled = relay . provider !== 'cloudron-smtp' ? true : false ,
host = relay . host || '' ,
port = relay . port || 25 ,
username = relay . username || '' ,
password = relay . password || '' ;
2017-06-27 10:54:24 -05:00
2017-07-18 13:50:39 -07:00
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/mail/smtp_forward.ini' ,
` enable_outbound= ${ enabled } \n host= ${ host } \n port= ${ port } \n enable_tls=true \n auth_type=plain \n auth_user= ${ username } \n auth_pass= ${ password } ` , 'utf8' ) ) {
return callback ( new Error ( 'Could not create mail var file:' + safe . error . message ) ) ;
}
2017-06-27 10:54:24 -05:00
2017-07-18 13:50:39 -07:00
callback ( ) ;
2017-06-11 17:51:08 -07:00
} ) ;
2017-01-17 23:14:52 -08:00
} ) ;
}
2016-06-14 15:49:24 -07:00
function startMail ( callback ) {
// mail (note: 2525 is hardcoded in mail container and app use this port)
// MAIL_SERVER_NAME is the hostname of the mailserver i.e server uses these certs
// MAIL_DOMAIN is the domain for which this server is relaying mails
// mail container uses /app/data for backed up data and /run for restart-able data
const tag = infra . images . mail . tag ;
2017-03-29 15:51:53 +02:00
const dataDir = paths . PLATFORM _DATA _DIR ;
2016-12-29 18:22:36 -08:00
const memoryLimit = Math . max ( ( 1 + Math . round ( os . totalmem ( ) / ( 1024 * 1024 * 1024 ) / 4 ) ) * 128 , 256 ) ;
2017-01-07 16:39:13 -08:00
2017-01-17 10:53:26 -08:00
// admin and mail share the same certificate
certificates . getAdminCertificate ( function ( error , cert , key ) {
2016-05-24 10:58:18 -07:00
if ( error ) return callback ( error ) ;
2017-03-29 15:51:53 +02:00
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/mail/tls_cert.pem' , cert ) ) return callback ( new Error ( 'Could not create cert file:' + safe . error . message ) ) ;
if ( ! safe . fs . writeFileSync ( paths . ADDON _CONFIG _DIR + '/mail/tls_key.pem' , key ) ) return callback ( new Error ( 'Could not create key file:' + safe . error . message ) ) ;
2017-01-17 10:21:42 -08:00
2016-08-30 20:04:18 -07:00
settings . getMailConfig ( function ( error , mailConfig ) {
if ( error ) return callback ( error ) ;
2016-08-31 08:13:03 -07:00
shell . execSync ( 'startMail' , 'docker rm -f mail || true' ) ;
2017-01-17 23:14:52 -08:00
createMailConfig ( function ( error ) {
if ( error ) return callback ( error ) ;
2017-01-07 23:24:10 -08:00
var ports = mailConfig . enabled ? '-p 587:2525 -p 993:9993 -p 4190:4190 -p 25:2525' : '' ;
const cmd = ` docker run --restart=always -d --name="mail" \
-- net cloudron \
-- net - alias mail \
- m $ { memoryLimit } m \
-- memory - swap $ { memoryLimit * 2 } m \
2017-04-25 15:21:23 +00:00
-- dns 172.18 . 0.1 \
-- dns - search = . \
2017-03-22 20:42:28 -07:00
-- env ENABLE _MDA = $ { mailConfig . enabled } \
2017-01-20 15:51:01 -08:00
- v "${dataDir}/mail:/app/data" \
2017-01-17 23:49:22 -08:00
- v "${dataDir}/addons/mail:/etc/mail" \
2017-01-07 23:24:10 -08:00
$ { ports } \
2017-01-20 15:51:01 -08:00
-- read - only - v / run - v / tmp $ { tag } ` ;
2017-01-07 23:24:10 -08:00
shell . execSync ( 'startMail' , cmd ) ;
if ( ! mailConfig . enabled || process . env . BOX _ENV === 'test' ) return callback ( ) ;
// Add MX and DMARC record. Note that DMARC policy depends on DKIM signing and thus works
// only if we use our internal mail server.
var records = [
{ subdomain : '_dmarc' , type : 'TXT' , values : [ '"v=DMARC1; p=reject; pct=100"' ] } ,
{ subdomain : '' , type : 'MX' , values : [ '10 ' + config . mailFqdn ( ) + '.' ] }
] ;
async . mapSeries ( records , function ( record , iteratorCallback ) {
subdomains . upsert ( record . subdomain , record . type , record . values , iteratorCallback ) ;
} , callback ) ;
} ) ;
2016-08-30 20:04:18 -07:00
} ) ;
2016-05-24 10:58:18 -07:00
} ) ;
}
2016-05-24 16:28:59 -07:00
2016-07-25 00:39:57 -07:00
function startAddons ( existingInfra , callback ) {
var startFuncs = [ ] ;
2017-03-30 12:48:46 +02:00
// always start addons on any infra change, regardless of minor or major update
2016-07-25 09:38:31 -07:00
if ( existingInfra . version !== infra . version ) {
debug ( 'startAddons: no existing infra or infra upgrade. starting all addons' ) ;
startFuncs . push ( startGraphite , startMysql , startPostgresql , startMongodb , startMail ) ;
} else {
assert . strictEqual ( typeof existingInfra . images , 'object' ) ;
2016-07-25 00:39:57 -07:00
if ( infra . images . graphite . tag !== existingInfra . images . graphite . tag ) startFuncs . push ( startGraphite ) ;
if ( infra . images . mysql . tag !== existingInfra . images . mysql . tag ) startFuncs . push ( startMysql ) ;
if ( infra . images . postgresql . tag !== existingInfra . images . postgresql . tag ) startFuncs . push ( startPostgresql ) ;
if ( infra . images . mongodb . tag !== existingInfra . images . mongodb . tag ) startFuncs . push ( startMongodb ) ;
if ( infra . images . mail . tag !== existingInfra . images . mail . tag ) startFuncs . push ( startMail ) ;
2016-07-25 10:18:35 -07:00
debug ( 'startAddons: existing infra. incremental addon create %j' , startFuncs . map ( function ( f ) { return f . name ; } ) ) ;
2016-07-25 00:39:57 -07:00
}
2016-06-14 15:49:24 -07:00
2016-07-25 00:39:57 -07:00
async . series ( startFuncs , callback ) ;
2016-06-14 15:49:24 -07:00
}
2016-07-25 18:57:54 -07:00
function startApps ( existingInfra , callback ) {
2017-03-30 12:48:46 +02:00
// Infra version change strategy:
// * no existing version - restore apps
// * major versions - restore apps
// * minor versions - reconfigure apps
2016-07-25 18:57:54 -07:00
if ( existingInfra . version === infra . version ) {
debug ( 'startApp: apps are already uptodate' ) ;
callback ( ) ;
2017-04-04 12:15:29 -07:00
} else if ( existingInfra . version === 'none' || ! semver . valid ( existingInfra . version ) || semver . major ( existingInfra . version ) !== semver . major ( infra . version ) ) {
2016-07-25 18:57:54 -07:00
debug ( 'startApps: restoring installed apps' ) ;
apps . restoreInstalledApps ( callback ) ;
} else {
debug ( 'startApps: reconfiguring installed apps' ) ;
2017-01-28 01:39:11 -08:00
nginx . removeAppConfigs ( ) ; // should we change the cert location, nginx will not start
2016-07-25 18:57:54 -07:00
apps . configureInstalledApps ( callback ) ;
}
}