Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
api.listApps = function (callback) {
var apps = Object.keys(globalConfig.apps)
if (!apps.length) {
return callback(null, [])
}
Satan.executeRemote('list', {}, function (err, list) {
if (err) return callback(err)
callback(null, apps.map(function (appname) {
var app = api.getAppInfo(appname)
app.isRunning = findInList(appname, list)
return app
}))
})
}
function restart (app, callback) {
var msg = app.opts.name.yellow + ' restarted'
if (app.status === 'stopped') {
Satan.executeRemote('startId', { id: app.pm_id }, function (err) {
if (err) return callback(err)
callback(null, msg)
})
} else {
try {
process.kill(app.pid)
} catch (err) {
return callback(err)
}
return callback(null, msg)
}
}
Satan.executeRemote('findByScript', {script: app.script}, function (err, proc) {
if (err) return callback(err)
if (proc) return callback(null, appname.yellow + ' already running.')
var appConf = prepareConfig(app)
appConf.NODE_ENV = app.config.nodeEnv || globalConfig.nodeEnv
if (app.config.port) appConf.PORT = app.config.port
Satan.executeRemote('prepare', appConf, function (err) {
if (err) return callback(err)
callback(null, appname.yellow + ' running on ' + app.port)
})
})
})
Satan.executeRemote('findByScript', {script: app.script}, function (err, proc) {
if (err) return callback(err)
if (!proc) return callback(null, appname.yellow + ' is not running')
Satan.executeRemote('stopId', { id: proc.pm_id }, function (err) {
if (err) return callback(err)
callback(null, appname.yellow + ' stopped.')
})
})
}
api.stopApp = function (appname, callback) {
var app = api.getAppInfo(appname)
if (!app) {
return callback(new Error('app ' + appname.yellow + ' does not exist.'))
}
Satan.executeRemote('findByScript', {script: app.script}, function (err, proc) {
if (err) return callback(err)
if (!proc) return callback(null, appname.yellow + ' is not running')
Satan.executeRemote('stopId', { id: proc.pm_id }, function (err) {
if (err) return callback(err)
callback(null, appname.yellow + ' stopped.')
})
})
}