3.4. Managing Services in Software Collections When packaging your Software Collection, ensure that users can directly manage any services (daemons) provided by the Software Collection or one of the associated applications with the system default tools, like service or chkconfig on Red Hat Enterprise Linux 6, or systemctl on Red Hat Enterprise Linux 7. For Software Collections on Red Hat Enterprise Linux 6, make sure to adjust the %install section of the spec file as follows to avoid possible name conflicts with the system versions of the services that are part of the Software Collection: %install install -p -c -m 644 %{SOURCE2} USDRPM_BUILD_ROOT%{?scl:%_root_sysconfdir}%{!?scl:%_sysconfdir}/rc.d/init.d/%{?scl_prefix} service_name Replace service_name with the actual name of the service. For Software Collections on Red Hat Enterprise Linux 7, adjust the %install section of the spec file as follows: %install install -p -c -m 644 %{SOURCE2} USDRPM_BUILD_ROOT%{_unitdir}/%{?scl_prefix} service_name .service With this configuration in place, you can then refer to the version of the service included in the Software Collection as follows: Keep in mind that no environment variables are propagated from the user's environment to a SysV init script (or a systemd service file on Red Hat Enterprise Linux 7). This is expected and ensures that services are always started in a clean environment. However, this requires you to properly set up a Software Collection environment for processes that are to be run by the SysV init scripts (or systemd service files). 3.4.1. Configuring an Environment for Services It is recommended to make the Software Collection you want to enable for services configurable. The directions in this section show how to make a Software Collection named software_collection configurable. Procedure 3.2. Configuring an environment for services on Red Hat Enterprise Linux 6 Create a configuration file in /opt/provider/ software_collection /service-environment with the following content: Replace SCLNAME with a unique identifier for your Software Collection, for instance, your Software Collection's name written in capital letters. Replace software_collection with the name of your Software Collection as defined by the %scl_name macro. Add the following line at the beginning of the SysV init script: In the SysV init script, determine commands that run binaries located in the /opt/provider/ file system hierarchy. Prefix these commands with scl enable USD[SCLNAME]_SCLS_ENABLED , similarly to when you run a command in the Software Collection environment. For example, replace the following line: with: Some commands, like su or runuser , also clear environment variables. Thus, if these commands are used in the SysV init script, enable your Software Collection again after running these commands. For instance, replace the following line: with: Procedure 3.3. Configuring an environment for services on Red Hat Enterprise Linux 7 Create a configuration file in /opt/provider/ software_collection /service-environment with the following content: Replace SCLNAME with a unique identifier for your Software Collection, for instance, your Software Collection's name written in capital letters. Replace software_collection with the name of your Software Collection as defined by the %scl_name macro. Add the following line in the systemd service file to load the configuration file: In the systemd service file, prefix all commands specified in ExecStartPre , ExecStart , and similar directives with scl enable USD[SCLNAME]_SCLS_ENABLED , similarly to when you run a command in the Software Collection environment: Warning Prefixing ExecStart* commands with scl enable ... as described above will prevent the service from transitioning to its target SELinux context indicated by the SELinux policy in effect. If the service is supposed to be confined using SELinux, the systemd service file needs to execute the binary directly. If the binary is linked against shared libraries which are part of the Software Collection, the DT_RUNPATH attribute may help make those shared libraries accessible at runtime without the need for using the scl enable ... wrapper. See Section 3.15.1, "SELinux Support in Red Hat Enterprise Linux 7" for more information.

Commands:
%install install -p -c -m 644 %{SOURCE2} USDRPM_BUILD_ROOT%{?scl:%_root_sysconfdir}%{!?scl:%_sysconfdir}/rc.d/init.d/%{?scl_prefix} service_name
%install install -p -c -m 644 %{SOURCE2} USDRPM_BUILD_ROOT%{_unitdir}/%{?scl_prefix} service_name .service
%{?scl_prefix} service_name
[ SCLNAME ]_SCLS_ENABLED=" software_collection "
source /opt/provider/ software_collection /service-environment
/usr/bin/daemon_binary --argument-1 --argument-2
scl enable USD[SCLNAME]_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2
su - user_name -c '/usr/bin/daemon_binary --argument-1 --argument-2'
su - user_name -c ' source /opt/provider/software_collection/service-environment scl enable USDSCLNAME_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2'
[ SCLNAME ]_SCLS_ENABLED=" software_collection "
EnvironmentFile=/opt/provider/software_collection/service-environment
ExecStartPre=/usr/bin/scl enable USD[SCLNAME]_SCLS_ENABLED -- /opt/provider/software_collection/root/usr/bin/daemon_helper_binary --argument-1 --argument-2 ExecStart=/usr/bin/scl enable USD[SCLNAME]_SCLS_ENABLED -- /opt/provider/software_collection/root/usr/bin/daemon_binary --argument-1 --argument-2