diff --git a/.gitignore b/.gitignore index f1afbd1..92baf81 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,15 @@ test/app-prepare/node_modules test/container test/copy.out test/receive-base +intl/MSG.json +intl/de +intl/es +intl/fr +intl/it +intl/ja +intl/ko +intl/pt +intl/ru +intl/zh-Hans +intl/zh-Hant +intl/en/*.json diff --git a/bin/sl-pm-install.txt b/bin/sl-pm-install.txt deleted file mode 100644 index 45bbfb9..0000000 --- a/bin/sl-pm-install.txt +++ /dev/null @@ -1,38 +0,0 @@ -usage: %MAIN% [options] - -Install the Strongloop process manager as a service. - -Options: - -h,--help Print this message and exit. - -v,--version Print version and exit. - -m,--metrics STATS Specify --metrics option for supervisor running deployed - applications. - -b,--base BASE Base directory to work in (default is $HOME of the user - that manager is run as, see --user). - -P,--base-port PORT Applications will run at PORT + service ID (default 3000). - -d,--driver DRIVER Specify application execution driver. May be direct or - docker (default is direct). - -e,--set-env K=V... Initial application environment variables. If setting - multiple variables they must be quoted into a single - argument: "K1=V1 K2=V2 K3=V3". - -u,--user USER User to run manager as (default is strong-pm). - -p,--port PORT Listen on PORT for control (default 8701). - -n,--dry-run Don't write any files. - -j,--job-file FILE Path of Upstart job to create (default is - `/etc/init/strong-pm.conf`). - -f,--force Overwrite existing job file if present. - --upstart VERSION Specify Upstart version, 1.4 or 0.6 (default is 1.4). - --systemd Install as a systemd service, not an Upstart job. - --http-auth CREDS Enable HTTP authentication using Basic auth, requiring - the specified credentials for every request sent to the - REST API where CREDS is given in the form of - `:`. - --skip-default-install - Disable 'npm install' phase of application deployments - made on this PM. - -OS Service support: - -The --systemd and --upstart VERSION options are mutually exclusive. If neither -is specified, the service is installed as an Upstart job using a template that -assumes Upstart 1.4 or higher. diff --git a/bin/sl-pm.js b/bin/sl-pm.js index 1458608..6a99ebb 100755 --- a/bin/sl-pm.js +++ b/bin/sl-pm.js @@ -16,6 +16,7 @@ var home = require('userhome'); var mkdirp = require('mkdirp').sync; var path = require('path'); var fs = require('fs'); +var g = require('strong-globalize'); var versionApi = require('strong-mesh-models/package.json').apiVersion; var versionPm = require('../package.json').version; @@ -27,7 +28,7 @@ var DRIVERS = { var Server = require('../lib/server'); function printHelp($0, prn) { - var USAGE = fs.readFileSync(require.resolve('./sl-pm.txt'), 'utf-8') + var USAGE = g.t('sl-pm.txt') .replace(/%MAIN%/g, $0) .trim(); @@ -57,6 +58,8 @@ var driver = DRIVERS.direct; var basePort = Number(process.env.STRONGLOOP_BASEPORT) || 3000; var dbDriver = 'sqlite3'; +g.setRootDir(path.resolve(__dirname, '..')); + var option; while ((option = parser.getopt()) !== undefined) { switch (option.option) { @@ -72,7 +75,7 @@ while ((option = parser.getopt()) !== undefined) { base = option.optarg; break; case 'c': - console.error('Warning: ignoring config file: ', option.optarg); + g.error('Warning: ignoring config file: %s', option.optarg); break; case 'd': driver = DRIVERS[option.optarg.toLowerCase()]; @@ -92,7 +95,7 @@ while ((option = parser.getopt()) !== undefined) { dbDriver = 'memory'; break; default: - console.error('Invalid usage (near option \'%s\'), try `%s --help`.', + g.error('Invalid usage (near option \'%s\'), try `{{%s --help}}`.', option.optopt, $0); process.exit(1); } @@ -101,12 +104,12 @@ while ((option = parser.getopt()) !== undefined) { base = path.resolve(base); if (parser.optind() !== argv.length) { - console.error('Invalid usage (extra arguments), try `%s --help`.', $0); + g.error('Invalid usage (extra arguments), try `{{%s --help}}`.', $0); process.exit(1); } if (listen == null) { - console.error('Listen port was not specified, try `%s --help`.', $0); + g.error('Listen port was not specified, try `{{%s --help}}`.', $0); process.exit(1); } @@ -117,7 +120,7 @@ process.chdir(base); if (dbDriver === 'sqlite3') { checkAndUpgradeDb(base, function(err) { if (err) { - console.error('%s(%d) %s', $0, process.pid, err.message); + g.error('%s(%d) %s', $0, process.pid, err.message); return process.exit(1); } startPm(); @@ -126,9 +129,9 @@ if (dbDriver === 'sqlite3') { var sqliteDbPath = path.join(base, 'strong-mesh.db'); fs.stat(sqliteDbPath, function(err) { if (!err) { - console.error( - '%s(%d) SQLite3 database found at %s. Please delete this' + - 'file if you wish to use the JSON file database.', + g.error( + '%s(%d) {{SQLite3}} database found at %s. Please delete this' + + 'file if you wish to use the {{JSON}} file database.', $0, process.pid, sqliteDbPath ); return process.exit(1); @@ -149,16 +152,16 @@ function startPm() { }); app.on('listening', function(listenAddr) { - console.log('%s(%d): StrongLoop PM v%s (API v%s) on port `%s`', + g.log('%s(%d): {{StrongLoop PM}} v%s (API v%s) on port `%s`', $0, process.pid, versionPm, versionApi, listenAddr.port); - console.log('%s(%d): Base folder `%s`', + g.log('%s(%d): Base folder `%s`', $0, process.pid, base); - console.log('%s(%d): Applications on port `%d + service ID`', + g.log('%s(%d): Applications on port `%d + service ID`', $0, process.pid, basePort); }); diff --git a/bin/sl-pm.txt b/bin/sl-pm.txt deleted file mode 100644 index 1b63126..0000000 --- a/bin/sl-pm.txt +++ /dev/null @@ -1,26 +0,0 @@ -usage: %MAIN% [options] - -The Strongloop process manager. - -Options: - -h,--help Print this message and exit. - -v,--version Print version and exit. - -b,--base BASE Base directory to work in (default `~/.strong-pm`). - -l,--listen PORT Listen on PORT for control (default 8701). - -P,--base-port PORT Applications will run at PORT + service ID (default 3000). - --driver DRIVER Execution backend to use for running apps. Current drivers - are 'direct' and 'docker' (default `direct`). - --skip-default-install - Disable 'npm install' phase of application deployments - made on this PM. - --json-file-db Persist deployment information and metrics in a JSON based - database. Not recommended for production use. - -The base directory is used to save deployed applications, for working -directories, and for any other files the process manager needs to create. - -The process manager will be controllable via HTTP on the port specified. That -port is also used for deployment with strong-deploy. Basic authentication -can be enabled for HTTP by setting the STRONGLOOP_PM_HTTP_AUTH environment -variable to : (eg. strong-pm:super-secret). This is the same format -as used by the --http-auth option of pm-install. diff --git a/intl/en/sl-pm-install.txt b/intl/en/sl-pm-install.txt new file mode 100644 index 0000000..c76d447 --- /dev/null +++ b/intl/en/sl-pm-install.txt @@ -0,0 +1,26 @@ +usage: {{%MAIN%}} [options] + +Install the {{Strongloop process manager}} as a service. + +Options: + {{-h,--help}} Print this message and exit. + {{-v,--version}} Print version and exit. + {{-m,--metrics STATS}} Specify {{--metrics}} option for supervisor running deployed applications. + {{-b,--base BASE}} Base directory to work in (default is {{$HOME}} of the user that manager is run as, see {{--user}}). + {{-P,--base-port PORT}} Applications will run at {{PORT + service ID}} (default 3000). + {{-d,--driver DRIVER}} Specify application execution driver. May be direct or docker (default is direct). + {{-e,--set-env K=V...}} Initial application environment variables. If setting multiple variables they must be quoted into a single argument: {{"K1=V1 K2=V2 K3=V3"}}. + {{-u,--user USER}} User to run manager as (default is {{strong-pm}}). + {{-p,--port PORT}} Listen on {{PORT}} for control (default 8701). + {{-n,--dry-run}} Don't write any files. + {{-j,--job-file FILE}} Path of Upstart job to create (default is `{{/etc/init/strong-pm.conf}}`). + {{-f,--force}} Overwrite existing job file if present. + {{--upstart VERSION}} Specify Upstart version, 1.4 or 0.6 (default is 1.4). + {{--systemd}} Install as a {{systemd}} service, not an {{Upstart}} job. + {{--http-auth CREDS}} Enable HTTP authentication using Basic auth, requiring the specified credentials for every request sent to the {{REST API}} where {{CREDS}} is given in the form of `{{:}}`. + {{--skip-default-install}} + Disable '{{npm install}}' phase of application deployments made on this PM. + +OS Service support: + +The {{--systemd}} and {{--upstart VERSION}} options are mutually exclusive. If neither is specified, the service is installed as an Upstart job using a template that assumes Upstart 1.4 or higher. diff --git a/intl/en/sl-pm.txt b/intl/en/sl-pm.txt new file mode 100644 index 0000000..df7e8a8 --- /dev/null +++ b/intl/en/sl-pm.txt @@ -0,0 +1,26 @@ +usage: {{%MAIN%}} [options] + +The {{Strongloop process manager}}. + +Options: + {{-h,--help}} Print this message and exit. + {{-v,--version}} Print version and exit. + {{-b,--base BASE}} Base directory to work in (default `{{~/.strong-pm}}`). + {{-l,--listen PORT}} Listen on PORT for control (default 8701). + {{-P,--base-port PORT}} Applications will run at {{PORT + service ID}} (default 3000). + {{--driver DRIVER}} Execution backend to use for running apps. Current drivers + are '{{direct}}' and '{{docker}}' (default `{{direct}}`). + {{--skip-default-install}} + Disable '{{npm install}}' phase of application deployments + made on this PM. + {{--json-file-db}} Persist deployment information and metrics in a JSON based + database. Not recommended for production use. + +The base directory is used to save deployed applications, for working +directories, and for any other files the process manager needs to create. + +The process manager will be controllable via HTTP on the port specified. That +port is also used for deployment with strong-deploy. Basic authentication +can be enabled for HTTP by setting the STRONGLOOP_PM_HTTP_AUTH environment +variable to {{:}} (eg. {{strong-pm:super-secret}}). This is the same format +as used by the {{--http-auth}} option of {{pm-install}}. diff --git a/lib/auth.js b/lib/auth.js index c4801ea..c4ecff7 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -1,6 +1,7 @@ var auth = require('http-auth'); var crypto = require('crypto'); var fmt = require('util').format; +var g = require('strong-globalize'); module.exports = makeAuthMiddleware; module.exports.parse = parseAuth; @@ -37,7 +38,7 @@ function makeNoAuth() { } function makeBasicAuth(user, realm, pass) { - console.log('PM: enabling HTTP authentication (Basic)'); + g.log('PM: enabling HTTP authentication (Basic)'); var basicAuth = auth.basic({realm: realm}, checkCredentials); return auth.connect(basicAuth); @@ -47,7 +48,7 @@ function makeBasicAuth(user, realm, pass) { } function makeDigestAuth(user, realm, pass) { - console.log('PM: enabling HTTP authentication (Digest)'); + g.log('PM: enabling HTTP authentication (Digest)'); var digest = md5(fmt('%s:%s:%s', user, realm, pass)); var digestAuth = auth.digest({realm: realm}, checkDigest); return auth.connect(digestAuth); diff --git a/lib/ctl.js b/lib/ctl.js index 08536af..29bdec2 100644 --- a/lib/ctl.js +++ b/lib/ctl.js @@ -1,6 +1,8 @@ 'use strict'; var debug = require('debug')('strong-pm:ctl'); +var g = require('strong-globalize'); +var path = require('path'); module.exports = onCtlRequest; @@ -13,6 +15,8 @@ function onCtlRequest(options, req, callback) { var cmd = req.cmd; var rsp = {}; // Clear this response if the handler will callback itself. + g.setRootDir(path.resolve(__dirname, '..')); + switch (cmd) { case 'shutdown': rsp = shutdown(server, rsp); @@ -77,7 +81,7 @@ function shutdown(server, rsp) { process.exit(0); }); }); - rsp.message = 'strong-pm is shutting down...'; + rsp.message = g.t('{{strong-pm}} is shutting down...'); return rsp; } @@ -86,7 +90,7 @@ function start(server, instanceId, rsp, callback) { if (err) { rsp.error = err.message; } else { - rsp.message = 'starting...'; + rsp.message = g.t('starting...'); } return callback(rsp); }); @@ -110,7 +114,7 @@ function restart(server, style, instanceId, rsp, callback) { if (err) { rsp.error = err.message; } else { - rsp.message = 're-starting...'; + rsp.message = g.t('re-starting...'); } return callback(rsp); }); @@ -121,7 +125,7 @@ function setEnv(server, env, instanceId, rsp, callback) { if (err) { rsp.error = err.message; } else { - rsp.message = 'ok'; + rsp.message = g.t('ok'); } return callback(rsp); }); @@ -142,7 +146,7 @@ function logDump(server, instanceId, rsp) { rsp.log = server.dumpInstanceLog(instanceId); if (rsp.log == null) { - rsp.message = 'No application running, no log to dump'; + rsp.message = g.t('No application running, no log to dump'); } return rsp; diff --git a/lib/drivers/common/local-deploy.js b/lib/drivers/common/local-deploy.js index e616901..c466cf0 100644 --- a/lib/drivers/common/local-deploy.js +++ b/lib/drivers/common/local-deploy.js @@ -4,6 +4,7 @@ var concat = require('concat-stream'); var crypto = require('crypto'); var debug = require('debug')('strong-pm:local-deploy'); var fs = require('fs'); +var g = require('strong-globalize'); var path = require('path'); var serverCommit = require('strong-fork-cicada/lib/commit'); @@ -21,7 +22,7 @@ function LocalDeployer(_server) { LocalDeployer.prototype.sendError = function(res, err) { debug('error 400: %s', err); res.writeHead(400); - res.end('Local deploy failed: ' + err); + res.end(g.t('Local deploy failed: %s', err)); }; LocalDeployer.prototype.processLocalDir = function(req, res, dirPath, hash) { @@ -43,7 +44,7 @@ LocalDeployer.prototype.processLocalDir = function(req, res, dirPath, hash) { debug('commit: %j', commit); this.server.emit('prepared', commit); // FIXME emit on container res.writeHead(200); - res.end('Application deployed\n'); + res.end(g.t('Application deployed\n')); }; LocalDeployer.prototype.computeHash = function(req, res, dirPath) { @@ -53,10 +54,10 @@ LocalDeployer.prototype.computeHash = function(req, res, dirPath) { shasum.update(dirPath); fs.stat(dirPath, function(err, stats) { if (err) { - return self.sendError(res, '`' + dirPath + '` does not exist'); + return self.sendError(res, g.t('`%s` does not exist', dirPath)); } if (!stats.isDirectory()) { - return self.sendError(res, '`' + dirPath + '` is not a directory'); + return self.sendError(res, g.t('`%s` is not a directory', dirPath)); } var hash = shasum.digest('hex'); @@ -72,12 +73,12 @@ LocalDeployer.prototype.handle = function(req, res) { try { var postObj = JSON.parse(postData); if (!postObj.hasOwnProperty('local-directory')) { - return self.sendError(res, 'local directory not specified'); + return self.sendError(res, g.t('local directory not specified')); } self.computeHash(req, res, postObj['local-directory']); } catch (err) { - return self.sendError(res, 'error parsing request: ' + err.message); + return self.sendError(res, g.t('error parsing request: %s', err.message)); } })); diff --git a/lib/drivers/common/pack-receiver.js b/lib/drivers/common/pack-receiver.js index 7cf6d68..ea4bd83 100644 --- a/lib/drivers/common/pack-receiver.js +++ b/lib/drivers/common/pack-receiver.js @@ -3,6 +3,7 @@ var crypto = require('crypto'); var debug = require('debug')('strong-pm:pack-receiver'); var fmt = require('util').format; var fs = require('fs'); +var g = require('strong-globalize'); var mkdirp = require('mkdirp'); var os = require('os'); var path = require('path'); @@ -47,13 +48,13 @@ PackReceiver.prototype.processTarball = function(req, res, tarGzPath, hash) { readStream.pipe(unzipStream).pipe(untarStream); readStream.on('error', function(err) { - self.sendError(res, 'Read %s failed with: %s', tarGzPath, err); + self.sendError(res, g.t('Read %s failed with: %s', tarGzPath, err)); }); unzipStream.on('error', function(err) { - self.sendError(res, 'Untar %s failed with: %s', tarGzPath, err); + self.sendError(res, g.t('Untar %s failed with: %s', tarGzPath, err)); }); untarStream.on('error', function(err) { - self.sendError(res, 'Untar %s failed with: %s', tarGzPath, err); + self.sendError(res, g.t('Untar %s failed with: %s', tarGzPath, err)); }); untarStream.on('end', function() { @@ -80,7 +81,7 @@ PackReceiver.prototype.processTarball = function(req, res, tarGzPath, hash) { commit.runInPlace = false; self.cicada.emit('commit', commit); res.writeHead(200); - res.end('Application received'); + res.end(g.t('Application received')); }); }; @@ -90,8 +91,9 @@ PackReceiver.prototype.getTarballHash = function(req, res, tarballPath) { var self = this; tarballStream.on('error', function(err) { - console.log('Read %s for sha failed: %s', tarballPath, err); - self.sendError(res, 'Read %s for sha failed: %s', tarballPath, err); + g.log('Read %s for {{sha}} failed: %s', tarballPath, err); + self.sendError(res, + g.t('Read %s for {{sha}} failed: %s', tarballPath, err)); }); tarballStream.on('data', function(d) { @@ -111,7 +113,7 @@ PackReceiver.prototype.handle = function(req, res) { debug('mkdirp %j', tmpDirPath); mkdirp(tmpDirPath, {}, function(err, made) { if (err) { - self.sendError(res, fmt( + self.sendError(res, g.t( 'Unable to create dir: %s (%s)', made, err)); return; } diff --git a/lib/drivers/direct/container.js b/lib/drivers/direct/container.js index a315eb6..f2025ab 100644 --- a/lib/drivers/direct/container.js +++ b/lib/drivers/direct/container.js @@ -8,6 +8,7 @@ var c2s = require('strong-runner').Runnable.toString; var cicada = require('strong-fork-cicada'); var cicadaCommit = require('strong-fork-cicada/lib/commit'); var fs = require('fs'); +var g = require('strong-globalize'); var localDeploy = require('../common/local-deploy'); var logBuffer = require('../common/log-buffer'); var mandatory = require('./../../util').mandatory; @@ -221,7 +222,7 @@ Container.prototype.deployInstance = function(req, res) { function rejectDeployments(req, res) { res.status(403) .set('Content-Type', 'text/plain') - .end('Forbidden: Server is not accepting deployments'); + .end(g.t('Forbidden: Server is not accepting deployments')); } Container.prototype._onCommit = function(commit) { @@ -255,7 +256,7 @@ Container.prototype._onCommit = function(commit) { // XXX(sam) ... can I remove the commit? not much else to do, would be // nice if git push could be failed, but I think its too late for that. if (err) { - console.log('Prepare failed on %j in %j: %s', err.cmd, err.dir, err); + g.log('Prepare failed on %j in %j: %s', err.cmd, err.dir, err); return; } diff --git a/lib/drivers/docker/image.js b/lib/drivers/docker/image.js index e842187..bb23075 100644 --- a/lib/drivers/docker/image.js +++ b/lib/drivers/docker/image.js @@ -5,6 +5,7 @@ var Container = require('./container'); var debug = require('debug'); var EventEmitter = require('events').EventEmitter; var fmt = require('util').format; +var g = require('strong-globalize'); var inherits = require('util').inherits; var localDeploy = require('../common/local-deploy'); var packReceiver = require('../common/pack-receiver'); @@ -77,7 +78,7 @@ Image.prototype.receive = function(req, res) { function rejectDeployments(req, res) { res.status(403) .set('Content-Type', 'text/plain') - .end('Forbidden: Server is not accepting deployments'); + .end(g.t('Forbidden: Server is not accepting deployments')); } Image.prototype._onCommit = function(commit) { diff --git a/lib/drivers/docker/index.js b/lib/drivers/docker/index.js index 9a7d27a..94f650c 100644 --- a/lib/drivers/docker/index.js +++ b/lib/drivers/docker/index.js @@ -7,6 +7,7 @@ var debug = require('debug')('strong-pm:docker:driver'); var Docker = require('dockerode'); var EventEmitter = require('events').EventEmitter; var fmt = require('util').format; +var g = require('strong-globalize'); var Image = require('./image'); var inherits = require('util').inherits; var isError = require('util').isError; @@ -351,16 +352,16 @@ DockerDriver.prototype._resume = function(id, meta) { image.commit = meta.commit; image.emit('commit', meta.commit); image.on('error', function(err) { - self.error('error deploying %j:', id, err); + self.error(g.t('error deploying %s %j:', id, err)); throw err; }); image.on('image', function() { - debug('Deployment image for %j:', id, image.name); + debug('Deployment image for %s %j:', id, image.name); self.startInstance(id, function(err) { if (err) { - self.error('error resuming %j', id, err); + self.error(g.t('error resuming %s %j', id, err)); } else { - self.log('resumed instance %j', id); + self.log(g.t('resumed instance %s', id)); } }); }); @@ -368,7 +369,7 @@ DockerDriver.prototype._resume = function(id, meta) { DockerDriver.prototype.stop = function(cb) { var self = this; - this.log('shutting down driver'); + this.log(g.t('shutting down driver')); async.each(Object.keys(this._instances), stopInstanceById, cb); function stopInstanceById(id, next) { diff --git a/lib/install.js b/lib/install.js index baa29f1..f1d2676 100644 --- a/lib/install.js +++ b/lib/install.js @@ -5,14 +5,14 @@ var async = require('async'); var auth = require('./auth'); var debug = require('debug')('strong-pm:install'); var fs = require('fs'); +var g = require('strong-globalize'); var path = require('path'); var slServiceInstall = require('strong-service-install'); module.exports = install; function printHelp($0, prn) { - var usageFile = require.resolve('../bin/sl-pm-install.txt'); - var USAGE = fs.readFileSync(usageFile, 'utf-8') + var USAGE = g.t('sl-pm-install.txt') .replace(/%MAIN%/g, $0) .trim(); prn(USAGE); @@ -59,6 +59,8 @@ function install(argv, callback) { dirs: [], }; + g.setRootDir(path.resolve(__dirname, '..')); + var option; while ((option = parser.getopt()) !== undefined) { switch (option.option) { @@ -113,59 +115,60 @@ function install(argv, callback) { jobConfig.env.STRONGLOOP_PM_SKIP_DEFAULT_INSTALL = 'true'; break; default: - console.error('Invalid usage (near option \'%s\'), try `%s --help`.', + g.error('Invalid usage (near option \'%s\'), try `{{%s --help}}`.', option.optopt, $0); return callback(Error('usage')); } } if (parser.optind() !== argv.length) { - console.error('Invalid usage (extra arguments), try `%s --help`.', $0); - return callback(Error('usage')); + g.error('Invalid usage (extra arguments), try `{{%s --help}}`.', $0); + return callback(g.Error('usage')); } if (!(jobConfig.pmPort > 0)) { - console.error('Port %j is not valid, try `%s --help`.', + g.error('Port %j is not valid, try `{{%s --help}}`.', jobConfig.pmPort, $0); - return callback(Error('usage')); + return callback(g.Error('usage')); } if (!(jobConfig.basePort > 0)) { - console.error('Base port %j is not valid, try `%s --help`.', + g.error('Base port %j is not valid, try `{{%s --help}}`.', jobConfig.basePort, $0); - return callback(Error('usage')); + return callback(g.Error('usage')); } if (!jobConfig.systemd && !jobConfig.upstart) { jobConfig.upstart = '1.4'; // default } else if (jobConfig.systemd && jobConfig.upstart) { - console.error( - 'Invalid usage (cannot specify both --systemd and --upstart)' + + g.error( + 'Invalid usage (cannot specify both {{--systemd}} and {{--upstart}})' + ', see `%s --help`', $0); - return callback(Error('usage')); + return callback(g.Error('usage')); } if (!jobConfig.systemd && jobConfig.upstart !== '0.6' && jobConfig.upstart !== '1.4') { - console.error('Invalid usage (only upstart "0.6" and "1.4" supported)' + - ', see `%s --help`', $0); - return callback(Error('usage')); + g.error('Invalid usage (only {{upstart}} "0.6" and "1.4" supported)' + + ', see `{{%s --help}}`', $0); + return callback(g.Error('usage')); } if (jobConfig.env.STRONGLOOP_PM_HTTP_AUTH && auth.parse(jobConfig.env.STRONGLOOP_PM_HTTP_AUTH).scheme === 'none') { - console.error( - 'Bad http-auth specification: %s', jobConfig.env.STRONGLOOP_PM_HTTP_AUTH); - return callback(Error('usage')); + g.error( + 'Bad {{http-auth}} specification: %s', + jobConfig.env.STRONGLOOP_PM_HTTP_AUTH); + return callback(g.Error('usage')); } if (!/^(direct|docker)$/.test(jobConfig.driver)) { - console.error('Invalid driver: %s', jobConfig.driver); - return callback(Error('usage')); + g.error('Invalid driver: %s', jobConfig.driver); + return callback(g.Error('usage')); } if (jobConfig.upstart === '0.6' && jobConfig.driver === 'docker') { - console.error('Upstart 0.6 does not support setgid. Please run:\n' + - ' "sudo usermod -aG docker %s".', jobConfig.user); + g.error('{{Upstart}} 0.6 does not support {{setgid}}. Please run:\n' + + ' "{{sudo usermod -aG docker %s}}".', jobConfig.user); } if (jobConfig.driver === 'docker') { @@ -192,7 +195,7 @@ function install(argv, callback) { function report(err) { if (err) { - console.error('Error installing service \'%s\':', + g.error('Error installing service \'%s\':', jobConfig.name, err.message); } return callback(err); @@ -214,7 +217,7 @@ function ensureDocker(options, callback) { var docker = new Docker(); docker.info(function(err) { if (err) { - console.error('Docker not usable:', err); + g.error('Docker not usable: %s', err); } callback(err); }); @@ -275,7 +278,7 @@ function writeSeedEnvironment(options, callback) { store.set(k, env[k]); } if (options.dryRun) { - console.log('Would seed environment with: %j', env); + g.log('Would seed environment with: %j', env); return cb(); } else { options._touched.push(path); diff --git a/lib/server.js b/lib/server.js index a1c907d..9470c74 100644 --- a/lib/server.js +++ b/lib/server.js @@ -16,6 +16,7 @@ var c2s = require('strong-runner').Runnable.toString; var debug = require('./debug')('server'); var express = require('express'); var fmt = require('util').format; +var g = require('strong-globalize'); var http = require('http'); var mandatory = require('./util').mandatory; var onCtlRequest = require('./ctl'); @@ -330,7 +331,7 @@ Server.prototype._onInstanceRequest = function(instanceId, req, callback) { Server.prototype._onInstanceListening = function(instanceId, address) { var host = address.address || '*'; - console.log('%s: Service "%s" listening on %s:%d', this._cmdName, + g.log('%s: Service "%s" listening on %s:%d', this._cmdName, instanceId, host, address.port); }; @@ -413,7 +414,7 @@ Server.prototype.start = function start(cb) { function done(err) { if (!err) return cb(); - console.error('Listening failed with: %s', err.message); + g.error('Listening failed with: %s', err.message); self.stop(); self.emit('error', err); cb(err); diff --git a/lib/service-manager.js b/lib/service-manager.js index 0bd71dd..cab0957 100644 --- a/lib/service-manager.js +++ b/lib/service-manager.js @@ -5,6 +5,7 @@ var assert = require('assert'); var async = require('async'); var debug = require('debug')('strong-pm:service-manager'); var fmt = require('util').format; +var g = require('strong-globalize'); var util = require('util'); var pmVersion = require('../package.json').version; var versionApi = require('strong-mesh-models/package.json').apiVersion; @@ -53,7 +54,7 @@ prototype.handle = function(req, res, next) { Service.findOrCreate(filter, service, function(err, service) { if (err) { - console.error('service-manager: handle.findOrCreate: %s', err); + g.error('{{service-manager: handle.findOrCreate}}: %s', err); return next(err); } debug('old-style deploy to svc %j name %j', service.id, service.name); @@ -111,8 +112,8 @@ prototype.initOrUpdateDb = function(meshApp, callback) { return callback(); } debug('mark stopped: pid %j wid %j', proc.pid, proc.workerId); - proc.stopReason = 'StrongLoop Process Manager was stopped'; - proc.stopTime = new Date(); + proc.stopReason = g.t('StrongLoop Process Manager was stopped'); + proc.stopTime = g.d(new Date()); proc.save(callback); } }; @@ -300,13 +301,13 @@ prototype.onDeployment = function(service, req, res) { if (err) { debug(err); res.status(500).set({}); - res.end('Error while deploying: ' + err.message); + res.end(g.t('Error while deploying: %s', err.message)); return; } if (instances.length <= 0) { debug(err); res.status(500).set({}); - res.end('Error while deploying: no instance found'); + res.end(g.t('Error while deploying: no instance found')); return; } var instance = instances[0]; @@ -322,13 +323,14 @@ prototype.getInstanceEnv = function(instanceId, callback) { Instance.findById(instanceId, function(err, instance) { if (err) return callback(err); if (!instance) - return callback(Error('Unable to find instance with id ' + instanceId)); + return callback( + g.Error('Unable to find instance with id %s', instanceId)); instance.serverService(function(err, service) { if (err) return callback(err); if (!service) return callback( - Error('Unable to find service for instance with id ' + instanceId) + g.Error('Unable to find service for instance with id %s', instanceId) ); var env = getServiceEnv(service, self._basePort); diff --git a/lib/upgrade-db.js b/lib/upgrade-db.js index 7e6d837..a98f2e6 100644 --- a/lib/upgrade-db.js +++ b/lib/upgrade-db.js @@ -6,6 +6,7 @@ var SQLite3 = require('loopback-connector-sqlite3'); var async = require('async'); var debug = require('debug')('upgrade-db'); var fs = require('fs'); +var g = require('strong-globalize'); var path = require('path'); module.exports = tryUpgradeDb; @@ -16,7 +17,7 @@ function tryUpgradeDb(baseDir, memoryDbPath, dryRun, callback) { debug('Ensuring %s doesn\'t exist', meshDbPath); if (!err) { debug('Error: %s exist', meshDbPath); - return callback(new Error('Database ' + meshDbPath + ' already exists')); + return callback(g.Error('Database %s already exists', meshDbPath)); } upgradeDb(memoryDbPath, meshDbPath, function(err) { diff --git a/package.json b/package.json index b29915f..89fc1c7 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "dependencies": { "async": "^0.9.0", "bl": "^0.9.4", + "cldr-data": "^28.0.3", "compression": "^1.1.0", "concat-stream": "^1.4.7", "debug": "^2.1.3", @@ -78,6 +79,7 @@ "strong-control-channel": "^2.0.0", "strong-docker-build": "^1.0.0", "strong-fork-cicada": "^1.1.2", + "strong-globalize": "^1.0.0", "strong-mesh-models": "^8.0.0", "strong-npm-ls": "^1.0.0", "strong-runner": "^5.x",