Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jalogisch/df9e1be49287846161a77aabd7d2ea7b to your computer and use it in GitHub Desktop.
Save jalogisch/df9e1be49287846161a77aabd7d2ea7b to your computer and use it in GitHub Desktop.
ECE found-shell script to disable indexer mode and migrations for the adminconsole container. Create this file, chmod +X it, run it with the bypass option (1), fix your env, run the script again with the cleanup option (2)
#!/bin/bash
set -e
echo "=================================================================================================="
echo "NOTE: The script will set the Adminconsole to api-only mode (no indexer), so that"
echo " migrations are bypassed and Adminconsole can boot for environment salvage operations."
echo " Please run the same script with the cleanup option afterwards."
echo ""
echo "IMPORTANT: Until the cleanup script is run, adminconsole will not be able to index "
echo " changes in the admin cluster, breaking the Deployments dashboard and "
echo " other important functionality! Make sure to clean up after the "
echo " environment is properly salvaged."
echo "=================================================================================================="
while true; do
read -p "Enter 1 for Bypass or 2 for Cleanup: " ANSWER
case $ANSWER in
[1]* ) CREATE_BYPASS_BOOL=true; break;;
[2]* ) CREATE_BYPASS_BOOL=false; break;;
* ) echo "Please answer 1 or 2";;
esac
done
cat <<EOF > disable-adminconsole-indexer.fssh
import scala.concurrent._
import scala.collection.JavaConverters._
import no.found.json.mapper
import com.fasterxml.jackson.databind.node._
def run(): Unit = {
val disableIndexer = $CREATE_BYPASS_BOOL
zk"/container_sets/admin-consoles/containers/admin-console".update { data =>
println("Updating admin-console container set")
if (disableIndexer) println("- Ensuring FOUND_ADMINCONSOLE_APP_ROLES env var is set to 'adminapi'")
else println("- Ensuring FOUND_ADMINCONSOLE_APP_ROLES env var does not exist")
val cset = data.deepCopy()
val containerConfig = cset.path("container_config").asInstanceOf[ObjectNode]
val env = containerConfig.path("Env").asInstanceOf[ArrayNode].asScala.toList.filterNot(_.asText.startsWith("FOUND_ADMINCONSOLE_APP_ROLES"))
val newEnv = mapper.createArrayNode
env.foreach(newEnv.add)
if (disableIndexer) newEnv.add("FOUND_ADMINCONSOLE_APP_ROLES=adminapi")
containerConfig.put("Env", newEnv)
cset
}.run().futureValue.value
}
run()
EOF
##################################
echo "Running found-shell script"
docker run --env SHELL_JAVA_OPTIONS='-Dfound.shell.exec=/hostpwd/disable-adminconsole-indexer.fssh' \
-v $(pwd):/hostpwd -v ~/.found-shell:/elastic_cloud_apps/shell/.found-shell \
-e ELASTIC_UID=$(id -u) -e ELASTIC_GID=$(id -g) \
--env SHELL_ZK_AUTH=$(docker exec -it frc-directors-director bash -c 'echo -n $FOUND_ZK_READWRITE') $(docker inspect -f '{{ range .HostConfig.ExtraHosts }} --add-host {{.}} {{ end }}' frc-directors-director) --rm -it $(docker inspect -f '{{ .Config.Image }}' frc-directors-director) \
/elastic_cloud_apps/shell/run-shell.sh
echo "Removing admin-console container"
echo "NOTE: If this fails, log on to a Coordinator host and run 'docker rm -vf frc-admin-consoles-admin-console'"
docker rm -vf frc-admin-consoles-admin-console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment