File: //proc/self/root/usr/lib/python3.9/site-packages/ansible/modules/__pycache__/service.cpython-39.pyc
a
�)gd� � @ sx d dl mZmZmZ eZdZdZdZd dl Z d dl
Z
d dlZd dlZd dl
Z
d dlZd dlZd dlZd dlZd dlZe�� dkr�d dlmZ d dlmZmZ d d lmZ d d
lmZ d dlmZ d dlm Z d d
l!m"Z"m#Z# G dd� de$�Z%G dd� de%�Z&G dd� de%�Z'G dd� de'�Z(G dd� de%�Z)G dd� de%�Z*G dd� de%�Z+G dd� de%�Z,dd� Z-e.d k�rte-� dS )!� )�absolute_import�division�print_functionaI
---
module: service
version_added: "0.1"
short_description: Manage services
description:
- Controls services on remote hosts. Supported init systems include BSD init,
OpenRC, SysV, Solaris SMF, systemd, upstart.
- This module acts as a proxy to the underlying service manager module. While all arguments will be passed to the
underlying module, not all modules support the same arguments. This documentation only covers the minimum intersection
of module arguments that all service manager modules support.
- This module is a proxy for multiple more specific service manager modules
(such as M(ansible.builtin.systemd) and M(ansible.builtin.sysvinit)).
This allows management of a heterogeneous environment of machines without creating a specific task for
each service manager. The module to be executed is determined by the I(use) option, which defaults to the
service manager discovered by M(ansible.builtin.setup). If C(setup) was not yet run, this module may run it.
- For Windows targets, use the M(ansible.windows.win_service) module instead.
options:
name:
description:
- Name of the service.
type: str
required: true
state:
description:
- C(started)/C(stopped) are idempotent actions that will not run
commands unless necessary.
- C(restarted) will always bounce the service.
- C(reloaded) will always reload.
- B(At least one of state and enabled are required.)
- Note that reloaded will start the service if it is not already started,
even if your chosen init system wouldn't normally.
type: str
choices: [ reloaded, restarted, started, stopped ]
sleep:
description:
- If the service is being C(restarted) then sleep this many seconds
between the stop and start command.
- This helps to work around badly-behaving init scripts that exit immediately
after signaling a process to stop.
- Not all service managers support sleep, i.e when using systemd this setting will be ignored.
type: int
version_added: "1.3"
pattern:
description:
- If the service does not respond to the status command, name a
substring to look for as would be found in the output of the I(ps)
command as a stand-in for a status result.
- If the string is found, the service will be assumed to be started.
- While using remote hosts with systemd this setting will be ignored.
type: str
version_added: "0.7"
enabled:
description:
- Whether the service should start on boot.
- B(At least one of state and enabled are required.)
type: bool
runlevel:
description:
- For OpenRC init scripts (e.g. Gentoo) only.
- The runlevel that this service belongs to.
- While using remote hosts with systemd this setting will be ignored.
type: str
default: default
arguments:
description:
- Additional arguments provided on the command line.
- While using remote hosts with systemd this setting will be ignored.
type: str
aliases: [ args ]
use:
description:
- The service module actually uses system specific modules, normally through auto detection, this setting can force a specific module.
- Normally it uses the value of the 'ansible_service_mgr' fact and falls back to the old 'service' module when none matching is found.
type: str
default: auto
version_added: 2.2
extends_documentation_fragment:
- action_common_attributes
- action_common_attributes.flow
attributes:
action:
support: full
async:
support: full
bypass_host_loop:
support: none
check_mode:
details: support depends on the underlying plugin invoked
support: N/A
diff_mode:
details: support depends on the underlying plugin invoked
support: N/A
platform:
details: The support depends on the availability for the specific plugin for each platform and if fact gathering is able to detect it
platforms: all
notes:
- For AIX, group subsystem names can be used.
seealso:
- module: ansible.windows.win_service
author:
- Ansible Core Team
- Michael DeHaan
a9
- name: Start service httpd, if not started
ansible.builtin.service:
name: httpd
state: started
- name: Stop service httpd, if started
ansible.builtin.service:
name: httpd
state: stopped
- name: Restart service httpd, in all cases
ansible.builtin.service:
name: httpd
state: restarted
- name: Reload service httpd, in all cases
ansible.builtin.service:
name: httpd
state: reloaded
- name: Enable service httpd, and not touch the state
ansible.builtin.service:
name: httpd
enabled: yes
- name: Start service foo, based on running process /usr/bin/foo
ansible.builtin.service:
name: foo
pattern: /usr/bin/foo
state: started
- name: Restart network service for interface eth0
ansible.builtin.service:
name: network
state: restarted
args: eth0
�#N�SunOS)�LooseVersion)�to_bytes�to_text)�
AnsibleModule)�get_best_parsable_locale)�get_platform_subclass)�fail_if_missing)�PY2�bc sz e Zd ZdZdZdZ� fdd�Zdd� Zdd � Zd
d� Z dd
� Z
dd� Zddd�Zdd� Z
dd� Zdd� Zdd� Z� ZS )�ServiceaT
This is the generic Service manipulation class that is subclassed
based on platform.
A subclass should override the following action methods:-
- get_service_tools
- service_enable
- get_service_status
- service_control
All subclasses MUST define platform and distribution (which may be None).
�GenericNc s t t�}t| |��|�S )N)r r �super�__new__)�cls�args�kwargsZnew_cls�� __class__� �;/usr/lib/python3.9/site-packages/ansible/modules/service.pyr � s zService.__new__c C s� || _ |jd | _|jd | _|jd | _|jd | _|jd | _|jd | _d| _d | _ d | _
d | _d | _d | _
d | _d | _|j�dd �| _d | _d | _d | _d| _d S )
N�name�state�sleep�pattern�enabled�runlevelF� arguments� )�module�paramsr r r r �enabler �changed�running�crashed�action�svc_cmd�svc_initscript�svc_initctl�
enable_cmd�getr! �rcconf_file�
rcconf_key�rcconf_value�
svc_change)�selfr# r r r �__init__� s( zService.__init__c C s | j jdd� d S )Nz4get_service_tools not implemented on target platform��msg�r# � fail_json�r3 r r r �get_service_tools� s zService.get_service_toolsc C s | j jdd� d S )Nz1service_enable not implemented on target platformr5 r7 r9 r r r �service_enable� s zService.service_enablec C s | j jdd� d S )Nz5get_service_status not implemented on target platformr5 r7 r9 r r r �get_service_status� s zService.get_service_statusc C s | j jdd� d S )Nz2service_control not implemented on target platformr5 r7 r9 r r r �service_control� s zService.service_controlFc s t | j�}t|||d�}|s,| jj||d�S t�� � t�� }|dk�rxt�� d � t�tj tj
�}|dkrxt�|d� |dkr�t�|d� |dkr�t�|d� |dvr�t�|� t�� }|dkr�t�d� t�
� t�d� t�� }|dkr�t�d� t�rt|dd �}t�|�}n t|dd �}d
d� t�|�D �}tj|dtjtj|� fd
d�d�}td�}td�} |j|jg}
|
�r$t�|
g |
d�\}}}
|| |
�s�|�� d u�r��q$|j|v �r�t�|j�� d�}|�s�|
�|j� ||7 }|j|v �rtt�|j�� d�}|�s|
�|j� | |7 } �qt|�� t �!|j"t|�t| �g�}t�#� d t|dd �� t�� d � t�d� n�|dk�r�| jj$dd� n�t�� d � t�%|d� td�}t�� d gg � d g�\}}}
� d |v �r�t�� d d�}|�s��q||7 }�q�t �&t|dd ��S d S )N)�LANG�LC_ALL�LC_MESSAGES)Zenviron_updater � � )r rA rB �/�surrogate_or_strict��errorsc S s g | ]}t |d d��qS )rD rE )r )�.0�cr r r �
<listcomp># � z+Service.execute_command.<locals>.<listcomp>Fc s t �� d �S )NrA )�os�closer ��piper r �<lambda>( rJ z)Service.execute_command.<locals>.<lambda>)�shell�stdout�stderr�envZ
preexec_fnr"