useful_scripts/check_mongo.sh

22 lines
616 B
Bash
Raw Permalink Normal View History

2021-10-12 19:24:31 +00:00
#!/bin/bash
machine=${1:-0}
model=${2:-controller}
read -d '' -r cmds <<'EOF'
user=$(sudo ls /var/lib/juju/agents/ | grep machine)
2022-03-31 11:44:52 +00:00
conf=/var/lib/juju/agents/${user}/agent.conf
password=$(sudo grep statepassword ${conf} | cut -d' ' -f2)
2021-10-12 19:24:31 +00:00
if [ -f /usr/lib/juju/mongo*/bin/mongo ]; then
client=/usr/lib/juju/mongo*/bin/mongo
elif [ -f /usr/bin/mongo ] ; then
2021-10-12 19:24:31 +00:00
client=/usr/bin/mongo
else
client=/snap/bin/juju-db.mongo
2021-10-12 19:24:31 +00:00
fi
2022-03-31 11:44:52 +00:00
${client} 127.0.0.1:37017/juju --authenticationDatabase admin --ssl --sslAllowInvalidCertificates --username "${user}" --password "${password}"
2021-10-12 19:24:31 +00:00
EOF
2022-03-31 11:44:52 +00:00
juju ssh -m ${model} ${machine} "${cmds}"
2021-10-12 19:24:31 +00:00