mecano
Version:
Common functions for system deployment.
69 lines (66 loc) • 1.95 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var discover;
module.exports = function(options) {
options.log({
message: "Entering service.stop",
level: 'DEBUG',
module: 'mecano/lib/service/stop'
});
if (typeof options.argument === 'string') {
if (options.name == null) {
options.name = options.argument;
}
}
if (!options.name) {
throw Error("Invalid Name: " + (JSON.stringify(options.name)));
}
options.log({
message: "Stop service " + options.name,
level: 'INFO',
module: 'mecano/lib/service/stop'
});
this.call(discover.system);
this.call(discover.loader, function() {
return options.loader != null ? options.loader : options.loader = options.store['mecano:service:loader'];
});
return this.call({
"if": function() {
var ref;
return (ref = options.store['mecano:system:type']) === 'redhat' || ref === 'centos';
},
if_exec: "ls /lib/systemd/system/*.service /etc/systemd/system/*.service /etc/rc.d/* | grep " + options.name,
handler: function() {
var cmd;
cmd = (function() {
switch (options.loader) {
case 'systemctl':
return "systemctl stop " + options.name;
case 'service':
return "service " + options.name + " stop";
default:
throw Error('Init System not supported');
}
})();
this.service.status({
name: options.name,
code_started: options.code_started,
code_stopped: options.code_stopped,
shy: true
});
return this.execute({
cmd: cmd,
"if": function() {
return this.status(-1);
}
}, function(err, stopped) {
if (err) {
throw err;
}
if (!err && options.cache) {
return options.store["mecano.service." + options.name + ".status"] = 'stopped';
}
});
}
});
};
discover = require('../misc/discover');