| 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/recipes/ |
Upload File : |
/// <reference path="../../typings-recipe.d.ts" />
/*
* Recipe for handling the Bitnami Agent
*/
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const agentDirectory = `${platform.pathInfo.namiAppPath}/stats`;
const agentConfFile = `${agentDirectory}/agent.conf`;
const bitnamiLegacyPropertiesFile = "/opt/bitnami/properties.ini";
const agentExtraPropertiesFile = `${agentDirectory}/extra.ini`;
const agentBinary = `${agentDirectory}/agent.bin`;
const agentPropertiesFile = `${agentDirectory}/settings.db`;
recipes.register({
id: "agent-init",
on: { afterInitialize: {}, afterFailedInitialize: {} },
conditions: {
platformTags: { any: ["linux"] },
cloudTags: { not: { any: ["skip-agent"] } },
// don't run if the machine was provisioned externally
shouldInvoke: (input) => !(input.provisioner.provisioned)
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (!$file.exists(agentDirectory)) {
logger.trace("Bitnami Agent directory not found. Skipping initialization.");
return;
}
let agentMinute = (new Date).getMinutes();
let bitnamiUser = "bitnami";
// make sure we do not have any leftovers
$file.substitute(agentConfFile, [
{ pattern: RegExp(".*installation_guid.*"), value: "" },
{ pattern: RegExp(".*generated\\sby\\sthe.*"), value: "" }
], {
multiline: false
});
// setup cron
$file.substitute("/etc/crontab", [
{ pattern: /.*agent\.bin.*/, value: "" }
], {
multiline: false
});
let agentCommand = `cd ${agentDirectory} && ./agent.bin --run -D`;
let cronLine = `${agentMinute} * * * * ${bitnamiUser} ${agentCommand}`;
if (!$file.exists(agentExtraPropertiesFile)) {
const deploymentId = provisioner.uniqueDeploymentId || "";
$file.touch(agentExtraPropertiesFile);
$file.append(agentExtraPropertiesFile, "[all]\n");
$file.append(agentExtraPropertiesFile, `instance_tier_id=${provisioner.instanceTier}\n`);
if (deploymentId !== "") {
$file.append(agentExtraPropertiesFile, "deployment_type=nami\n");
$file.append(agentExtraPropertiesFile, `deployment_id=${deploymentId}\n`);
}
else {
$file.append(agentExtraPropertiesFile, "deployment_type=nami_singlevm\n");
}
// demo detection
let is_demo = yield cloud.getUserDataBoolean("demo_machine");
if (is_demo && is_demo !== undefined) {
$file.append(agentExtraPropertiesFile, `demo_machine=${is_demo}\n`);
}
// process extra properties
let extraPropertyNames = yield cloud.getUserData("bitnami_agent_extra");
if (extraPropertyNames !== "" && extraPropertyNames !== undefined) {
for (const l of extraPropertyNames.split(" ")) {
$file.append(agentExtraPropertiesFile, `${l}=${yield cloud.getUserData(l)}\n`);
}
}
// add a testing mode
if (yield cloud.isBitnamiTestingMode()) {
$file.append(agentExtraPropertiesFile, "testing_mode=1\n");
}
// add account-id if available
const accountId = yield cloud.getMetaData("account-id");
if (accountId && accountId.length > 0) {
const hash = utils.createHashAsHex(accountId, "sha256");
$file.append(agentExtraPropertiesFile, `account_id_sha256=${hash}\n`);
}
}
// write properties.ini file
if (!$file.exists(bitnamiLegacyPropertiesFile)) {
$file.touch(bitnamiLegacyPropertiesFile);
$file.append(bitnamiLegacyPropertiesFile, "[General]\n");
let details = provisioner.stackDefinition.details;
$file.append(bitnamiLegacyPropertiesFile, `base_stack_name=${details.name}\n`);
$file.append(bitnamiLegacyPropertiesFile, `base_stack_key=${details.key}\n`);
$file.append(bitnamiLegacyPropertiesFile, `base_stack_version=${details.version}\n`);
}
// set proper permissions
$file.chmod(agentBinary, "0755");
$file.chown(agentDirectory, "bitnami", "bitnami", { recursive: true });
// run the agent for the first time
$os.runProgram("sh", ["-c", agentCommand], { runAs: bitnamiUser });
// register with crontab, after everything else has been run
platform.createFileSection("/etc/crontab", { title: "BITNAMI AGENT", contents: cronLine });
let agentConf = $file.read(agentConfFile);
logger.trace(`Agent Config File (${agentConfFile}):\n${agentConf}`);
});
}
});