mecano
Version:
Common functions for system deployment.
73 lines (72 loc) • 2.13 kB
JavaScript
// Generated by CoffeeScript 1.11.1
module.exports = function(options) {
var cacheonly;
options.log({
message: "Entering service.remove",
level: 'DEBUG',
module: 'mecano/lib/service/remove'
});
if (typeof options.argument === 'string') {
if (options.name == null) {
options.name = options.argument;
}
}
if (options.manager == null) {
options.manager = options.store['mecano:service:manager'];
}
if (!options.name) {
throw Error("Invalid Name: " + (JSON.stringify(options.name)));
}
options.log({
message: "Remove service " + options.name,
level: 'INFO',
module: 'mecano/lib/service/remove'
});
cacheonly = options.cacheonly ? '-C' : '';
this.execute({
cmd: "if which yum >/dev/null; then exit 1; fi\nif which apt-get >/dev/null; then exit 2; fi",
code: [1, 2],
unless: options.manager,
relax: true,
shy: true
}, function(err, status, stdout, stderr, signal) {
if (err) {
throw err;
}
options.manager = (function() {
switch (signal) {
case 1:
return 'yum';
case 2:
return 'apt';
}
})();
if (options.cache) {
return options.store['mecano:service:manager'] = options.manager;
}
});
return this.execute({
cmd: function() {
switch (options.manager) {
case 'yum':
return "if ! rpm -qa --qf \"%{NAME}\n\" | grep -w '" + options.name + "'; then exit 3; fi;\nyum remove -y " + cacheonly + " '" + options.name + "'";
case 'apt':
return "if ! dpkg -l | grep \'^ii\' | awk \'{print $2}\' | grep -w '" + options.name + "'; then exit 3; fi;\napt-get remove -y " + cacheonly + " '" + options.name + "'";
}
},
code_skipped: 3
}, function(err, removed) {
if (err) {
throw Error("Invalid Service Name: " + options.name);
}
return options.log(removed ? {
message: "Service removed",
level: 'WARN',
module: 'mecano/lib/service/remove'
} : {
message: "Service already removed",
level: 'INFO',
module: 'mecano/lib/service/remove'
});
});
};