%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/module_utils/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/module_utils/__pycache__/service.cpython-39.pyc

a

�)g�#�@s�ddlmZmZmZeZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZmZddlmZmZddd�Zdd�Zd	d
�Zdd�Zddd�Zdd�Zdd�Zdd�ZdS)�)�absolute_import�division�print_functionN)�PY2�b)�to_bytes�to_textcCsp|r<tj�d�s&tt�d||f��Stt�d||f��Stj�d�sZtt�d|��Stt�d|��SdS)z�
    This function will check if the service name supplied
    is enabled in any of the sysv runlevels

    :arg name: name of the service to test for
    :kw runlevel: runlevel to check (default: None)
    z/etc/rc0.d/z/etc/init.d/rc%s.d/S??%sz/etc/rc%s.d/S??%sz/etc/init.d/rc?.d/S??%sz/etc/rc?.d/S??%sN)�os�path�isdir�bool�glob)�nameZrunlevel�r�@/usr/lib/python3.9/site-packages/ansible/module_utils/service.py�sysv_is_enabled-srcCs|�d�r|}nd|}|S)z�
    This function will return the expected path for an init script
    corresponding to the service name supplied.

    :arg name: name or path of the service to test for
    �/z/etc/init.d/%s)�
startswith)r�resultrrr�get_sysv_script?s
rcCstj�t|��S)z�
    This function will return True or False depending on
    the existence of an init script corresponding to the service name supplied.

    :arg name: name of the service to test for
    )r	r
�existsr)rrrr�sysv_existsNsrc	Csdd}t��dkrd}nd}|�dd�}|�||g�\}}}|dkr`|��D]}||vrJd}q`qJ|S)zX
    Last resort to find a service by trying to match pattern to programs in memory
    F�SunOS�-ef�auxww�psTr)�platform�system�get_bin_path�run_command�
splitlines)	�module�pattern�found�flags�psbin�rcZpsoutZpserr�linerrr�get_psXsr(�cCs|s|jd||fd�dS)a{
    This function will return an error or exit gracefully depending on check mode status
    and if the service is missing or not.

    :arg module: is an  AnsibleModule object, used for it's utility methods
    :arg found: boolean indicating if services was found or not
    :arg service: name of service
    :kw msg: extra info to append to error/success msg when missing
    z+Could not find the requested service %s: %s��msgN)�	fail_json)r!r#Zservicer+rrr�fail_if_missingms
r-cCs�t��}|dkr�t�tjtj�}td�D]}||kr(t�||�q(|td�vrXt�|�t��}|dkrrt�d�t�	�}|dkr�t
d��t�d�t��}|dkr�t�d�|S)zk
    This function performs the double fork process to detach from the
    parent process and execute.
    r����z*Unable to detach session while daemonizingr)r	�fork�open�devnull�O_RDWR�range�dup2�close�_exit�setsid�	Exception�chdir)�pid�fdZnumZsidrrr�fork_process{s&



r=c
s�d}d}zt���t�}Wn\ty>|jdt��d�Yn:tyv}z"|jt|�t��d�WYd}~n
d}~00|dk�rt�	�d�t
|t�s�tr�t
�t||d��}nt
�t||d��}g}|D]}|�t||d��q�tj|dtjtj�fd	d
�d�}|j|jg}	|jtd�|jtd�i}
|	�r�t�|	g|	d
�\}}}
|||
�s\|���r(t|	�D]D}||v�r�t�|��|�}|�s�|	�|�|
|t|�7<�qd�q(|��tj|jt|
|j�t|
|j�gtj d�}t�!�d
t||d��t�	�d
�t�"d�n�|dk�r,|jdd�n�t�	�d
�t�#|d�td�}t��dgg�dg�\}}}
�d|v�rNt��d|�}|�s��q�|t|�7}�qNt�$t||d��SdS)a�
    Execute a command while detaching as a daemon, returns rc, stdout, and stderr.

    :arg module: is an  AnsibleModule object, used for it's utility methods
    :arg cmd: is a list or string representing the command and options to run

    This is complex because daemonization is hard for people.
    What we do is daemonize a part of this module, the daemon runs the command,
    picks up the return code and output, and returns it to the main process.
    iZsurrogate_or_strictz"Error while attempting to fork: %s)r+�	exceptionNr)�errorsFcst��d�S)N�)r	r6r��piperr�<lambda>��zdaemonize.<locals>.<lambda>)�shell�stdout�stderrZ
preexec_fnr)r@)Zprotocolr/zSUnable to fork, no exception thrown, probably due to lack of resources, check logs.r*)%r	rBr=�OSErrorr,�	traceback�
format_excr9rr6�
isinstance�listr�shlex�splitr�append�
subprocess�Popen�PIPErFrGr�selectZpoll�read�fileno�remove�wait�pickle�dumps�
returncodeZHIGHEST_PROTOCOL�writer7�waitpid�loads)r!�cmd�chunkr?r;�excZrun_cmd�c�pZfds�outputZrfdZwfdZefd�out�dataZreturn_datarrAr�	daemonize�s^

,

 

,
 rfcCsdt��dkrd}nd}|�dd�}|�d||f�\}}}|dkr`|�d�D]}||vrLdSqLd	S)
NrrrrTz%s %sr�
F)rrrrrN)r!r"Zpsflagsr%r&rd�errr'rrr�check_pssri)N)r))Z
__future__rrr�typeZ
__metaclass__r
r	rXrrSrMrPrIZansible.module_utils.sixrrZansible.module_utils._textrrrrrr(r-r=rfrirrrr�<module>s&


*\

Zerion Mini Shell 1.0