mecano
Version:
Common functions for system deployment.
70 lines (67 loc) • 1.81 kB
JavaScript
// Generated by CoffeeScript 1.9.1
var execute;
module.exports = function(options, callback) {
var ref, ref1, write;
if (!options.user) {
return callback(new Error("Missing required option 'user'"));
}
if (options.nofile === true) {
options.nofile;
}
if (options.nproc === true) {
options.nproc = 65536;
}
if ((options.nofile != null) && ((ref = typeof options.nofile) !== 'number' && ref !== 'boolean')) {
throw Error('Invalid option "nofile"');
}
if ((options.nproc != null) && ((ref1 = typeof options.nproc) !== 'number' && ref1 !== 'boolean')) {
throw Error('Invalid option "nproc"');
}
if (options.destination == null) {
options.destination = "/etc/security/limits.d/" + options.user + ".conf";
}
write = [];
return this.execute({
cmd: "ulimit -Hn",
shy: true,
"if": options.nofile === true
}, function(err, status, stdout) {
if (err) {
return callback(err);
}
if (!status) {
return;
}
return options.nofile = stdout.trim();
}).call(function() {
if (options.nofile == null) {
return;
}
write.push({
match: RegExp("^" + options.user + ".+nofile.+$", "m"),
replace: options.user + " - nofile " + options.nofile,
append: true
});
return false;
}).call(function() {
if (options.nproc == null) {
return;
}
write.push({
match: RegExp("^" + options.user + ".+nproc.+$", "m"),
replace: options.user + " - nproc " + options.nproc,
append: true
});
return false;
}).write({
destination: options.destination,
write: write,
eof: true,
uid: options.uid,
gid: options.gid,
"if": function() {
return write.length;
}
}).then(callback);
};
execute = require('./execute');