Instead of saving SPARK_NONDAEMON_JAVA_OPTS, I think it would be better to modify the scripts to use a different variable name for the JAVA_OPTS they do eventually use. For example:

    OUR_JAVA_OPTS="$SPARK_JAVA_OPTS"
    if [ "$1" = "spark.deploy.master.Master ]; then
        OUR_JAVA_OPTS="$SPARK_DAEMON_JAVA_OPTS"
    fi

This will make the scripts clearer to understand.