| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/nami/node_modules/provisioner/lib/ |
Upload File : |
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const nami_wrapper_1 = require("./nami_wrapper");
const bitnami_module_1 = require("./bitnami_module");
const arguments_handler_1 = require("./arguments_handler");
const logger_1 = require("./logger");
/**
* Class for performing basic actions on a bash-based module
*/
class BashModule extends bitnami_module_1.BitnamiModule {
/**
* Create instance of bash-based module handler
* @param tierDefinition definition of current tier (part of multi-VM deployment)
* @param moduleDefinition definition of this specific module
*/
constructor(tierDefinition, moduleDefinition) {
super(tierDefinition, moduleDefinition);
this.tierDefinition = tierDefinition;
this.moduleDefinition = moduleDefinition;
this._installationRoot = this.provisioner.platform.pathInfo.namiAppPath;
this._additionalFiles = moduleDefinition.additionalFiles || {};
this._exports = moduleDefinition.exports || {};
// We use ArgumentHandler to parse Provisioner variables such as appPassword
this._environmentHandler = new arguments_handler_1.ArgumentHandler(moduleDefinition.environment || [], this.provisioner, this.logger);
}
/**
* Whether an object is a service and should be started/stopped when all services should be
* stopped and started accordingly
*/
get isService() {
// Consider it includes a service if it exports the "start" method
return !!this._exports["start"];
}
/**
* Install a module from directory where it was previously downloaded
* (by provisioner or other tool)
* @param directory Directory where module was downloaded to, NOT the subdirectory with module
*/
installModuleFromDirectory(directory) {
// The module has already been extracted, so we must copy the files
// We use 'cp' with '-a' option to avoid converting hard links to files, which file.copy does not currently support
// This is the case for Git, where it causes issues with the output size (>600M without hard links, 30M without)
const srcDir = nami_wrapper_1.file.join(directory, this.baseName);
nami_wrapper_1.os.runProgram("cp", ["-R", "-a", `${srcDir}/files/.`, this._installationRoot], { logger: this.logger });
// Create required files
for (let filePath in this._additionalFiles) {
this.logger.debug(`Creating ${filePath}`);
nami_wrapper_1.file.write(filePath, nami_wrapper_1.crypt.base64(this._additionalFiles[filePath].data.content, "decode"));
nami_wrapper_1.file.chmod(filePath, this._additionalFiles[filePath].data.mode);
}
}
/**
* List of environment variables used by the module
*/
get environment() {
if (!this._environment) {
let args = this._environmentHandler.arguments;
// Additional environment variables
const distroName = `${this.provisioner.platform.distro}-${this.provisioner.platform.distroVersion}`;
const osArch = this.provisioner.platform.osArch;
const os = osArch.split("-")[0];
const arch = osArch.split("-").slice(1).join("-");
// Parse environment variables to be a key-value object
// It needed to be in array format in order for ArgumentsHandler to support it
this._environment = args.reduce(function (result, item, index, array) {
const splittedEnvVar = item.split("=");
const name = splittedEnvVar[0];
const value = splittedEnvVar.slice(1).join("=");
result[name] = value;
return result;
}, {
PATH: `${this.provisioner.platform.getAdditionalSystemPaths().join(":")}:${process.env.PATH}`,
OS_ARCH: arch,
OS_FLAVOUR: distroName,
OS_NAME: os,
});
}
if (this.logger.logLevel >= logger_1.LogLevel.DEBUG) {
this._environment.BITNAMI_DEBUG = "true";
this.logger.debug(`Injecting the following environment: ${JSON.stringify(this._environment)}`);
}
return this._environment;
}
/**
* Initialize a module ; arguments to pass to module are taken from its definition
*/
initializeModule() {
this.runExport("setup");
}
/**
* Start or stop a module
*/
serviceCommand(cmd) {
this.runExport(cmd);
}
/**
* Execute an exported function
*/
runExport(cmd, args) {
// Ensure the cmd is defined before running it
if (this.exportsFunction(cmd)) {
this.logger.verbose(`Running export ${cmd} for ${this.moduleDefinition.name}`);
const env = this.environment;
const bashCommand = this._exports[cmd].split(" ").concat(args || []).join(" ");
const res = nami_wrapper_1.os.runProgram("bash", ["--login", "-c", bashCommand], {
env, retrieveStdStreams: true, logger: this.logger, detachStdStreams: true,
});
process.stdout.write(res.stdout);
process.stderr.write(res.stderr);
if (res.code !== 0) {
throw new Error(`Export ${cmd} for ${this.moduleDefinition.name} failed with exit code ${res.code}`);
}
}
else {
this.logger.debug(`Export ${cmd} is not defined for ${this.moduleDefinition.name}`);
}
}
/**
* Check if the module exports a function
*/
exportsFunction(cmd) {
return !!this._exports[cmd];
}
}
exports.BashModule = BashModule;