UNPKG

the-shepherd

Version:
36 lines (30 loc) 1.44 kB
// Generated by CoffeeScript 2.5.1 (function() { var $, addGroup, echo, echoResponse, int, required, verbose, warn; ({$, echo, warn, verbose, required, echoResponse} = require('../common')); ({addGroup} = require('../daemon/groups')); ({int} = require('../util/format')); Object.assign(module.exports, { options: [["--group <group>", "Name of the group to create."], ["--cd <path>", "The working directory to spawn processes in."], ["--exec <script>", "Any shell command, e.g. 'node app.js'."], ["--count <n>", "The starting size of the group.", int], ["--port <port>", "If specified, set PORT in env for each child, incrementing port each time.", int], ["--grace <ms>", "How long to wait for a process to start."]], toMessage: function(cmd) { return { c: 'add', g: cmd.group, d: cmd.cd, x: cmd.exec, n: cmd.count, p: cmd.port, ms: cmd.grace }; }, onMessage: function(msg, client, cb) { var acted; acted = required(msg, 'g', "--group is required with 'add'") && required(msg, 'x', "--exec is required with 'add'") && addGroup(msg.g, msg.d, msg.x, msg.n, msg.p, msg.ms, cb); if (client != null) { client.write($.TNET.stringify((acted ? `Group ${msg.g} added.` : "No group added."))); } return typeof cb === "function" ? cb(null, acted) : void 0; }, onResponse: echoResponse }); }).call(this);