UNPKG

mecano

Version:

Common functions for system deployment.

127 lines (119 loc) 3.44 kB
// Generated by CoffeeScript 1.11.1 var discover, fs, merge, misc, path, uid_gid; module.exports = function(options) { var i, key, len, ref; options.log({ message: "Entering tmpfs action", level: 'DEBUG', module: 'mecano/tmpfs/index' }); if (options.mount == null) { throw Error('Missing Mount Point'); } if (options.merge == null) { options.merge = true; } if (options.backup == null) { options.backup = true; } if (options.perm == null) { options.perm = '0644'; } options.content = {}; options.content[options.mount] = {}; ref = ['mount', 'perm', 'uid', 'gid', 'age', 'argu']; for (i = 0, len = ref.length; i < len; i++) { key = ref[i]; options.content[options.mount][key] = options[key]; } options.content[options.mount]['type'] = 'd'; if (options.uid != null) { if (!/^[0-9]+/.exec(options.uid)) { if (options.name == null) { options.name = options.uid; } } } this.call(discover.system, function() { var available, ref1; available = ((ref1 = options.store['mecano:system:type']) === 'redhat' || ref1 === 'centos') && (options.store['mecano:system:release'][0] === '7'); if (!available) { throw Error('tempfs not available on your OS'); } options.log({ message: "discovering tmpfs file target", level: 'DEBUG', module: 'mecano/tmpfs/index' }); if (options.target == null) { options.target = options.name != null ? "/etc/tmpfiles.d/" + options.name + ".conf" : '/etc/tmpfiles.d/default.conf'; } return options.log({ message: "target set to " + options.target, level: 'DEBUG', module: 'mecano/tmpfs/index' }); }); this.call({ shy: true, "if": options.merge, handler: function(_, callback) { options.log({ message: "opening target file for merge", level: 'DEBUG', module: 'mecano/tmpfs/index' }); return fs.readFile(options.ssh, options.target, 'utf8', function(err, data) { var source; if (err) { if (err.code === 'ENOENT') { return callback(null, false); } if (err) { return callback(err); } } else { source = misc.tmpfs.parse(data); options.content = merge({}, source, options.content); options.log({ message: "content has been merged", level: 'DEBUG', module: 'mecano/tmpfs/index' }); return callback(null, false); } }); } }); return this.call(function() { this.file(options, { content: misc.tmpfs.stringify(options.content), merge: false, target: options.target }); return this.call({ "if": function() { return this.status(-1); }, handler: function() { options.log({ message: "re-creating " + options.mount + " tmpfs file", level: 'INFO', module: 'mecano/tmpfs/index' }); this.execute({ cmd: "systemd-tmpfiles --remove " + options.target }); return this.execute({ cmd: "systemd-tmpfiles --create " + options.target }); } }); }); }; fs = require('ssh2-fs'); path = require('path'); uid_gid = require('../misc/uid_gid'); discover = require('../misc/discover'); misc = require('../misc'); merge = require('../misc').merge;