Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add the java.hostname on migration if not already present #479

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion mgradm/shared/templates/migrateScriptTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ $SSH {{ .SourceFqdn }} sh -c "systemctl list-unit-files | grep hub-xmlrpc-api |

echo "Altering configuration for domain resolution..."
sed 's/report_db_host = {{ .SourceFqdn }}/report_db_host = localhost/' -i /etc/rhn/rhn.conf;
sed 's/server\.jabber_server/java\.hostname/' -i /etc/rhn/rhn.conf;
if test -z "$(grep '^java.hostname *=' /etc/rhn/rhn.conf)\"; then
sed 's/server\.jabber_server/java\.hostname/' -i /etc/rhn/rhn.conf;
fi
Comment on lines +122 to +124
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think test -z is needed. Grep returns 1 if string not found.

Suggested change
if test -z "$(grep '^java.hostname *=' /etc/rhn/rhn.conf)\"; then
sed 's/server\.jabber_server/java\.hostname/' -i /etc/rhn/rhn.conf;
fi
if ! grep -q '^java.hostname *=' /etc/rhn/rhn.conf); then
sed 's/server\.jabber_server/java\.hostname/' -i /etc/rhn/rhn.conf;
fi

should be enough, right?

sed 's/client_use_localhost: false/client_use_localhost: true/' -i /etc/cobbler/settings.yaml;

echo "Altering configuration for container environment..."
Expand Down
10 changes: 5 additions & 5 deletions shared/utils/serverinspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func NewServerInspector(scriptDir string) ServerInspector {
"sed 's/.*(\\([0-9.]*\\)).*/\\1/g' /etc/susemanager-release || true"),
types.NewInspectData(
"fqdn",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep 'java.hostname' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^java.hostname' | cut -d' ' -f3 || true"),
types.NewInspectData(
"image_pg_version",
"rpm -qa --qf '%{VERSION}\\n' 'name=postgresql[0-8][0-9]-server' | cut -d. -f1 | sort -n | tail -1 || true"),
types.NewInspectData("current_pg_version",
"(test -e /var/lib/pgsql/data/PG_VERSION && cat /var/lib/pgsql/data/PG_VERSION) || true"),
types.NewInspectData("db_user",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_user' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_user' | cut -d' ' -f3 || true"),
types.NewInspectData("db_password",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_password' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_password' | cut -d' ' -f3 || true"),
types.NewInspectData("db_name",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_name' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_name' | cut -d' ' -f3 || true"),
types.NewInspectData("db_port",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_port' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_port' | cut -d' ' -f3 || true"),
},
ScriptDir: scriptDir,
DataPath: path.Join(InspectContainerDirectory, inspectDataFile),
Expand Down
10 changes: 5 additions & 5 deletions shared/utils/serverinspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func TestServerInspectorGenerate(t *testing.T) {
# inspect.sh, generated by mgradm
echo "uyuni_release=$(cat /etc/*release | grep 'Uyuni release' | cut -d ' ' -f3 || true)" >> ` + dataPath + `
echo "suse_manager_release=$(sed 's/.*(\([0-9.]*\)).*/\1/g' /etc/susemanager-release || true)" >> ` + dataPath + `
echo "fqdn=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep 'java.hostname' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "fqdn=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^java.hostname' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "image_pg_version=$(rpm -qa --qf '%{VERSION}\n' 'name=postgresql[0-8][0-9]-server' | cut -d. -f1 | sort -n | tail -1 || true)" >> ` + dataPath + `
echo "current_pg_version=$((test -e /var/lib/pgsql/data/PG_VERSION && cat /var/lib/pgsql/data/PG_VERSION) || true)" >> ` + dataPath + `
echo "db_user=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_user' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_password=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_password' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_name=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_name' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_port=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_port' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_user=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_user' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_password=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_password' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_name=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_name' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_port=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_port' | cut -d' ' -f3 || true)" >> ` + dataPath + `
exit 0
`

Expand Down
1 change: 1 addition & 0 deletions uyuni-tools.changes.cbosdo.migration_fqdn_fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Only add java.hostname on migrated server if not present