Este contenido no está disponible en el idioma seleccionado.
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} $RPM_BUILD_ROOT%{?scl:%_root_sysconfdir}%{!?scl:%_sysconfdir}/rc.d/init.d/%{?scl_prefix}service_name
%install
install -p -c -m 644 %{SOURCE2} $RPM_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} $RPM_BUILD_ROOT%{_unitdir}/%{?scl_prefix}service_name.service
%install
install -p -c -m 644 %{SOURCE2} $RPM_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:
%{?scl_prefix}service_name
%{?scl_prefix}service_name
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 Copiar enlaceEnlace copiado en el portapapeles!
Copiar enlaceEnlace copiado en el portapapeles!
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-environmentwith the following content:[SCLNAME]_SCLS_ENABLED="software_collection"
[SCLNAME]_SCLS_ENABLED="software_collection"Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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_namemacro. - Add the following line at the beginning of the SysV init script:
source /opt/provider/software_collection/service-environment
source /opt/provider/software_collection/service-environmentCopy to Clipboard Copied! Toggle word wrap Toggle overflow - In the SysV init script, determine commands that run binaries located in the
/opt/provider/file system hierarchy. Prefix these commands withscl enable $[SCLNAME]_SCLS_ENABLED, similarly to when you run a command in the Software Collection environment.For example, replace the following line:/usr/bin/daemon_binary --argument-1 --argument-2
/usr/bin/daemon_binary --argument-1 --argument-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow with:scl enable $[SCLNAME]_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2
scl enable $[SCLNAME]_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Some commands, like
suorrunuser, 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:su - user_name -c '/usr/bin/daemon_binary --argument-1 --argument-2'
su - user_name -c '/usr/bin/daemon_binary --argument-1 --argument-2'Copy to Clipboard Copied! Toggle word wrap Toggle overflow with:su - user_name -c '\ source /opt/provider/software_collection/service-environment \ scl enable $SCLNAME_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2'
su - user_name -c '\ source /opt/provider/software_collection/service-environment \ scl enable $SCLNAME_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2'Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure 3.3. Configuring an environment for services on Red Hat Enterprise Linux 7
- Create a configuration file in
/opt/provider/software_collection/service-environmentwith the following content:[SCLNAME]_SCLS_ENABLED="software_collection"
[SCLNAME]_SCLS_ENABLED="software_collection"Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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_namemacro. - Add the following line in the systemd service file to load the configuration file:
EnvironmentFile=/opt/provider/software_collection/service-environment
EnvironmentFile=/opt/provider/software_collection/service-environmentCopy to Clipboard Copied! Toggle word wrap Toggle overflow - In the systemd service file, prefix all commands specified in
ExecStartPre,ExecStart, and similar directives withscl enable $[SCLNAME]_SCLS_ENABLED, similarly to when you run a command in the Software Collection environment:ExecStartPre=/usr/bin/scl enable $[SCLNAME]_SCLS_ENABLED -- /opt/provider/software_collection/root/usr/bin/daemon_helper_binary --argument-1 --argument-2 ExecStart=/usr/bin/scl enable $[SCLNAME]_SCLS_ENABLED -- /opt/provider/software_collection/root/usr/bin/daemon_binary --argument-1 --argument-2
ExecStartPre=/usr/bin/scl enable $[SCLNAME]_SCLS_ENABLED -- /opt/provider/software_collection/root/usr/bin/daemon_helper_binary --argument-1 --argument-2 ExecStart=/usr/bin/scl enable $[SCLNAME]_SCLS_ENABLED -- /opt/provider/software_collection/root/usr/bin/daemon_binary --argument-1 --argument-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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.