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

fix: jans-linux-setup centos/rhel pgsql installation #3404

Merged
merged 1 commit into from
Dec 23, 2022
Merged
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
20 changes: 19 additions & 1 deletion jans-linux-setup/jans_setup/setup_app/installers/rdbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from string import Template

from setup_app import paths
from setup_app.static import AppType, InstallOption
from setup_app.config import Config
from setup_app.utils import base
Expand Down Expand Up @@ -92,14 +93,31 @@ def local_install(self):

elif Config.rdbm_type == 'pgsql':
if base.clone_type == 'rpm':
self.restart('postgresql')
self.run(['postgresql-setup', 'initdb'])
elif base.clone_type == 'deb':
self.run([paths.cmd_chmod, '640', '/etc/ssl/private/ssl-cert-snakeoil.key'])

self.restart('postgresql')

cmd_create_db = '''su - postgres -c "psql -U postgres -d postgres -c \\"CREATE DATABASE {};\\""'''.format(Config.rdbm_db)
cmd_create_user = '''su - postgres -c "psql -U postgres -d postgres -c \\"CREATE USER {} WITH PASSWORD '{}';\\""'''.format(Config.rdbm_user, Config.rdbm_password)
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)

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

if base.clone_type == 'rpm':
hba_file_path_query = self.run('''su - postgres -c "psql -U postgres -d postgres -t -c \\"SHOW hba_file;\\""''', shell=True)
if hba_file_path_query and hba_file_path_query.strip():
self.stop('postgresql')
hba_file_path = hba_file_path_query.strip()
hba_file_content = self.readFile(hba_file_path)
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
self.writeFile(hba_file_path, hba_file_content)
self.start('postgresql')

self.enable('postgresql')

self.dbUtils.bind(force=True)

def get_sql_col_type(self, attrname, table=None):
Expand Down
10 changes: 8 additions & 2 deletions jans-linux-setup/jans_setup/setup_app/utils/package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ def check_and_install_packages(self):
if base.argsp.local_rdbm == 'mysql' or (Config.get('rdbm_install_type') == InstallTypes.LOCAL and Config.rdbm_type == 'mysql'):
package_list[os_type_version]['mandatory'] += ' mysql-server'
if base.argsp.local_rdbm == 'pgsql' or (Config.get('rdbm_install_type') == InstallTypes.LOCAL and Config.rdbm_type == 'pgsql'):
package_list[os_type_version]['mandatory'] += ' postgresql python3-psycopg2'
package_list[os_type_version]['mandatory'] += ' postgresql python3-psycopg2 postgresql-contrib'
if base.clone_type == 'deb':
package_list[os_type_version]['mandatory'] += ' postgresql-contrib'
package_list[os_type_version]['mandatory'] += ''
elif base.clone_type == 'rpm':
package_list[os_type_version]['mandatory'] += ' postgresql-server'
self.run(['dnf', '-y', 'module', 'disable', 'postgresql'])
self.run(['dnf', '-y', 'module', 'reset', 'postgresql'])
self.run(['dnf', '-y', 'module', 'enable', 'postgresql:12'])


for pypackage in package_list[os_type_version]['python']:
try:
Expand Down
20 changes: 17 additions & 3 deletions jans-linux-setup/jans_setup/setup_app/utils/setup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import string
import random
import hashlib
import grp

from pathlib import Path
from urllib.parse import urlparse
Expand Down Expand Up @@ -406,9 +407,21 @@ def renderTemplate(self, filePath):

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

try:
grp.getgrnam(userName)
user_group_exists = True
except KeyError:
user_group_exists = False

try:
useradd = '/usr/sbin/useradd'
cmd = [useradd, '--system', '--user-group', '--shell', shell, userName]
cmd = [useradd, '--system', '--shell', shell, userName]
if user_group_exists:
cmd.insert(1, '-g')
cmd.insert(2, userName)
else:
cmd.insert(1, '--user-group')

if homeDir:
cmd.insert(-1, '--create-home')
cmd.insert(-1, '--home-dir')
Expand All @@ -420,8 +433,9 @@ def createUser(self, userName, homeDir, shell='/bin/bash'):
self.logOSChanges("User %s with homedir %s was created" % (userName, homeDir))
else:
self.logOSChanges("User %s without homedir was created" % (userName))
except:
self.logIt("Error adding user", True)

except Exception as e:
self.logIt("Error adding user: {}".format(e), True)

def createGroup(self, groupName):
try:
Expand Down