관리-도구
편집 파일: service.cpython-39.opt-1.pyc
a �)g�# � @ s� d dl mZmZmZ eZd dlZd dlZd dlZd dl Z d dl Z d dlZd dlZd dl Z d dlmZmZ d dlmZmZ ddd�Zdd� Zd d � Zdd� Zddd�Zdd� Zdd� Zdd� ZdS )� )�absolute_import�division�print_functionN)�PY2�b)�to_bytes�to_textc C sp |r<t j�d�s&tt�d|| f ��S tt�d|| f ��S t j�d�sZtt�d| ��S tt�d| ��S dS )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 r c C s | � 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 �resultr r r �get_sysv_script? s r c C s t j�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 )r r r r �sysv_existsN s r c C sd d}t �� dkrd}nd}| �dd�}| �||g�\}}}|dkr`|�� D ]}||v rJd} 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�liner r r �get_psX s r( � c C s |s| j d||f d� 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+ r r r �fail_if_missingm s r- c C s� t �� } | dkr�t �t jt j�}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�fdZnumZsidr r r �fork_process{ s&