【问题标题】:how to deal with config changes in rpm for a nodejs app如何处理 nodejs 应用程序的 rpm 配置更改
【发布时间】:2015-06-07 19:02:56
【问题描述】:

我对使用 rpm 打包 nodejs 应用程序还很陌生。

要求我们始终合并配置文件中的任何更改,而不会清除系统管理员可能更改的任何设置。

如您所料,nodejs 应用程序的配置文件在 json 中。

我已经研究了 spec 文件中的 %config 和 %config(noreplace) ,并且 noreplace 更适合例外情况,如果我们在新配置文件中添加了一些新内容,那么将这些更改添加到现有文件中清除系统管理员可能所做的任何更改。

我发现很少有工具/shell 脚本可以做到这一点,但我不确定是否有更直接的方法或最佳实践可以实现这一目标?

【问题讨论】:

  • 我不确定我是否完全理解您的要求,但一般来说,如果 rpm 中有一个管理员可编辑的配置文件,那么它会被标记为 %config(noreplace) 并且最多管理员将其与新的上游配置文件进行比较并手动合并任何更改。
  • 我已经更新了问题。要求是合并配置文件中的潜在更改。这是非常基本的,在开发过程中我们有时会在配置中添加密钥,但是使用 rpm(noreplace)这些密钥永远不会进入我们安装软件的盒子。那么在这种情况下你会怎么做呢?
  • 为了一目了然,有没有一种方法可以检查新 rpm 中的更改并将其合并到已安装的 rpm 中?还是由系统管理员来合并更改(如果有)是一种常见的做法?
  • 正如我所说,对于为一般用途而设计的软件包,一般期望是管理员手动合并上游更改。合并是可能的(也完成了),但需要更仔细的测试/等。虽然没有任何内置的东西。您只需在%post 中做您需要做的事情。

标签: node.js shell centos rpm rpmbuild


【解决方案1】:

您需要一种在规范的%post 部分检测.rpmsave 文件的方法。它可能看起来像这样:

%post
# Check this during an update to the RPM $1 = 2
if [ "$1" = "2" ]
then
  ########################################################################
  # apply updates to config files, preserving any customizations
  #   1) restore original (customized) file if renamed to file.rpmsave
  #   2) run all config files through config_updates.pl
  ########################################################################
  #
  # RPM query will get config files from old and new rpm, so there will be dups
  # 
  IFS=$'\n'
  # Eliminate dups by passing query through sort -u %name is RPM name
  config_files=(`rpm -qc %name | sort -u`)
  unset IFS
  for AF in "${config_files[@]}"
  do
    # Search for config files with .rpmsave extension
    [ -f "$RF.rpmsave" ] && {
      # Save the new $RF file (cp -vf $RF $RF.new)
      # Copy the original rpm config file renamed during
      # the update with.rpmsave extension
      # back to $RF (cp -vf $RF.rpmsave $RF)
      # Launch another script to merge $RF.new into $RF.
      %dir_to_config_script/config_updates.pl -file=$RF
    }
  done
fi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2017-03-03
    • 2013-01-08
    • 2013-12-23
    相关资源
    最近更新 更多