diff --git a/CustomScript/HandlerManifest.json b/CustomScript/HandlerManifest.json index 2594429a2..4726a7c59 100644 --- a/CustomScript/HandlerManifest.json +++ b/CustomScript/HandlerManifest.json @@ -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 } diff --git a/CustomScript/customscript.py b/CustomScript/customscript.py index 697731830..7e2904a77 100644 --- a/CustomScript/customscript.py +++ b/CustomScript/customscript.py @@ -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', diff --git a/CustomScript/manifest.xml b/CustomScript/manifest.xml index 1a306c80e..a7130a867 100644 --- a/CustomScript/manifest.xml +++ b/CustomScript/manifest.xml @@ -2,7 +2,7 @@ Microsoft.OSTCExtensions CustomScriptForLinux - 1.5.3 + 1.5.4 VmRole diff --git a/CustomScript/shim.sh b/CustomScript/shim.sh new file mode 100644 index 000000000..0f6affa82 --- /dev/null +++ b/CustomScript/shim.sh @@ -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 \ No newline at end of file