From 916d40d5bf5540abd8269b3014a44aae4b0d9d14 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Wed, 13 Mar 2024 10:50:05 -0700 Subject: [PATCH] Remove hard coded ROCm path in rdc.service The executable rdcd was using an absolute path in rdc.service. Using update-alternatives gives the flexibility to invoke the binary from anywhere and no absolute path is required. Change-Id: I2f3d6fcbf9dd854870cfc2e00532c504ce6cd6fc [ROCm/rdc commit: 0ca6d6fa59746d4aa17b64a171b89489dd2985c2] --- projects/rdc/cmake_modules/utils.cmake | 1 + projects/rdc/server/rdc.service.in | 5 ++- projects/rdc/src/DEBIAN_postinst.in | 54 +++++++++++++++++++++++++- projects/rdc/src/DEBIAN_prerm.in | 14 +++++++ projects/rdc/src/RPM_postun.in | 13 +++++++ projects/rdc/src/RPM_rpm_post.in | 52 +++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 4 deletions(-) diff --git a/projects/rdc/cmake_modules/utils.cmake b/projects/rdc/cmake_modules/utils.cmake index 9cc1da33f3..0080296c0f 100755 --- a/projects/rdc/cmake_modules/utils.cmake +++ b/projects/rdc/cmake_modules/utils.cmake @@ -99,6 +99,7 @@ function(get_version_from_tag DEFAULT_VERSION_STRING VERSION_PREFIX GIT) set( VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE ) set( VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE ) set( VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE ) + set( VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE ) endfunction() function(num_change_since_prev_pkg VERSION_PREFIX) diff --git a/projects/rdc/server/rdc.service.in b/projects/rdc/server/rdc.service.in index 5ae7666903..b63d44b76a 100755 --- a/projects/rdc/server/rdc.service.in +++ b/projects/rdc/server/rdc.service.in @@ -23,8 +23,9 @@ AmbientCapabilities=CAP_DAC_OVERRIDE # If we need to start anything before rdcd, use this # ExecStartPre= - -ExecStart=/@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/rdcd +# update-alternative has been run for rdcd and +# soft link will be available in usr/bin +ExecStart=rdcd # If we need to start anything after rdcd use this # ExecStartPost= diff --git a/projects/rdc/src/DEBIAN_postinst.in b/projects/rdc/src/DEBIAN_postinst.in index 37d6e90057..71a6bc84a1 100755 --- a/projects/rdc/src/DEBIAN_postinst.in +++ b/projects/rdc/src/DEBIAN_postinst.in @@ -1,5 +1,56 @@ #!/bin/bash +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + local binaries altscore now + now=$(date -u +%s) # Number of seconds since 1 Jan 1970 + + # The reason for this approach rather than using the build number + # is to allow for jobs from different builds. In one build job the + # job number might be at 1200, whilst in a release job the number + # may be only 1. This approach assums that if you install a build + # with a different semantic version then the highest is the + # desired one, but if you install two with the same semver then + # the newest is the desired version. + + # Build up a score. It needs to fit in 32 bits + altscore=$((@VERSION_MAJOR@ - 3)) + altscore=$((altscore * 14 + @VERSION_MINOR@)) # Allow up to 14 minor + altscore=$((altscore * 14 + @VERSION_PATCH@)) # Allow up to 14 patch + + # So far if the version is less than 9 we have a number (altscore) + # that is less than 1175. 2**31/1175 is about 1.8 million. So + # multiply altscore by 1,000,000 and add in a factor of how many + # minutes have passed from an arbitary point in time (1,600,000,000 + # seconds after 1 Jan 1970 or Sep 13 12:26:40 2020) on the + # basis that no one is going to be installing a new version more + # often than every minute. This does get things wrong if a million + # minutes pass and you are downgrading, but the chances of someone + # waiting almost 2 years between installing a version and the + # previous patch level is small. + + altscore=$((altscore*1000000+(now-1600000000)/60)) + + binaries=( + rdcd + ) + + for i in $binaries + do + # No obvious recover strategy if things fail + # No manual or other slave pages to install + if [ -e @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/"$i" ] + then + update-alternatives --install /usr/bin/"$i" "$i" \ + @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/"$i" "$altscore" + else + echo "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/$i not found, but that is OK" >&2 + fi + done + true +} + # This will return 0 if an id is created and non-zero if # it already exists # https://www.debian.org/doc/debian-policy/ch-opersys.html#users-and-groups @@ -34,9 +85,9 @@ reload_systemd() { return 0 } - case "$1" in configure) + do_update_alternatives do_create_rdc_user create_rdc_service reload_systemd @@ -49,4 +100,3 @@ case "$1" in exit 0 ;; esac - diff --git a/projects/rdc/src/DEBIAN_prerm.in b/projects/rdc/src/DEBIAN_prerm.in index a047f2c35a..3281910430 100644 --- a/projects/rdc/src/DEBIAN_prerm.in +++ b/projects/rdc/src/DEBIAN_prerm.in @@ -1,5 +1,18 @@ #!/bin/bash +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + binaries=( + rdcd + ) + + for i in "$binaries" + do + update-alternatives --remove $i @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/$i + done +} + stop_rdc() { #stop RDC service if systemd exists and service is running if [ -d /run/systemd/system ] && $( systemctl is-active --quiet rdc ); then @@ -34,6 +47,7 @@ case "$1" in rm_rdc_service reload_systemd rm_pyc + do_update_alternatives ;; purge) ;; diff --git a/projects/rdc/src/RPM_postun.in b/projects/rdc/src/RPM_postun.in index c0b7f3c676..ef855397aa 100755 --- a/projects/rdc/src/RPM_postun.in +++ b/projects/rdc/src/RPM_postun.in @@ -1,4 +1,16 @@ #!/bin/bash +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + binaries=( + rdcd + ) + + for i in "$binaries" + do + update-alternatives --remove $i @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/$i + done +} stop_rdc() { #stop RDC service if systemd exists and service is running @@ -28,4 +40,5 @@ if [ $1 -le 1 ]; then stop_rdc rm_rdc_service reload_systemd + do_update_alternatives fi diff --git a/projects/rdc/src/RPM_rpm_post.in b/projects/rdc/src/RPM_rpm_post.in index d3c71e803b..658c1298a0 100755 --- a/projects/rdc/src/RPM_rpm_post.in +++ b/projects/rdc/src/RPM_rpm_post.in @@ -1,5 +1,55 @@ #!/bin/bash +do_update_alternatives(){ + # skip update if program doesn't exist + command -v update-alternatives >/dev/null || return 0 + local binaries altscore now + now=$(date -u +%s) # Number of seconds since 1 Jan 1970 + + # The reason for this approach rather than using the build number + # is to allow for jobs from different builds. In one build job the + # job number might be at 1200, whilst in a release job the number + # may be only 1. This approach assums that if you install a build + # with a different semantic version then the highest is the + # desired one, but if you install two with the same semver then + # the newest is the desired version. + + # Build up a score. It needs to fit in 32 bits + altscore=$((@VERSION_MAJOR@ - 3)) + altscore=$((altscore * 14 + @VERSION_MINOR@)) # Allow up to 14 minor + altscore=$((altscore * 14 + @VERSION_PATCH@)) # Allow up to 14 patch + + # So far if the version is less than 9 we have a number (altscore) + # that is less than 1175. 2**31/1175 is about 1.8 million. So + # multiply altscore by 1,000,000 and add in a factor of how many + # minutes have passed from an arbitary point in time (1,600,000,000 + # seconds after 1 Jan 1970 or Sep 13 12:26:40 2020) on the + # basis that no one is going to be installing a new version more + # often than every minute. This does get things wrong if a million + # minutes pass and you are downgrading, but the chances of someone + # waiting almost 2 years between installing a version and the + # previous patch level is small. + + altscore=$((altscore*1000000+(now-1600000000)/60)) + binaries=( + rdcd + ) + + for i in $binaries + do + # No obvious recover strategy if things fail + # No manual or other slave pages to install + if [ -e @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/"$i" ] + then + update-alternatives --install /usr/bin/"$i" "$i" \ + @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/"$i" "$altscore" + else + echo "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/$i not found, but that is OK" >&2 + fi + done + true +} + # https://fedoraproject.org/wiki/Packaging%3aUsersAndGroups do_create_rdc_user() { useradd -r -s /sbin/nologin rdc @@ -26,6 +76,8 @@ reload_systemd() { return 0 } +do_update_alternatives + do_create_rdc_user #Symlink RDC Service