Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


## [Unreleased]
### Added
- [CONNECT] New easy way to connect to redis and mongodb
### Changed
- [COMMON] Use new mongodb `connect` command to interact with all versions of DB

Expand Down
7 changes: 7 additions & 0 deletions usr/local/bin/vlt-admin
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Available Commands:
upgrade-pkg Upgrade the packages.
snapshot Create and manage machine ZFS snapshots.
restore Use Snapshots to rollback all or parts of the machine.
connect Connect to mongodb and redis easily.

Use "vlt-admin -v" for version information.
Use "vlt-admin <command> -h" for more information about a command.
Expand Down Expand Up @@ -65,6 +66,12 @@ case "${CMD}" in
upgrade-os|upgrade-pkg)
# Nothing to do specificaly for there commands (apart from launching them)
;;
connect)
# Default to printing help if no argument is given
if [ $# -eq 0 ]; then
PARAMS='-h'
fi
;;
*) # Print usage if sub-command is unknown
error "unknown command ${CMD}"
usage
Expand Down
22 changes: 21 additions & 1 deletion usr/local/share/vulture-utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,27 @@ exec_mongo() {
return 1
fi

/usr/sbin/jexec mongodb connect -- --eval "${_command}"
if [ -z "${_command}" ]; then
/usr/sbin/jexec mongodb connect
else
/usr/sbin/jexec mongodb connect -- --eval "${_command}"
fi
return $?
}

exec_redis() {
_command="$1"
_password="$(grep -F 'masterauth' /zroot/redis/usr/local/etc/redis/redis.conf | sed -n 's/masterauth "\(.*\)"/\1/p')"

if ! /usr/sbin/jls | /usr/bin/grep -q redis; then
return 1
fi

if [ -z "${_password}" ]; then
/usr/sbin/jexec redis /usr/local/bin/redis-cli ${_command}
else
REDISCLI_AUTH="$_password" /usr/sbin/jexec redis /usr/local/bin/redis-cli ${_command}
fi
return $?
}

Expand Down
49 changes: 49 additions & 0 deletions usr/local/share/vulture-utils/connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env sh

. /usr/local/share/vulture-utils/common.sh

#############
# variables #
#############
VALID_JAILS="mongodb redis"

#############
# functions #
#############
usage() {
echo "USAGE connect [jail name]"
echo "This script is a wrapper to connect easily to mongodb or redis"
echo ""
echo "OPTIONS:"
echo " -h Display this help message"
exit 1
}

####################
# parse parameters #
####################
while getopts 'h' opt; do
case "${opt}" in
h|*) usage;
;;
esac
done
shift $((OPTIND-1))

jail="$1"
shift
_params="$*"

case "$jail" in
mongodb)
exec_mongo "$_params"
;;
redis)
exec_redis "$_params"
;;
*)
echo "Error: '$jail' is not a valid jail."
echo "Available jails: $VALID_JAILS"
exit 1
;;
esac
2 changes: 1 addition & 1 deletion usr/local/share/vulture-utils/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _rollback_datasets_list=""
#############
usage() {
echo "USAGE restore OPTIONS"
echo "This command triggers rollbacks on all or specific datasets, machine should then be restarted to apply the rollbacks"
echo "This script triggers rollbacks on all or specific datasets, machine should then be restarted to apply the rollbacks"
echo ""
echo "OPTIONS:"
echo " -A act on all underlying datasets"
Expand Down