Questo contenuto non è disponibile nella lingua selezionata.

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
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap
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

  1. Create a configuration file in /opt/provider/software_collection/service-environment with the following content:
    [SCLNAME]_SCLS_ENABLED="software_collection"
    Copy to Clipboard Toggle word wrap
    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.
  2. Add the following line at the beginning of the SysV init script:
    source /opt/provider/software_collection/service-environment
    Copy to Clipboard Toggle word wrap
  3. In the SysV init script, determine commands that run binaries located in the /opt/provider/ file system hierarchy. Prefix these commands with scl 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
    Copy to Clipboard Toggle word wrap
    with:
    scl enable $[SCLNAME]_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2
    Copy to Clipboard Toggle word wrap
  4. 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:
    su - user_name -c '/usr/bin/daemon_binary --argument-1 --argument-2'
    Copy to Clipboard Toggle word wrap
    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'
    Copy to Clipboard Toggle word wrap

Procedure 3.3. Configuring an environment for services on Red Hat Enterprise Linux 7

  1. Create a configuration file in /opt/provider/software_collection/service-environment with the following content:
    [SCLNAME]_SCLS_ENABLED="software_collection"
    Copy to Clipboard Toggle word wrap
    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.
  2. Add the following line in the systemd service file to load the configuration file:
    EnvironmentFile=/opt/provider/software_collection/service-environment
    Copy to Clipboard Toggle word wrap
  3. In the systemd service file, prefix all commands specified in ExecStartPre, ExecStart, and similar directives with scl 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
    Copy to Clipboard Toggle word wrap

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.
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat