Skip to content

Commit

Permalink
Merge pull request #650 from Azure/dalbe/cse_shim_1.5.4
Browse files Browse the repository at this point in the history
CustomScriptExtension shim layer for python interpreter
  • Loading branch information
Diastro authored Sep 25, 2018
2 parents b2008e9 + 375e33f commit 32a9103
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
10 changes: 5 additions & 5 deletions CustomScript/HandlerManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
"version": 1.0,
"handlerManifest": {
"disableCommand": "customscript.py -disable",
"enableCommand": "customscript.py -enable",
"installCommand": "customscript.py -install",
"uninstallCommand": "customscript.py -uninstall",
"updateCommand": "customscript.py -update",
"disableCommand": "shim.sh -disable",
"enableCommand": "shim.sh -enable",
"installCommand": "shim.sh -install",
"uninstallCommand": "shim.sh -uninstall",
"updateCommand": "shim.sh -update",
"rebootAfterInstall": false,
"reportHeartbeat": false
}
Expand Down
8 changes: 4 additions & 4 deletions CustomScript/customscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ def download_files(hutil):
def start_daemon(hutil):
cmd = get_command_to_execute(hutil)
if cmd:
args = [os.path.join(os.getcwd(), __file__), "-daemon"]
args = [os.path.join(os.getcwd(), "shim.sh"), "-daemon"]

# This process will start a new background process by calling
# customscript.py -daemon
# to run the script and will exit itself immediatelly.
# shim.sh -daemon
# to run the script and will exit itself immediately.

# Redirect stdout and stderr to /dev/null. Otherwise daemon process
# will throw Broke pipe exeception when parent process exit.
# will throw Broke pipe exception when parent process exit.
devnull = open(os.devnull, 'w')
subprocess.Popen(args, stdout=devnull, stderr=devnull)
hutil.do_exit(0, 'Enable', 'transitioning', '0',
Expand Down
2 changes: 1 addition & 1 deletion CustomScript/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure">
<ProviderNameSpace>Microsoft.OSTCExtensions</ProviderNameSpace>
<Type>CustomScriptForLinux</Type>
<Version>1.5.3</Version>
<Version>1.5.4</Version>
<Label>Microsoft Azure Custom Script Extension for Linux Virtual Machines</Label>
<HostingResources>VmRole</HostingResources>
<MediaLink></MediaLink>
Expand Down
38 changes: 38 additions & 0 deletions CustomScript/shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# The shim scripts provide a single entry point for CSE and will invoke the customscript.py entry point using the
# appropriate python interpreter version.
# Arguments passed to the shim layer are redirected to the invoked script without any validation.

COMMAND="./customscript.py"
PYTHON=""
ARG="$@"

function find_python(){
local python_exec_command=$1

# Check if there is python defined.
if command -v python >/dev/null 2>&1 ; then
eval ${python_exec_command}="python"
else
# Python was not found. Searching for Python3 now.
if command -v python >/dev/null 2>&1 ; then
eval ${python_exec_command}="python3"
fi
fi
}

find_python PYTHON

if [ -z "$PYTHON" ]
then
echo "No Python interpreter found on the box" >&2
exit 51 # Not Supported
else
echo "Found: `${PYTHON} --version`"
fi

${PYTHON} ${COMMAND} ${ARG}
exit $?

# DONE

0 comments on commit 32a9103

Please sign in to comment.