| 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 adding information to welcome message
*/
"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 VERSION = 1;
const MOTD_FILE = "/etc/motd";
recipes.register({
id: "welcome-message-create",
on: { afterInitialize: {}, afterFailedInitialize: {} },
conditions: {
ifChanged: (input) => {
return VERSION;
},
// 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* () {
let storage = provisioner.storageManager.getItem("recipe-welcome-message");
let motd = "";
if ($file.exists(MOTD_FILE)) {
motd = $file.read(MOTD_FILE);
}
motd += " ___ _ _ _\n";
motd += " | _ |_) |_ _ _ __ _ _ __ (_)\n";
motd += " | _ \\ | _| ' \\/ _` | ' \\| |\n";
motd += " |___/_|\\__|_|_|\\__,_|_|_|_|_|\n";
motd += "\n";
motd += "************************************************************";
motd += "\n";
if (input.eventName === "afterInitialize") {
// TODO: we need more metadata to show more meaningful message.
motd += " This is a Bitnami server.\n";
motd += "\n";
if (provisioner.tierDefinition.tags.indexOf("fixed-public-url") > 0) {
motd += " The application is available at:\n";
motd += "\n";
motd += ` ##PUBLIC_URL##\n`;
}
else if (provisioner.stackDefinition.tags.indexOf("requires-application-gateway") > 0) {
// TODO It should get the public IP from the Application Gateway if there is one
}
else if (provisioner.tierDefinition.publicPorts.indexOf(443) >= 0) {
motd += " The application is available at:\n";
motd += "\n";
motd += ` https://##PUBLIC_IP##/\n`;
}
else if (provisioner.tierDefinition.publicPorts.indexOf(80) >= 0) {
motd += " The application is available at:\n";
motd += "\n";
motd += " http://##PUBLIC_IP##/\n";
}
}
else if (input.eventName === "afterFailedInitialize") {
motd += " The application initialization has failed with an error.\n";
motd += " More information can be found in the following log file:\n";
motd += "\n";
motd += " /opt/bitnami/var/log/first-boot.log\n";
}
motd += "\n";
motd += "************************************************************\n";
storage.data.motd = motd;
storage.save();
if (provisioner.tierDefinition.tags.indexOf("fixed-public-url") > 0) {
motd = motd.replace(/##PUBLIC_URL##/, yield cloud.getUserData("PROVISIONER_PUBLIC_URL"));
}
else {
motd = motd.replace(/##PUBLIC_IP##/, yield provisioner.cloud.getMetaData("public-ipv4"));
}
$file.write(MOTD_FILE, motd);
});
}
});
/*
* Recipe for writing message file before services are started
*/
recipes.register({
id: "welcome-message",
on: { beforeStart: {} },
conditions: {
tierTags: { not: ["fixed-public-url"] },
ifChanged: (input) => {
return provisioner.cloud.getMetaData("public-ipv4");
},
// 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* () {
let storage = provisioner.storageManager.getItem("recipe-welcome-message");
// TODO: private / public IP address ?
const publicIp = yield provisioner.cloud.getMetaData("public-ipv4");
let motd = storage.data.motd;
motd = motd.replace(/##PUBLIC_IP##/, publicIp);
$file.write(MOTD_FILE, motd);
});
}
});