Skip to content

Commit

Permalink
squash w/ startup/shutdown. Add dedicated upgrade python script for u…
Browse files Browse the repository at this point in the history
…pgrading the server.
  • Loading branch information
korydraughn committed Nov 11, 2024
1 parent b746b53 commit 21cbb8f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
1 change: 0 additions & 1 deletion scripts/irods_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def main():
operations_dict['restart'] = lambda: irods_controller.restart(write_to_stdout=options.write_to_stdout, test_mode=options.test_mode)
operations_dict['status'] = lambda: irods_controller.status()
operations_dict['get_environment'] = lambda: irods_config.print_execution_environment()
operations_dict['upgrade'] = lambda: irods_controller.upgrade()

(options, arguments) = parse_options()
if len(arguments) != 1:
Expand Down
77 changes: 77 additions & 0 deletions scripts/upgrade_irods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! /usr/bin/python3

import argparse
import json
import logging
import os
import sys

import irods.paths

# Wrapper to set up LD_LIBRARY_PATH.
def wrap_if_necessary():
with open(irods.paths.server_config_path()) as server_config_path:
server_config = json.load(server_config_path)
ld_library_path_list = [p for p in server_config.get('environment_variables', {}).get('LD_LIBRARY_PATH', '').split(':') if p]

# For Oracle databases, ORACLE_HOME must be in LD_LIBRARY_PATH.
oracle_home = server_config.get('environment_variables', {}).get('ORACLE_HOME', None)
if oracle_home is None:
oracle_home = os.environ.get('ORACLE_HOME', None)
if oracle_home is not None:
oracle_lib_dir = os.path.join(oracle_home, 'lib')
if oracle_lib_dir not in ld_library_path_list:
ld_library_path_list.append(oracle_lib_dir)

current_ld_library_path_list = [p for p in os.environ.get('LD_LIBRARY_PATH', '').split(':') if p]
if ld_library_path_list != current_ld_library_path_list[0:len(ld_library_path_list)]:
os.environ['LD_LIBRARY_PATH'] = ':'.join(ld_library_path_list + current_ld_library_path_list)
argv = [sys.executable] + sys.argv
os.execve(argv[0], argv, os.environ)

wrap_if_necessary()

from irods.configuration import IrodsConfig
from irods.controller import IrodsController
from irods.exceptions import IrodsError
import irods.lib
import irods.log

def main():
logging.getLogger().setLevel(logging.NOTSET)
l = logging.getLogger(__name__)

irods.log.register_tty_handler(sys.stderr, logging.WARNING, None)

if (os.geteuid() == 0):
l.error('upgrade_irods.py should NOT be run by the root user.\nExiting...')
return 1

parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='count', default=0, help='Verbose mode. Passing more -v increases the verbosity.')
args = parser.parse_args()

log_levels = [
logging.WARNING,
logging.INFO,
logging.DEBUG,
]
lvl = [max(0, min(args.verbose, len(log_levels) - 1))]
irods.log.register_tty_handler(sys.stdout, log_levels[lvl], logging.WARNING)

irods_config = IrodsConfig()
irods.log.register_file_handler(irods_config.control_log_path)

try:
IrodsController(irods_config).upgrade()
except IrodsError as e:
l.error('Error encountered running irods_control %s:\n', operation), exc_info=True)
l.info('Exiting...')
return 1

return 0

logging.getLogger(__name__).addHandler(irods.log.NullHandler())

if __name__ == '__main__':
sys.exit(main())

0 comments on commit 21cbb8f

Please sign in to comment.