UNPKG

mecano

Version:

Common functions for system deployment.

61 lines (58 loc) 2.06 kB
// Generated by CoffeeScript 1.11.1 var discover; module.exports = function(options) { options.log({ message: "Entering service.status", level: 'DEBUG', module: 'mecano/lib/service/status' }); 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: "Status for service " + options.name, level: 'INFO', module: 'mecano/lib/service/status' }); if (options.code_stopped !== 3) { options.log({ message: "Option code_stopped is " + options.code_stopped, level: 'DEBUG', module: 'mecano/lib/service/status' }); } this.call(discover.loader, function() { return options.loader != null ? options.loader : options.loader = options.store['mecano:service:loader']; }); return this.call(function() { return this.execute({ "if": function() { var ref; return (ref = options.store['mecano:system:type']) === 'redhat' || ref === 'centos'; }, cmd: "ls /lib/systemd/system/*.service /etc/systemd/system/*.service /etc/rc.d/* | grep -w \"" + options.name + "\" || exit 1\ncase \"" + options.loader + "\" in\n systemctl)\n systemctl status " + options.name + " || exit 3\n ;;\n service)\n service " + options.name + " status || exit 3\n ;;\n *)\n exit 2 # Unsupported Loader\n ;;\nesac", code: 0, code_skipped: 3 }, function(err, started) { var status; if (err) { throw Error("Invalid Service Name: " + options.name); } status = started ? 'started' : 'stopped'; options.log({ message: "Status for " + options.name + " is " + status, level: 'INFO', module: 'mecano/lib/service/status' }); if (options.cache) { return options.store["mecano.service." + options.name + ".status"] = "" + status; } }); }); }; discover = require('../misc/discover');