Skip to content

Instantly share code, notes, and snippets.

@dale-c-anderson
Last active June 15, 2022 00:32
Show Gist options
  • Save dale-c-anderson/4c8dd5a566a0be6f079ca8aaef834636 to your computer and use it in GitHub Desktop.
Save dale-c-anderson/4c8dd5a566a0be6f079ca8aaef834636 to your computer and use it in GitHub Desktop.
Purge solr service and data from ubuntu
#!/bin/bash
set -eu -o pipefail
# --------------------------------------------
# ---------- USE AT YOUR OWN RISK -----------
# --------------------------------------------
# Remove Solr from Ubuntu, as long as it was installed with defaults.
# As of 2022, works for any version of solr on any version of Ubuntu.
# --------------------------------------------
# ---------- USE AT YOUR OWN RISK -----------
# --------------------------------------------
(set -x && service solr stop) || true
(umask 007 && mkdir -pv /var/backups/solr)
DATESTAMP=$(date +%s.%N)
test -d /var/solr/ && {
BAKFILE="/var/backups/solr/var-solr.$DATESTAMP"
echo "Backing up /var/solr to $BAKFILE"
( umask 007 && tar --create --file "$BAKFILE" --verbose --total --directory /var solr/ )
}
test -d /opt/solr/ && {
BAKFILE="/var/backups/solr/opt-solr.$DATESTAMP"
echo "Backing up /opt/solr to $BAKFILE"
( umask 007 && tar --create --file "$BAKFILE" --verbose --total --directory /opt solr/ )
}
test -d /etc/ && {
BAKFILE="/var/backups/solr/etc.$DATESTAMP"
echo "Backing up /etc to $BAKFILE"
( umask 007 && tar --create --file "$BAKFILE" --verbose --total --directory / etc/ )
}
(set -x && rm -r /var/solr/) || true
(set -x && rm -r /opt/solr/) || true # will remove it if its a dir.
(set -x && rm /opt/solr) || true # will remove the remaining file if its a symlink
(set -x && rm /etc/init.d/solr) || true
(set -x && deluser --remove-home solr) || true
(set -x && deluser --group solr) || true
(set -x && rm /etc/default/solr.in.sh) || true
(set -x && update-rc.d -f solr remove) || true
>&2 echo '# ----------------------------------------------------------------------'
>&2 echo '# Use following command to verify whether or not removal was successful:'
>&2 echo '# ----------------------------------------------------------------------'
>&2 echo '# :~$ updatedb && locate solr'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment