diff --git a/bin/resources/recreate_openmanage.sql b/bin/resources/recreate_openmanage.sql new file mode 100644 index 0000000..cde3f85 --- /dev/null +++ b/bin/resources/recreate_openmanage.sql @@ -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; diff --git a/bin/restore_omva.sh b/bin/restore_omva.sh index c41c869..2546c51 100755 --- a/bin/restore_omva.sh +++ b/bin/restore_omva.sh @@ -33,9 +33,8 @@ 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 @@ -43,3 +42,4 @@ touch /opt/openmanage/etc/.ran_firstsetup # Clean up. popd rm -r openmanage-backup* +sudo sv restart admin_console diff --git a/bin/run_restore_omva.sh b/bin/run_restore_omva.sh index 632d5cd..3ad815c 100755 --- a/bin/run_restore_omva.sh +++ b/bin/run_restore_omva.sh @@ -14,4 +14,5 @@ BACKUP_BASE=$OPENMANAGE_ROOT/tmp_backup rm -rf $BACKUP_BASE mkdir $BACKUP_BASE + python $OPENMANAGE_ROOT/bin/restore_backup.py diff --git a/bin/set_version.py b/bin/set_version.py new file mode 100644 index 0000000..318c658 --- /dev/null +++ b/bin/set_version.py @@ -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])) diff --git a/deploy/make_tarball.sh b/deploy/make_tarball.sh index 6444f4c..462edb2 100755 --- a/deploy/make_tarball.sh +++ b/deploy/make_tarball.sh @@ -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 diff --git a/django/apps/blue_management/blue_mgnt/views/views.py b/django/apps/blue_management/blue_mgnt/views/views.py index 090d9db..1d9bd53 100644 --- a/django/apps/blue_management/blue_mgnt/views/views.py +++ b/django/apps/blue_management/blue_mgnt/views/views.py @@ -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()) diff --git a/upgrade/upgrade.sh b/upgrade/upgrade.sh index 5b4b37d..f5fd42b 100755 --- a/upgrade/upgrade.sh +++ b/upgrade/upgrade.sh @@ -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!"