Remove mongodb when appropriate

This commit is contained in:
Bob Mottram 2017-11-20 10:47:18 +00:00
parent 89b7087c94
commit e500a0de3b
2 changed files with 39 additions and 1 deletions

View File

@ -256,6 +256,9 @@ function remove_smilodon {
function_check drop_database_mongodb
drop_database_mongodb smilodon
function_check remove_mongodb
remove_mongodb smilodon
remove_completion_param install_smilodon
sed -i '/smilodon_/d' $COMPLETION_FILE
}
@ -289,7 +292,7 @@ function install_smilodon {
useradd -c "Smilodon system account" -d $SMILODON_PATH -m -r -g smilodon smilodon
function_check install_mongodb
install_mongodb
install_mongodb smilodon
smilodon_create_database

View File

@ -30,6 +30,7 @@
# Set this when calling backup and restore commands
USE_MONGODB=
MONGODB_APPS_FILE=/root/.mongodbapps
function store_original_mongodb_password {
if [ ! -f /root/.mongodboriginal ]; then
@ -49,6 +50,8 @@ function get_mongodb_password {
}
function install_mongodb {
app_name=$1
if [[ "$(uname -a)" == *"armv7"* ]]; then
echo $'mongodb package is not available for arm 7 architecture'
exit 7356272
@ -81,9 +84,41 @@ function install_mongodb {
exit 78352
fi
if [ $app_name ]; then
if ! grep -q "$app_name" $MONGODB_APPS_FILE; then
echo "$app_name" >> $MONGODB_APPS_FILE
fi
fi
mark_completed $FUNCNAME
}
function remove_mongodb {
app_name=$1
if [ ! $app_name ]; then
return
fi
removemongo=
if [ -f $MONGODB_APPS_FILE ]; then
sed -i "/$app_name/d" $MONGODB_APPS_FILE
mongoapps=$(cat $MONGODB_APPS_FILE)
if [ ${#mongoapps} -lt 3 ]; then
removemongo=1
fi
else
removemongo=1
fi
if [ $removemongo ]; then
apt-get -yq remove mongodb mongo-tools
if [ -d /var/lib/mongodb ]; then
rm -rf /var/lib/mongodb
fi
fi
}
function add_mongodb_user {
mongodb_username=$1
mongodb_password=$2