Search code examples
cmakeredhatrpm

Is %config(noreplace) enough to instruct an RPM not to touch a config file in an upgrade?


On my RedHat 7.4, I'm creating an RPM with CMake, and one of the instructions I want to give the RPM is - to leave a certain config file alone, in case the action is an upgrade.

I thought I could accomplish this in my CMakeLists.txt with (mcve):

cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR)                                                                                                                                                                  
project(MyKibana)

set(kibana_version 6.2.2)
set(kibana_dir /usr/share/mykibana)

list(APPEND CPACK_RPM_USER_FILELIST                                                                                                                                                
  "%config(noreplace) ${kibana_dir}/config/kibana.yml"
  )

However, when I do sudo yum upgrade /tmp/my-kibana-6.2.2-577-g7cca696.el7.my.x86_64.rpm -y, I see that the file at /usr/share/mykibana/config/kibana.yml is overwritten with the file in the RPM.

Is there something else I need to do besides the %config(noreplace) directive?


Solution

  • The behavior of rpm with config files is rather complicated to understand.

    %config(noreplace) will not replace your config file if you changed it. If you did not touch the config file, it will always be overwritten with the new config file.

    For a more thorough understanding; see this excellent page: http://people.ds.cam.ac.uk/jw35/docs/rpm_config.html