UNPKG

mecano

Version:

Common functions for system deployment.

73 lines (70 loc) 2.14 kB
// Generated by CoffeeScript 1.11.1 var discover; module.exports = function(options) { options.log({ message: "Entering service.start", level: 'DEBUG', module: 'mecano/lib/service/start' }); 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: "Start service " + options.name, level: 'INFO', module: 'mecano/lib/service/start' }); 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.store['mecano:service:loader']) { case 'systemctl': return "systemctl start " + options.name; case 'service': return "service " + options.name + " start"; 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, unless: [ function() { return this.status(-1); }, function() { return options.cache && options.store["mecano.service." + options.name + ".status"] === 'started'; } ] }, function(err, started) { if (err) { throw err; } if (!err && options.cache) { return options.store["mecano.service." + options.name + ".status"] = 'started'; } }); } }); }; discover = require('../misc/discover');