搜索

此内容没有您所选择的语言版本。

3.4. Managing Services in Software Collections

download PDF
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
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
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
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"
    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
  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
    with:
    scl enable $[SCLNAME]_SCLS_ENABLED -- /usr/bin/daemon_binary --argument-1 --argument-2
  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'
    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'

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"
    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
  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
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.