← Back
Editing: socket.py
# This file is part of cloud-init. See LICENSE file for license information. """A module for common socket helpers.""" import logging import os import socket import sys from contextlib import suppress from typing import Dict from cloudinit import performance from cloudinit.settings import DEFAULT_RUN_DIR LOG = logging.getLogger(__name__) def sd_notify(message: str): """Send a sd_notify message. :param message: sd-notify message (must be valid ascii) """ socket_path = os.environ.get("NOTIFY_SOCKET", "") if not socket_path: # not running under systemd, no-op return elif socket_path[0] == "@": # abstract socket_path.replace("@", "\0", 1) # unix domain elif socket_path[0] != "/": raise OSError("Unsupported socket type") with socket.socket( socket.AF_UNIX, socket.SOCK_DGRAM | socket.SOCK_CLOEXEC ) as sock: LOG.info("Sending sd_notify(%s)", str(message)) sock.connect(socket_path) sock.sendall(message.encode("ascii")) class SocketSync: """A two way synchronization protocol over Unix domain sockets.""" def __init__(self, *names: str): """Initialize a synchronization context. 1) Ensure that the socket directory exists. 2) Bind a socket for each stage. Binding the sockets on initialization allows receipt of stage "start" notifications prior to the cloud-init stage being ready to start. :param names: stage names, used as a unique identifiers """ self.stage = "" self.first_exception = "" self.systemd_exit_code = 0 self.experienced_any_error = False self.sockets = { name: socket.socket( socket.AF_UNIX, socket.SOCK_STREAM | socket.SOCK_CLOEXEC ) for name in names } self.connections: Dict[str, socket.socket] = {} # ensure the directory exists os.makedirs(f"{DEFAULT_RUN_DIR}/share", mode=0o700, exist_ok=True) # removing stale sockets and bind for name, sock in self.sockets.items(): socket_path = f"{DEFAULT_RUN_DIR}/share/{name}.sock" with suppress(FileNotFoundError): os.remove(socket_path) sock.bind(socket_path) sock.listen() def __call__(self, stage: str): """Set the stage before entering context. This enables the context manager to be initialized separately from each stage synchronization. :param stage: the name of a stage to synchronize Example: sync = SocketSync("stage 1", "stage 2"): with sync("stage 1"): pass with sync("stage 2"): pass """ if stage not in self.sockets: raise ValueError(f"Invalid stage name: {stage}") self.stage = stage return self def __enter__(self): """Wait until a message has been received on this stage's socket. Once the message has been received, enter the context. """ if os.isatty(sys.stdin.fileno()): LOG.info( "Stdin is a tty, so skipping stage synchronization protocol" ) return self.systemd_exit_code = 0 sd_notify( "STATUS=Waiting on external services to " f"complete before starting the {self.stage} stage." ) # block until init system sends us data # the first value returned contains a message from the init system # (should be "start") # the second value contains the path to a unix socket on which to # reply, which is expected to be /path/to/{self.stage}-return.sock sock = self.sockets[self.stage] with performance.Timed(f"Waiting to start stage {self.stage}"): connection, _ = sock.accept() chunk, _ = connection.recvfrom(5) self.connections[self.stage] = connection if b"start" != chunk: # The protocol expects to receive a command "start" self.__exit__(None, None, None) raise ValueError(f"Received invalid message: [{str(chunk)}]") sd_notify(f"STATUS=Running ({self.stage} stage)") return self def __exit__(self, exc_type, exc_val, exc_tb): """Notify the socket that this stage is complete.""" if os.isatty(sys.stdin.fileno()): # See corresponding log for __enter__() return message = f"Completed socket interaction for boot stage {self.stage}" if exc_type: # handle exception thrown in context self.systemd_exit_code = 1 self.experienced_any_error = True status = f"{repr(exc_val)} in {exc_tb.tb_frame}" message = ( 'fatal error, run "systemctl status cloud-init-main.service" ' 'and "cloud-init status --long" for more details' ) if not self.first_exception: self.first_exception = status LOG.fatal(status) sd_notify(f"STATUS={status}") self.experienced_any_error = self.experienced_any_error or bool( self.systemd_exit_code ) sock = self.connections[self.stage] # the returned message will be executed in a subshell # hardcode this message rather than sending a more informative message # to avoid having to sanitize inputs (to prevent escaping the shell) sock.sendall( f"echo '{message}'; exit {self.systemd_exit_code};".encode() ) sock.close() # suppress exception - the exception was logged and the init system # notified of stage completion (and the exception received as a status # message). Raising an exception would block the rest of boot, so carry # on in a degraded state. return True
Mainco
https://validator.w3.org/feed/docs/rss2.html
WHALESPRAY CRACK-3 TINTA LIMPIADORA 400ML VERDE WS-3050-S
WHALESPRAY CRACK-2 TINTA REVELADORA 400ML BLANCO WS-1821-S
WHALESPRAY CRACK-1 TINTA PENETRANTE 400ML ROJO WS-1820-S
VIDRIO PARA MIRILLA TUBULAR TEMPLADO 4″
VIDRIO PARA MIRILLA TUBULAR TEMPLADO 21/2″
VIDRIO PARA MIRILLA TEMPLADO DN100 TIPO FLANGE ALTA PRESION
VIDRIO PARA MIRILLA TEMPLADO DN100
VASTAGO MOVIL P/BASE CUADRADA DE 11/2″
VARILLA PARA BOQUILLA SERIE DH/DS SS304 CON BOQUILLA DE PULVERIZADOR AJUSTABLE DE 3PIES
VARILLA LISA REDONDA SS304 3/8″
VARILLA LISA REDONDA SS304 3/4″
VARILLA LISA REDONDA SS304 3/16″
VARILLA LISA REDONDA SS304 1/8″
VARILLA LISA REDONDA SS304 1/4″
VARILLA LISA REDONDA SS304 1/2″
VALVULA SACAMUESTRAS CLAMP 1″-11/2″ SS316L JUNTA SILICON 10 BAR (120°C)
VALVULA SACAMUESTRAS ASEPTICA FARMA SOLDABLE 1″ DQW-01
VALVULA SACAMUESTRAS ASEPTICA FARMA CLAMP 2″ DQW-03 SS316L
VALVULA SACAMUESTRAS 3/4″ IQY-02 SS316L
VALVULA SACAMUESTRAS 1/4″ IQY-02 SS316L
VALVULA SACAMUESTRAS 1/2″ IQY-02 SS316L
VALVULA RETENCION WAFER 8″ H/FUNDIDO DISCO-DOBLE CF8M ASIENTO BUNA 16 BAR (-10°C-100°C)
VALVULA RETENCION WAFER 8″ CF8M DISCO-DOBLE CF8M ASIENTO VITON 25 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 8″ CF8M DISCO CF8M ASIENTO VITON 16 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 6″ H/FUNDIDO DISCO-DOBLE CF8M ASIENTO BUNA 16 BAR (-10°C-100°C)
VALVULA RETENCION WAFER 6″ CF8M DISCO-DOBLE CF8M ASIENTO VITON 25 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 6″ CF8M DISCO CF8M ASIENTO VITON 16 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 4″ H/FUNDIDO DISCO-DOBLE CF8M ASIENTO BUNA 16 BAR (-10°C-100°C)
VALVULA RETENCION WAFER 4″ CF8M DISCO-DOBLE CF8M ASIENTO VITON 25 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 4″ CF8M DISCO CF8M ASIENTO VITON 16 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 4″ CF8M DISCO CF8M 40 BAR (-20°C-240°C)
VALVULA RETENCION WAFER 3″ H/FUNDIDO DISCO-DOBLE CF8M ASIENTO BUNA 16 BAR (-10°C-100°C)
VALVULA RETENCION WAFER 3″ CF8M DISCO-DOBLE CF8M ASIENTO VITON 25 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 3″ CF8M DISCO CF8M ASIENTO VITON 16 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 3″ CF8M DISCO CF8M 40 BAR (-20°C-240°C)
VALVULA RETENCION WAFER 2″ CF8M DISCO CF8M ASIENTO VITON 16 BAR (-20°C-180°C)
VALVULA RETENCION WAFER 2″ CF8M DISCO CF8M 40 BAR (-20°C-240°C)
VALVULA RETENCION WAFER 1″ CF8M DISCO CF8M 40 BAR (-20°C-240°C)
VALVULA RETENCION SOLDABLE-SOCKET 2″ A/FORJADO PISTON F6A JUNTA SS304 140 BAR (-29°C-420°C)
VALVULA RETENCION SOLDABLE-SOCKET 11/2″ A/FORJADO PISTON F6A JUNTA SS304 140 BAR (-29°C-420°C)
VALVULA RETENCION SOLDABLE-SOCKET 1″ A/FORJADO PISTON F6A JUNTA SS304 140 BAR (-29°C-420°C)
VALVULA RETENCION SOLDABLE DN100 SS316L DISCO SS316L JUNTA EPDM 10 BAR (-10°C-120°C)
VALVULA RETENCION SOLDABLE 6″ SS316
VALVULA RETENCION SOLDABLE 4″ SS316
VALVULA RETENCION SOLDABLE 4″ SS304 DISCO SS304 JUNTA SILICON 10 BAR (-10°C-120°C)
VALVULA RETENCION SOLDABLE 3″ SS304 DISCO SS304 JUNTA SILICON 10 BAR (-10°C-120°C)
VALVULA RETENCION SOLDABLE 11/2″ SS316 JUNTA VITON
VALVULA RETENCION SOLDABLE 11/2″ SS316
Inicio
Blog