Skip to content

Commit f168fbc

Browse files
authored
fix: jans-linux-setup centos/rhel pgsql installation (#3404)
1 parent ab30953 commit f168fbc

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

jans-linux-setup/jans_setup/setup_app/installers/rdbm.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from string import Template
99

10+
from setup_app import paths
1011
from setup_app.static import AppType, InstallOption
1112
from setup_app.config import Config
1213
from setup_app.utils import base
@@ -92,14 +93,31 @@ def local_install(self):
9293

9394
elif Config.rdbm_type == 'pgsql':
9495
if base.clone_type == 'rpm':
95-
self.restart('postgresql')
96+
self.run(['postgresql-setup', 'initdb'])
97+
elif base.clone_type == 'deb':
98+
self.run([paths.cmd_chmod, '640', '/etc/ssl/private/ssl-cert-snakeoil.key'])
99+
100+
self.restart('postgresql')
101+
96102
cmd_create_db = '''su - postgres -c "psql -U postgres -d postgres -c \\"CREATE DATABASE {};\\""'''.format(Config.rdbm_db)
97103
cmd_create_user = '''su - postgres -c "psql -U postgres -d postgres -c \\"CREATE USER {} WITH PASSWORD '{}';\\""'''.format(Config.rdbm_user, Config.rdbm_password)
98104
cmd_grant_previlages = '''su - postgres -c "psql -U postgres -d postgres -c \\"GRANT ALL PRIVILEGES ON DATABASE {} TO {};\\""'''.format(Config.rdbm_db, Config.rdbm_user)
99105

100106
for cmd in (cmd_create_db, cmd_create_user, cmd_grant_previlages):
101107
self.run(cmd, shell=True)
102108

109+
if base.clone_type == 'rpm':
110+
hba_file_path_query = self.run('''su - postgres -c "psql -U postgres -d postgres -t -c \\"SHOW hba_file;\\""''', shell=True)
111+
if hba_file_path_query and hba_file_path_query.strip():
112+
self.stop('postgresql')
113+
hba_file_path = hba_file_path_query.strip()
114+
hba_file_content = self.readFile(hba_file_path)
115+
hba_file_content = 'host\t{0}\t{1}\t127.0.0.1/32\tmd5\nhost\t{0}\t{1}\t::1/128\tmd5\n'.format(Config.rdbm_db, Config.rdbm_user) + hba_file_content
116+
self.writeFile(hba_file_path, hba_file_content)
117+
self.start('postgresql')
118+
119+
self.enable('postgresql')
120+
103121
self.dbUtils.bind(force=True)
104122

105123
def get_sql_col_type(self, attrname, table=None):

jans-linux-setup/jans_setup/setup_app/utils/package_utils.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ def check_and_install_packages(self):
5757
if base.argsp.local_rdbm == 'mysql' or (Config.get('rdbm_install_type') == InstallTypes.LOCAL and Config.rdbm_type == 'mysql'):
5858
package_list[os_type_version]['mandatory'] += ' mysql-server'
5959
if base.argsp.local_rdbm == 'pgsql' or (Config.get('rdbm_install_type') == InstallTypes.LOCAL and Config.rdbm_type == 'pgsql'):
60-
package_list[os_type_version]['mandatory'] += ' postgresql python3-psycopg2'
60+
package_list[os_type_version]['mandatory'] += ' postgresql python3-psycopg2 postgresql-contrib'
6161
if base.clone_type == 'deb':
62-
package_list[os_type_version]['mandatory'] += ' postgresql-contrib'
62+
package_list[os_type_version]['mandatory'] += ''
63+
elif base.clone_type == 'rpm':
64+
package_list[os_type_version]['mandatory'] += ' postgresql-server'
65+
self.run(['dnf', '-y', 'module', 'disable', 'postgresql'])
66+
self.run(['dnf', '-y', 'module', 'reset', 'postgresql'])
67+
self.run(['dnf', '-y', 'module', 'enable', 'postgresql:12'])
68+
6369

6470
for pypackage in package_list[os_type_version]['python']:
6571
try:

jans-linux-setup/jans_setup/setup_app/utils/setup_utils.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import string
1212
import random
1313
import hashlib
14+
import grp
1415

1516
from pathlib import Path
1617
from urllib.parse import urlparse
@@ -406,9 +407,21 @@ def renderTemplate(self, filePath):
406407

407408
def createUser(self, userName, homeDir, shell='/bin/bash'):
408409

410+
try:
411+
grp.getgrnam(userName)
412+
user_group_exists = True
413+
except KeyError:
414+
user_group_exists = False
415+
409416
try:
410417
useradd = '/usr/sbin/useradd'
411-
cmd = [useradd, '--system', '--user-group', '--shell', shell, userName]
418+
cmd = [useradd, '--system', '--shell', shell, userName]
419+
if user_group_exists:
420+
cmd.insert(1, '-g')
421+
cmd.insert(2, userName)
422+
else:
423+
cmd.insert(1, '--user-group')
424+
412425
if homeDir:
413426
cmd.insert(-1, '--create-home')
414427
cmd.insert(-1, '--home-dir')
@@ -420,8 +433,9 @@ def createUser(self, userName, homeDir, shell='/bin/bash'):
420433
self.logOSChanges("User %s with homedir %s was created" % (userName, homeDir))
421434
else:
422435
self.logOSChanges("User %s without homedir was created" % (userName))
423-
except:
424-
self.logIt("Error adding user", True)
436+
437+
except Exception as e:
438+
self.logIt("Error adding user: {}".format(e), True)
425439

426440
def createGroup(self, groupName):
427441
try:

0 commit comments

Comments
 (0)