Skip to content

Commit

Permalink
properly recreate the db when restoring and set the api_version when …
Browse files Browse the repository at this point in the history
…upgrading
  • Loading branch information
bdzim committed Oct 7, 2014
1 parent a9fc9e0 commit 169dd64
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 7 deletions.
10 changes: 10 additions & 0 deletions bin/resources/recreate_openmanage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT
pg_terminate_backend (pg_stat_activity.procpid)
FROM
pg_stat_activity
WHERE
pg_stat_activity.datname = 'openmanage'
and procpid != pg_backend_pid()
;
drop database openmanage;
create database openmanage;
6 changes: 3 additions & 3 deletions bin/restore_omva.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ cp -r layers/* $SPIDEROAK_ESCROW_LAYERS_PATH
cp agent_config.json $OPENMANAGE_CONFIGDIR

# Stage Three: Re-load the DB SQL.
sudo -u postgres dropdb openmanage
sudo -u postgres createdb openmanage
sudo -u postgres psql --single-transaction -f openmanage.sql openmanage
sudo -u postgres psql -f /opt/openmanage/bin/resources/recreate_openmanage.sql
sudo -u postgres psql --single-transaction --pset pager=off -f openmanage.sql openmanage

# We already have keys so we don't need to run first setup
touch /opt/openmanage/etc/.ran_firstsetup

# Clean up.
popd
rm -r openmanage-backup*
sudo sv restart admin_console
1 change: 1 addition & 0 deletions bin/run_restore_omva.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ BACKUP_BASE=$OPENMANAGE_ROOT/tmp_backup
rm -rf $BACKUP_BASE
mkdir $BACKUP_BASE


python $OPENMANAGE_ROOT/bin/restore_backup.py
18 changes: 18 additions & 0 deletions bin/set_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
from netkes import common
from netkes.account_mgr.accounts_api import Api

config = common.read_config_file()

if len(sys.argv) != 2:
print "version is required"
print "python set_version.py 1.2.3"
sys.exit(0)

if config['api_password']:
api = Api.create(
config["api_root"],
config["api_user"],
config["api_password"],
)
api.update_enterprise_settings(dict(api_version=sys.argv[1]))
2 changes: 1 addition & 1 deletion deploy/make_tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mkdir $buildit_dir
mkdir $buildit_dir/bin

find $source_dir/bin/*.pyc -delete 2> /dev/null || true # hack to make pipefail not fail
cp $source_dir/bin/* $buildit_dir/bin
cp -r $source_dir/bin/* $buildit_dir/bin

# Copy libraries
cp -r $source_dir/netkes $buildit_dir
Expand Down
4 changes: 2 additions & 2 deletions django/apps/blue_management/blue_mgnt/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def login_user(request):
config = read_config_file()
api = get_api(config)
if api.backup():
log_admin_action(request, 'restoring from backup')
subprocess.call(['/opt/openmanage/bin/run_restore_omva.sh',])

if not config['groups']:
elif not config['groups']:
create_initial_group()

config_mgr_ = config_mgr.ConfigManager(config_mgr.default_config())
Expand Down
5 changes: 4 additions & 1 deletion upgrade/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ for SERVICE in openmanage admin_console; do
sv up $SERVICE
done

# Backup vm
# Backup VM
sudo /opt/openmanage/bin/backup_omva.sh
echo "Backup complete"

# Set VM version
python /opt/openmanage/bin/set_version.py $VERSION

echo "Upgrade complete!"

0 comments on commit 169dd64

Please sign in to comment.