Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
OMSConfig improvments (#828)
Browse files Browse the repository at this point in the history
1. Removing dependency on OMI port
2. Change python detection logic
3. Fixing omsconfig upgrade scenario
  • Loading branch information
chsamala2 authored Dec 6, 2021
1 parent df4c502 commit 7bafd75
Showing 1 changed file with 72 additions and 29 deletions.
101 changes: 72 additions & 29 deletions installbuilder/datafiles/Base_DSC.data
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,18 @@ fi

%Preinstall_200
# pythonVersion check must be repeated for each section
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python2"
pythonVersion="python2"
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
fi
fi
# Only check for ctypes if python2 is installed
if [ "$pythonVersion" = "python2" ]; then
Expand All @@ -237,7 +241,18 @@ fi
echo "Cleanning up existing dsc_hosts..."
kill $(ps -eo pid,cmd | grep '/opt/dsc/bin/dsc_host' | grep -v grep | tr -s ' ' | sed 's/^[ \t]*//' | cut -d' ' -f1) -9 2&>1 > /dev/null
chmod -R 777 /opt/dsc
rm -rfv /opt/dsc
# Clean dsc directory in case of install and clean
echo "Deployment operation type :" $1
if [ "$1" = "1" -o "$1" = 1 -o "$1" = "install" -o "$1" = "clean" ]; then
echo "Cleanning directory /opt/dsc..."
rm -rfv /opt/dsc
else
for file in `ls /opt/dsc`; do
if [ $file != "lib" ]; then
rm -rfv /opt/dsc/"$file"
fi
done
fi
rm -f /etc/opt/omi/conf/omsconfig/inventory_lock
echo "Cleaned up existing dsc_hosts..."

Expand Down Expand Up @@ -316,7 +331,7 @@ ln -fs /opt/microsoft/${{SHORT_NAME}}/bin/OMSConsistencyInvoker $OMI_HOME/bin/OM
#else

# Make OMI listen on the standard DSC port
$OMI_HOME/bin/omiconfigeditor httpsport -a 5986 < $CONFIG_SYSCONFDIR/omiserver.conf > $CONFIG_SYSCONFDIR/omiserver.conf_temp
$OMI_HOME/bin/omiconfigeditor httpsport -a 0 < $CONFIG_SYSCONFDIR/omiserver.conf > $CONFIG_SYSCONFDIR/omiserver.conf_temp
mv $CONFIG_SYSCONFDIR/omiserver.conf_temp $CONFIG_SYSCONFDIR/omiserver.conf

mkdir -p $OMI_REGISTER_DIR/root-Microsoft-DesiredStateConfiguration
Expand Down Expand Up @@ -363,14 +378,18 @@ chmod 1775 /opt/microsoft/omsconfig/Scripts


# pythonVersion check must be repeated for each section
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python2"
pythonVersion="python2"
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
fi
fi

# Set up built-in resource modules for OMS DSC
Expand Down Expand Up @@ -451,14 +470,18 @@ if [ -d "/etc/opt/omi/conf/omsconfig" ]; then chown -R omsagent:omiusers /etc/op
#else

# pythonVersion check must be repeated for each section
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python2"
pythonVersion="python2"
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
fi
fi

# Set up built-in resource module for DIY DSC
Expand Down Expand Up @@ -556,14 +579,18 @@ mv /etc/crontabtmp /etc/crontab
#if BUILD_OMS == 1

# pythonVersion check must be repeated for each section
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python2"
pythonVersion="python2"
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found"
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
fi
fi

# If omsadmin.conf exists, let's apply the metaconfig
Expand All @@ -587,23 +614,39 @@ chgrp omsagent /etc/opt/omi/conf/omsconfig/configuration/Inventory.mof
echo "Cleanning up existing dsc_hosts before uninstall..."
kill $(ps -eo pid,cmd | grep '/opt/dsc/bin/dsc_host' | grep -v grep | tr -s ' ' | sed 's/^[ \t]*//' | cut -d' ' -f1) -9 2&>1 > /dev/null
chmod -R 777 /opt/dsc
rm -rfv /opt/dsc
# remove entire dsc folder incase of remove and purge
echo "Deployment operation type :" $1
if [ "$1" = "0" -o "$1" = 0 -o "$1" = "remove" -o "$1" = "purge" ]; then
echo "Cleanning directory /opt/dsc..."
rm -rfv /opt/dsc
else
for file in `ls /opt/dsc`; do
if [ $file != "lib" ]; then
rm -rfv /opt/dsc/"$file"
fi
done
fi
rm -f /etc/opt/omi/conf/omsconfig/inventory_lock
echo "Cleaned up existing dsc_hosts before uninstall..."

%Preuninstall_999
# pythonVersion check must be repeated for each section
if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then
version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python2"
pythonVersion="python2"
elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found"
version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)')
if [ ! -z "$version" ]; then
echo "Using python3"
pythonVersion="python3"
else
echo "Python not found."
fi
fi
# if this is a package removal, not an upgrade, remove the modules
if [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ]; then
echo "Deployment operation type :" $1
if [ "$1" = "0" -o "$1" = 0 -o "$1" = "remove" -o "$1" = "purge" ]; then
# Remove all DSC specific data
if [ "$pythonVersion" = "python3" ]; then
echo "Running python3"
Expand Down

0 comments on commit 7bafd75

Please sign in to comment.