Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 0 additions & 38 deletions bin/sl-pm-install.txt

This file was deleted.

27 changes: 15 additions & 12 deletions bin/sl-pm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand All @@ -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()];
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
});

Expand Down
26 changes: 0 additions & 26 deletions bin/sl-pm.txt

This file was deleted.

26 changes: 26 additions & 0 deletions intl/en/sl-pm-install.txt
Original file line number Diff line number Diff line change
@@ -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 `{{<user>:<pass>}}`.
{{--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.
26 changes: 26 additions & 0 deletions intl/en/sl-pm.txt
Original file line number Diff line number Diff line change
@@ -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 {{<user>:<pass>}} (eg. {{strong-pm:super-secret}}). This is the same format
as used by the {{--http-auth}} option of {{pm-install}}.
5 changes: 3 additions & 2 deletions lib/auth.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions lib/ctl.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions lib/drivers/common/local-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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');
Expand All @@ -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));
}
}));

Expand Down
Loading