UNPKG

mecano

Version:

Common functions for system deployment.

77 lines (72 loc) 2.19 kB
// Generated by CoffeeScript 1.11.1 var discover, fs, path; module.exports = function(options) { options.log({ message: "Entering service.init", level: 'DEBUG', module: 'mecano/lib/service/init' }); if (options.source == null) { throw Error('Missing source'); } if (options.engine == null) { options.engine = 'nunjunks'; } if (options.mode == null) { options.mode = 0x1ed; } if (options.name == null) { options.name = path.basename(options.source).split('.')[0]; } if (options.target == null) { options.target = "/etc/init.d/" + options.name; } this.call(discover.loader, options); 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(function() { var cmd, ref; cmd = "systemctl status " + options.name + " 2>\&1 "; if (((ref = options.store['mecano:system:type']) === 'redhat' || ref === 'centos') && options.loader === 'systemctl') { cmd += (function() { switch (options.store['mecano:system:release'].split('.')[1]) { case '1': return "| grep '(Reason: No such file or directory)'"; case '2': return "| grep 'Unit " + options.name + ".service could not be found.'"; case '3': return "| grep 'Unit " + options.name + ".service could not be found.'"; } })(); } this.render({ target: options.target, source: options.source, mode: options.mode, uid: options.uid, gid: options.gid, backup: options.backup, context: options.context, local: options.local }); this.execute({ "if": function() { return (options.loader === 'systemctl') && (path.dirname(options.target) === '/etc/init.d'); }, shy: true, cmd: cmd, code_skipped: 1 }); return this.execute({ "if": function() { return this.status(-1); }, cmd: 'systemctl daemon-reload' }); }); }; fs = require('ssh2-fs'); path = require('path'); discover = require('../misc/discover');