0x10000000 #ˆl–ß=¿J µ2ÛR‚œP-\l%1hßÁ ƒB/À¿Ã@#!/usr/bin/sh # This file is part of cloud-init. See LICENSE file for license information. DATA_PRE="/var/lib/cloud/sem/bootper" INST_PRE="/var/lib/cloud/instance/sem/bootper" Usage() { cat <&2; } fail() { [ $# -eq 0 ] || error "$@"; exit 1; } # support the old 'cloud-init-run-module freq name "execute" cmd arg1' # if < 3 arguments, it will fail below on usage. if [ "${0##*/}" = "cloud-init-run-module" ]; then if [ $# -le 2 -o "$3" = "execute" ]; then error "Warning: ${0##*/} is deprecated. Please use cloud-init-per." freq=$1; name=$2; [ $# -le 2 ] || shift 3; set -- "$freq" "$name" "$@" else fail "legacy cloud-init-run-module only supported with module 'execute'" fi fi [ "$1" = "-h" -o "$1" = "--help" ] && { Usage ; exit 0; } [ $# -ge 3 ] || { Usage 1>&2; exit 1; } freq=$1 name=$(echo $2 | sed 's/-/_/g') shift 2; [ "${name#*/}" = "${name}" ] || fail "name cannot contain a /" [ "$(id -u)" = "0" ] || fail "must be root" case "$freq" in once|always) sem="${DATA_PRE}.$name.$freq";; instance) sem="${INST_PRE}.$name.$freq";; *) Usage 1>&2; fail "invalid frequency: $freq";; esac [ -d "${sem%/*}" ] || mkdir -p "${sem%/*}" || fail "failed to make directory for ${sem}" # Rename legacy sem files with dashes in their names. Do not overwrite existing # sem files to prevent clobbering those which may have been created from calls # outside of cloud-init. sem_legacy=$(echo $sem | sed 's/_/-/g') [ "$sem" != "$sem_legacy" -a -e "$sem_legacy" ] && mv -n "$sem_legacy" "$sem" [ "$freq" != "always" -a -e "$sem" ] && exit 0 "$@" ret=$? printf "%s\t%s\n" "$ret" "$(date +%s)" > "$sem" || fail "failed to write to $sem" exit $ret #ˆl–Ðz¾”Ji?u4 ^¸ËwÒ˜´o ƒeæÜÁÀÄ# Copyright: (c) 2021, Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import (absolute_import, division, print_function) __metaclass__ = type import os import subprocess import sys from ansible.module_utils.common.text.converters import to_bytes, to_native def has_respawned(): return hasattr(sys.modules['__main__'], '_respawned') def respawn_module(interpreter_path): """ Respawn the currently-running Ansible Python module under the specified Python interpreter. Ansible modules that require libraries that are typically available only under well-known interpreters (eg, ``yum``, ``apt``, ``dnf``) can use bespoke logic to determine the libraries they need are not available, then call `respawn_module` to re-execute the current module under a different interpreter and exit the current process when the new subprocess has completed. The respawned process inherits only stdout/stderr from the current process. Only a single respawn is allowed. ``respawn_module`` will fail on nested respawns. Modules are encouraged to call `has_respawned()` to defensively guide behavior before calling ``respawn_module``, and to ensure that the target interpreter exists, as ``respawn_module`` will not fail gracefully. :arg interpreter_path: path to a Python interpreter to respawn the current module """ if has_respawned(): raise Exception('module has already been respawned') # FUTURE: we need a safe way to log that a respawn has occurred for forensic/debug purposes payload = _create_payload() stdin_read, stdin_write = os.pipe() os.write(stdin_write, to_bytes(payload)) os.close(stdin_write) rc = subprocess.call([interpreter_path, '--'], stdin=stdin_read) sys.exit(rc) # pylint: disable=an