How can I make a Red Hat Software Collection persist after a reboot/logout?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 6.2 EUS and later
  • Red Hat Enterprise Linux 7.0 and later
  • Red Hat Software Collections 1.0 and later

Issue

  • When I reboot or logout of my machine, all my enabled software collections are disabled, and do not persist.

Resolution

Enabling SysV init services to persist after a reboot

The first problem is making SysV services like MySQL daemon from RHSCL enabled after rebooting -- this task is pretty straightforward; you only need to enable the correct SysV service. For example, mysql55 collection creates a new SysV init script called mysql55-mysqld under /etc/init.d, which you can handle the same as another SysV service files, only using the whole prefixed name. For example:

# chkconfig mysqld off
# chkconfig mysql55-mysqld on

A daemon from Red Hat Software Collections should now be started after next reboot, instead of daemon from the core-system. However, software collections will be properly enabled only for daemon processes, not for processes that interact with these daemons and are run by users (like mysql CLI, mysqldump utility, etc.). The usual way to enable software collections for whole sessions is to run a new bash wrapped with "scl enable" call, for example like that:

$ scl enable mysql55 bash

Enabling userspace environment automatically after logout/reboot

The second problem is enabling software collections for users after reboot, i.e. to allow them to work with a collection without calling "scl enable" all the time. This task is a bit more tricky, since Software collections weren't primarily design for such usage. The following is considered to be a work-around only, because we don't have a supported way to do it correctly now.

How the software collection concept works: The difference between running python from a software collection and core system's python is only in environment variables defined at a time you run python command. These variables are set using "scl enable python33 ..." call, which basically executes a bash script located in /opt/rh/python33/enable.

Generally, you are able to execute bash scripts that change environment of all users using files under /etc/profile.d/, so what you need is to enable desired collections here. The tricky part comes when you realize, that pure running "scl enable ..." in /etc/profile.d/something.sh doesn't work, because you cannot influence environment of the parent's process. For such a task we'd have to use a feature, that has been added into scl-utils recently, and is part of RHEL-6 since scl-utils-20120927-9.el6:

With that package, you can enable userspace environment automatically by creating a new file under /etc/profile.d with the following content (example for python33 collection):

$ cat /etc/profile.d/enablepython33.sh
#!/bin/bash
source scl_source enable python33

With such file all users will have python 3.3 collection enabled by default in shell.

NOTE: However, there is a side effect with this approach in that you cannot disable the collections thereafter. Also, shebang in the script affects which interpreter will be used.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments