2022-06-09 09:10:49 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
machine=${1:-0}
|
|
|
|
model=${2:-controller}
|
|
|
|
|
|
|
|
read -d '' -r cmds <<'EOF'
|
2022-10-20 13:41:17 +00:00
|
|
|
user=$(sudo ls /var/lib/juju/agents/ | grep machine)
|
2022-06-09 09:10:49 +00:00
|
|
|
conf=/var/lib/juju/agents/${user}/agent.conf
|
|
|
|
password=$(sudo grep statepassword ${conf} | cut -d' ' -f2)
|
|
|
|
if [ -f /usr/lib/juju/mongo*/bin/mongo ]; then
|
|
|
|
client=/usr/lib/juju/mongo*/bin/mongo
|
2022-10-20 13:41:17 +00:00
|
|
|
elif [ -f /usr/bin/mongo ]; then
|
2022-06-09 09:10:49 +00:00
|
|
|
client=/usr/bin/mongo
|
2022-10-20 13:41:17 +00:00
|
|
|
else
|
|
|
|
client=/snap/bin/juju-db.mongo
|
2022-06-09 09:10:49 +00:00
|
|
|
fi
|
|
|
|
${client} 127.0.0.1:37017/juju --authenticationDatabase admin --ssl --sslAllowInvalidCertificates --username "${user}" --password "${password}" --eval "rs.status()" | grep -P '(name|stateStr)'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
juju ssh -m ${model} ${machine} "${cmds}"
|