HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //proc/self/root/usr/lib/python3.9/site-packages/ansible/modules/__pycache__/service.cpython-39.pyc
a

�)gd��@sxddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZe��dkr�ddlmZddlmZmZdd	lmZdd
lmZddlmZddlm Z dd
l!m"Z"m#Z#Gdd�de$�Z%Gdd�de%�Z&Gdd�de%�Z'Gdd�de'�Z(Gdd�de%�Z)Gdd�de%�Z*Gdd�de%�Z+Gdd�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�bcszeZdZdZdZdZ�fdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zddd�Zdd�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).
    �GenericNcstt�}t||��|�S)N)rr�super�__new__)�cls�args�kwargsZnew_cls��	__class__��;/usr/lib/python3.9/site-packages/ansible/modules/service.pyr�szService.__new__cCs�||_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_d|_d|_	d|_
d|_d|_d|_
d|_d|_|j�dd	�|_d|_d|_d|_d|_dS)
N�name�state�sleep�pattern�enabled�runlevelF�	arguments�)�module�paramsrrrr�enabler �changed�running�crashed�action�svc_cmd�svc_initscript�svc_initctl�
enable_cmd�getr!�rcconf_file�
rcconf_key�rcconf_value�
svc_change)�selfr#rrr�__init__�s(zService.__init__cCs|jjdd�dS)Nz4get_service_tools not implemented on target platform��msg�r#�	fail_json�r3rrr�get_service_tools�szService.get_service_toolscCs|jjdd�dS)Nz1service_enable not implemented on target platformr5r7r9rrr�service_enable�szService.service_enablecCs|jjdd�dS)Nz5get_service_status not implemented on target platformr5r7r9rrr�get_service_status�szService.get_service_statuscCs|jjdd�dS)Nz2service_control not implemented on target platformr5r7r9rrr�service_control�szService.service_controlFc	st|j�}t|||d�}|s,|jj||d�St���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|dtjtj|�fd
d�d�}td�}td�}	|j|jg}
|
�r$t�|
g|
d�\}}}
|||
�s�|��du�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�#�dt|dd	��t��d�t�d�n�|dk�r�|jj$dd�n�t��d�t�%|d�td�}t��dgg�dg�\}}}
�d|v�r�t��dd�}|�s��q||7}�q�t �&t|dd	��SdS)N)�LANG�LC_ALL�LC_MESSAGES)Zenviron_updater��)rrArB�/�surrogate_or_strict��errorscSsg|]}t|dd��qS)rDrE)r)�.0�crrr�
<listcomp>#�z+Service.execute_command.<locals>.<listcomp>Fcst��d�S)NrA)�os�closer��piperr�<lambda>(rJz)Service.execute_command.<locals>.<lambda>)�shell�stdout�stderr�envZ
preexec_fnr"i���zunable to forkr5)'rr#�dict�run_commandrKrN�forkrL�open�devnull�O_RDWR�dup2�_exit�setsid�chdirrr�shlex�splitr	�
subprocess�Popen�PIPErrQrR�selectZpoll�read�fileno�remove�wait�json�dumps�
returncode�writer8�waitpid�loads)r3�cmd�	daemonize�localeZlang_env�pid�fd�prQrRZfdsZrfdZwfdZefdZdatZblob�datarrMr�execute_command�s�





"
 zService.execute_commandcCs~t��dkrd}nd}|j�dd�}|�d||f�\}}}|dkrzd|_|�d	�}|D] }|j|vrXd
|vrXd|_qzqXdS)Nrz-efZauxwwZpsT�%s %srF�
zpattern=)�platform�systemr#�get_bin_pathrvr'r`r)r3ZpsflagsZpsbin�rcZpsoutZpserr�lines�linerrr�check_psQs
zService.check_pscCs�|jr|jdur|jjdd�|js6|jdvr6d|_n(|jrN|jdvrNd|_n|jdkr^d|_|jjr||jr||jjddd�dS)	Nz@failed determining service state, possible typo of service name?r5)�reloaded�startedT)r��stopped�	restartedzservice state changed�r&r6)rr'r#r8r2�
check_mode�	exit_jsonr9rrr�check_service_changedfs
zService.check_service_changedcCs�|jr�|jdvrd|_nL|js0|jdkr0d|_n4|jdkrBd|_n"|jdkrTd|_n|jdkrdd|_|jjr||jjd	d
d�|��Sd}d
}d
}|||fSdS)N)r��startr�r��stop�reloadr��restartTzchanging service stater�rr")r2rr)r'r#r�r�r=)r3r|�err�outrrr�modify_service_statess$



zService.modify_service_statecCs�|jdus|jdus|jdur,|jjdd�d|_d|j|jf}t|jd���}g}|D]~}tj|dd�}t	|�dkr�d|d	vr�|d	�dd�\}}||jkr�|�
�|jkr�d
|_q�n
|}d|_|�|��d�qXWd�n1s�0Y|jdu�r|�|�d|_|jdu�r�|jj
�r8|jjddd
�tj�|j�}tj�|j�}	tj|d|	d�\}
}|D]}t�|
|����qnt�|
�|j�||j�dS)NzIservice_enable_rcconf() requires rcconf_file, rcconf_key and rcconf_valuer5z%s="%s"
�rT�ZcommentsrA�=rFrx�changing service enablementr�z%s-)�dir�prefix)r/r0r1r#r8r&rXr_r`�len�upper�append�stripr�r�rK�path�dirname�basename�tempfileZmkstemprl�encoderLZatomic_move)r3�entryZRCFILEZnew_rc_confZrclineZrcarray�key�valueZ
rcconf_dirZrcconf_baseZ
TMP_RCCONFZtmp_rcconf_filerrr�service_enable_rcconf�s<
2


zService.service_enable_rcconf)F)�__name__�
__module__�__qualname__�__doc__ry�distributionrr4r:r;r<r=rvrr�r�r��
__classcell__rrrrr�s

^
rc@sPeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�LinuxServicez�
    This is the Linux Service manipulation class - it is currently supporting
    a mixture of binaries and init scripts for controlling services started at
    boot, as well as for controlling the current state.
    ZLinuxNc
s>gd�}gd�}dg}t��|D]}|jj||d��|<q |D]$}d||jf}tj�|�r>||_q>�fdd�}|�r�|j|_�d|_	�d|_
�n&��d	d
��rBtj�d|j��rB�d	|_
t
d�|_zTt�d
�}|j�d�d	�\}	}
}|	dk�r|�|
�}|�rt
|��d�|_Wnt�y4Yn0�d	|_	nz��dd
��rh�d|_	�d|_
dS|j�r���dd
��r��d|_
n2��dd��r��d|_
n��dd
��r��d|_
|j
du�r�t|jd
|jdd�|j	du�r��dd
��r�d|_	|j	du�r"|j�s"|jjdd���d	d
��r:�d	|_dS)N)z/sbinz	/usr/sbinz/binz/usr/bin)�service�	chkconfig�update-rc.d�
rc-service�	rc-update�initctl�	systemctlr�r�r��insservz/etc/init.d)Zopt_dirs�%s/%scsh��dd�rddD]}tj�|�rdSqztdd�}WntyJYdS0|D]}d|vrPdSqPdS)Nr�F)z/run/systemd/system/z/dev/.run/systemd/z/dev/.systemd/Tz/proc/1/commr�Zsystemd)r.rKr��existsrX�IOError)Zcanary�fr~��locationrr�
check_systemd�sz5LinuxService.get_service_tools.<locals>.check_systemdr�r�Fz/etc/init/%s.confz0.0.0z\(upstart (.*)\)z
%s versionrr�r�r�r�r��hostr5r�zbcannot find 'service' binary or init script for service,  possible typo in service name?, aborting)rUr#r{rrKr��isfiler+�_LinuxService__systemd_unitr*r-r.r�r�upstart_version�re�compilerV�search�groups�	Exceptionr
r8r,)
r3�pathsZbinaries�	initpathsZbinary�initdir�
initscriptr�Z
version_rer|rQrR�resrr�rr:�s^
"








zLinuxService.get_service_toolscCsbdd�}dd�}|j}|�d|j|f�\}}}|dkr<dS|�d�rJd	S||�rZ||�Sd	SdS)
NcSsd|}t�|tj�S)Nz/etc/init.d/)rK�access�X_OK)rZscriptrrr�sysv_exists0sz=LinuxService.get_systemd_service_enabled.<locals>.sysv_existscSstt�d|��S)N�/etc/rc?.d/S??)�bool�glob)rrrr�sysv_is_enabled4szALinuxService.get_systemd_service_enabled.<locals>.sysv_is_enabledz%s is-enabled %srTZdisabledF)r�rvr-�
startswith)r3r�r��service_namer|r�r�rrr�get_systemd_service_enabled/s
z(LinuxService.get_systemd_service_enabledc	Cs|�d|j|jf�\}}}|dkr@|jjd||j|fd�n d|vr`|jjd|j|fd�d}g}i}|��D]�}d|v�r|s�|�dd�\}}|���d	�r�|�	��
d
�r�|||<d}q�|�|�n|||<d}n,|�	��
d
�r�d�|�||<d}n
|�|�qt|�|�qt|S)Nz%s show '%s'rz,failure %d running systemctl show for %r: %sr5zLoadState=not-foundz5systemd could not find the requested service "%r": %sr�rA�{�}rx)
rvr-r�r#r8�
splitlinesr`�lstripr��rstrip�endswithr��join)	r3r|r�r�r�Zvalue_bufferZstatus_dictr~r�rrr�get_systemd_status_dictBs2
z$LinuxService.get_systemd_status_dictcCsx|��}|�d�dkr$d|_d|_nN|�d�dkr@d|_d|_n2|�d�durf|jjd|jfd�nd|_d|_|jS)NZActiveState�activeTFZfailedz4No ActiveState value in systemctl show output for %rr5)r�r.r'r(r#r8r�)r3�drrr�get_systemd_service_statusjsz'LinuxService.get_systemd_service_statuscCs�|jr|j�d�r|��Sd|_|��\}}}|jr||jdur||�d|j|j|j	f�\}}}d|vrnd|_nd|vr|d|_|jr�|j�d�r�|jdur�|�d	|j|jf�\}}}	d
|v|_d|	v|_
|jdur�|dvr�d|_|jdu�r�|�d
�dk�r�|���
|j��d�}
d|
v�r$d|_nxd|
v�r:d|
v|_nbd|
v�rVd|
v�rVd|_nFd|
v�rhd|_n4d|
v�rzd|_n"d|
v�r�d|_nd|
v�r�d|_|jdu�r�|dk�r�d|_|jdu�r�|jdk�r�d|v�r�d|_|jS)Nr��statusz%s status %s %szstop/waitingFz
start/runningTr�z%s %s statusr�r()rArB���ErxrAr"r��runznot r�zcould not access pid filezis dead and pid file existszdead but subsys lockedzdead but pid file existsrZiptablesZACCEPT)r*r�r�r)r=r,r'rvrr!r(�count�lower�replace)r3r|Z
status_stdoutZ
status_stderrZ
initctl_rcZinitctl_status_stdoutZinitctl_status_stderrZ	openrc_rcZopenrc_status_stdoutZopenrc_status_stderrZcleanoutrrrr<|sL 







zLinuxService.get_service_statuscCsP|jdur|jjd|jd�d|_d}|j�d��r�dd�}d}|jtd�krjt�	d	tj
tjB�}d
}nt�	dtj
tjB�}d}d
||jf}d||jf}t|��}|�
�}	Wd�n1s�0Y|�|	�r�|jjdd�d|_tj�|��r�t|��}
|
�
�}Wd�n1�s"0Y|j�rT|�|��rTd|_|�d|�}n*|j�s�|�|��s�d|_d�||f�}nn|j�s�d|_|}n|jj�r�|jj|jd�|j�r�z|||�Wn"t�y�|jjdd�Yn0dS|j�d��r�|j�rd}nd}|�d|j|jf�\}
}}d|j|v�rj|�d|j|jf�|�d|j|jf�\}
}}|j|v�r�|jjd|jd�d||v�r�d||v�r�d|_dS|j�d��r�|j�r�d}nd }|��}|j|k�r�d|_dS|j�d!��r�|j�r
d"}nd#}|�d$|j�\}
}}|��D]t}|�d%�\}}|��}||jk�rV�q,t�d&|�}|j�r~|j|v�r~d|_n|j�s�|j|v�r�d|_�q��q,|j�s�d|_|j�s�dS|j�d'��r�d}t�d(|j�}|�r�d}|j|k�r�d|_|j�r�d}t�d)|j�}|�s�|jj�s�|�d*|j|jf�\}
}}|
d+k�r�|�rb|jj|d�n|jj|d�|j|j|fnd }|jj�s�|�d,|j|j|f�\}
}}|
d+k�r�|�r�|jj|d�n|jj|d�|j|j|fnd|_dS|j�d-��rt|j�r(|�d.|j|jf�\}
}}n|�d/|j|jf�\}
}}d|_|��D]N}|j�rz|�d0�d1k�rzd|_�q�|j�sR|�d2�d1k�rRd|_�q��qR|jj�r�|jj|jd�|j�s�dS|j�r"|�d3|j|jf�\}
}}|
d+k�s|dk�r|jjd4|
||fd�|
||fS|�d5|j|jf�\}
}}|
d+k�sR|dk�rj|jjd6|
||fd�|
||fSd|_|j�d!��r�|j||jd7|jf}n,|j�d��r�|j||j f}n|j|j|f}|jj�r�|jj|jd�|�d,|�\}
}}|
d+k�rF|�r*|jjd8||j|
|fd�n|jjd9||j|
|fd�|
||fS):NzScannot detect command to enable service %s, typo or init system potentially unknownr5Tr�cSs t|d�}|�|�|��dS)N�w)rXrlrL)�	file_nameZ
file_contentsZ
override_filerrr�write_to_override_file�s

z;LinuxService.service_enable.<locals>.write_to_override_filez	/etc/initz0.6.7z^manual\s*$zmanual
z^start on manual\s*$zstart on manual
z
%s/%s.confz%s/%s.overridez+manual stanza not supported in a .conf fileFr"rx)r&zCould not modify override filer�ZonZoffz%s --list %szchkconfig --add %sz%s --add %sz%service %s does not support chkconfigz3:%sz5:%sr�r%�disabler��add�deletez%s show�|z\s+r�r�z/etc/rc?.d/K??z%s %s defaultsr�%s %s %sr�z%s -n -v %sz%s -n -r -v %szenable servicerTzremove servicerwz3Failed to install service. rc: %s, out: %s, err: %sz%s -r %sz2Failed to remove service. rc: %s, out: %s, err: %s� z$Error when trying to %s %s: rc=%s %szFailure for %s %s: rc=%s %s)!r-r#r8rr&r�r�rr�r��M�IrXrer�rKr�r�r%�subr�r�r�r�rvr�r�r`r�r r��findr�)r3r)r�ZinitpathZmanregZconfig_lineZconf_file_nameZoverride_file_nameZconf_file_fhZconf_file_contentZoverride_fhZoverride_file_contentsZoverride_stater|r�r�Zservice_enabledr~r�Z	runlevelsrZslinksZklinksrrrrr;�s$

&

(











zLinuxService.service_enablecCs4d}|j}|jrf|j�d�sP|j�d�r>|j}d|j|f}qdd|j|jf}q�|j}d|j|f}n|jdur�|jr�d|j}|jr�|j�d�r�|jdkr�|jr�|jd|d	d
�|jdk�r|dkr�|jd||j|fd	d
�\}}}n"|jd|j|j|fd	d
�\}}}�n|j�rH|j�d��rH|jd||j|fd	d
�\}}}n�|dk�rr|jd|d
|fd	d
�\}}}n |jdd
|j|fd	d
�\}}}|j	�r�t
�	|j	�|dk�r�|jd|d|fd	d
�\}	}
}n |jdd|j|fd	d
�\}	}
}|dk�r|	dk�r|	}|
}|}n||	}||
}||}|||fS)Nr"r�r�rw�%sr�r�z%s zapT�rpr�r�r�r)r!r*r�rr�r+r)r(rvr�time)r3r*r!Zrc_staterQrRZrc1Zstdout1Zstderr1Zrc2Zstdout2Zstderr2rrrr=�sH
""&"
  
  zLinuxService.service_control)
r�r�r�r�ryr�r:r�r�r�r<r;r=rrrrr��s_(>tr�c@s8eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dS)�FreeBsdServicez�
    This is the FreeBSD Service manipulation class - it uses the /etc/rc.conf
    file for controlling services started at boot and the 'service' binary to
    check status and perform direct service manipulation.
    ZFreeBSDNcCs6|j�dd�|_|js$|jjdd�|j�d�|_dS)Nr�Tzunable to find service binaryr5Zsysrc)r#r{r*r8�	sysrc_cmdr9rrrr:�sz FreeBsdService.get_service_toolscCsZ|�d|j|jd|jf�\}}}|jdkr8d|v|_n|dkrHd|_n|dkrVd|_dS)	N�%s %s %s %s�	onestatusZpfZEnabledrAFrT)rvr*rr!r'�r3r|rQrRrrrr<s"
z!FreeBsdService.get_service_statuscCs�|jrd|_nd|_gd�}|D]}tj�|�r ||_q |�d|j|jd|j	f�\}}}zt
j|dd�}Wnty~Yn0|s�|j
jd||d	�|D]"}d
|vr�|�d
d�\|_}q�q�|jdur�|j
jd||d	�|j�r�|�d|j|jf�\}}	}|d
k�r|}	|	����|jk�r�d|_|j
j�r@|j
jddd�|�d|j|j|jf�\}}
}|d
k�r||j
jd|
|d	�|�d|j|jdf�\}}}
|j|d
kk�r�|j
jd|
|d	�nd|_n.z
|��WSt�y�|j
jdd�Yn0dS)N�YES�NO)�/etc/rc.confz/etc/rc.conf.localz/usr/local/etc/rc.confr��rcvarTr�zunable to determine rcvar)r6rQrRr�rAz%s -n %srr�r�z
%s %s="%s"zunable to set rcvar using sysrcr�rz/unable to set rcvar: sysrc did not change valueFzunable to set rcvarr5)r%r1rKr�r�r/rvr*rr!r_r`r�r#r8r0r�r�r�r&r�r�r�)r3�rcfiles�rcfiler|rQrRZrcvarsr�Zdefault_rcconf_valueZcurrent_rcconf_valueZ
change_stdoutZ
change_stderrZcheck_stdoutZcheck_stderrrrrr;
sN"


 

zFreeBsdService.service_enablecCsd|jdkrd|_|jdkr d|_|jdkr0d|_|�d|j|j|j|jf�}|jr`t�|j�|S)Nr��onestartr��onestopr�Z	onereloadr�)r)rvr*rr!rr�)r3�retrrrr=Ps


zFreeBsdService.service_control)
r�r�r�r�ryr�r:r<r;r=rrrrr��s
Cr�c@s eZdZdZdZdZdd�ZdS)�DragonFlyBsdServicez�
    This is the DragonFly BSD Service manipulation class - it uses the /etc/rc.conf
    file for controlling services started at boot and the 'service' binary to
    check status and perform direct service manipulation.
    Z	DragonFlyNcCsR|jrd|_nd|_dg}|D]}tj�|�r||_qd|j�dd�|_|�	�S�Nr�r�r�r��-�_�
r%r1rKr�r�r/rr�r0r��r3r�r�rrrr;ksz"DragonFlyBsdService.service_enable)r�r�r�r�ryr�r;rrrrrasrcs@eZdZdZdZdZdd�Zdd�Zdd	�Z�fd
d�Z	�Z
S)�OpenBsdServicez�
    This is the OpenBSD Service manipulation class - it uses rcctl(8) or
    /etc/rc.d scripts for service control. Enabling a service is
    only supported if rcctl is present.
    ZOpenBSDNcCsZ|j�d�|_|jr|j|_n$d}d||jf}tj�|�rB||_|jsV|jjdd�dS)NZrcctl�	/etc/rc.dr�zunable to find svc_cmdr5)	r#r{r-r*rrKr�r�r8)r3ZrcdirZ	rc_scriptrrrr:�s
z OpenBsdService.get_service_toolscCst|jr&|�d|jd|jf�\}}}n|�d|jdf�\}}}|rR|jj|d�|dkrbd|_n|dkrpd|_dS)	Nr��checkrwr5rAFrT)r-rvr*rr#r8r'r�rrrr<�s z!OpenBsdService.get_service_statuscCs>|jr$|jd|j|j|jfdd�S|�d|j|jf�SdS)Nz%s -f %s %sTr�z%s -f %s)r-rvr*r)rr9rrrr=�szOpenBsdService.service_controlc
sr|jstt|���S|�d|jd|jdf�\}}}|rF|jj|d�|��}|dks^|dkrdd}n|}|�d|jd|jdf�\}}}|r�|jj|d�|��}|dks�|dkr�d}n|}|j	r�|j	|kr�|j	}n|j	s�||kr�d	}nd}|�d|jd|jd
f�\}}}|j
�r^|dk�r(|�s(dS|dk�r>d|j}	nd}	|�rXd
|j|f}
nd}
n|dk�rldSd|j}	d}
|	�s�|
�s�|jjdd�|jj�r�|jjddd�d}|	�r|�d|j|	f�\}}}|dk�r|�r�|jj|d�n|jjdd�d}|
�rh|�d|j|
f�\}}}|dk�rh|�rJ|�rDd|}n|}n|�rVd}nd}|jj|d�d|_
dS)Nr�Zgetdef�flagsr5r�r�r"r.r�r�rzset %s status onzset %s flags %srAzset %s status offzFneither status_action or status_flags is set, this should never happenTr�r�rwz%rcctl failed to modify service statusz7rcctl modified service status but failed to set flags: z5rcctl modified service status but failed to set flagsz$rcctl failed to modify service flags)r-rrr;rvrr#r8r�r!r%r�r�r&)
r3r|rQrRZ
getdef_stringZ
default_flagsZ
get_stringZ
current_flagsZ
changed_flagsZ
status_actionZflags_actionZstatus_modifiedZ
error_messagerrrr;�sv   






zOpenBsdService.service_enable)r�r�r�r�ryr�r:r<r=r;r�rrrrr{src@s8eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dS)�
NetBsdServicea>
    This is the NetBSD Service manipulation class - it uses the /etc/rc.conf
    file for controlling services started at boot, check status and perform
    direct service manipulation. Init scripts in /etc/rc.d are used for
    controlling services (start/stop) as well as for controlling the current
    state.
    ZNetBSDNcCsHdg}|D]$}d||jf}tj�|�r
||_q
|jsD|jjdd�dS)Nrr�zunable to find rc.d scriptr5)rrKr�r�r+r#r8)r3r�r�r�rrrr:szNetBsdService.get_service_toolscCsR|jrd|_nd|_dg}|D]}tj�|�r||_qd|j�dd�|_|�	�Srrrrrrr;'szNetBsdService.service_enablecCsHd|j|_|�d|jdf�\}}}|dkr6d|_n|dkrDd|_dS)Nr�rwr�rAFrT)r+r*rvr'r�rrrr<6sz NetBsdService.get_service_statuscCsF|jdkrd|_|jdkr d|_d|j|_|jd|j|jfdd�S)	Nr�r�r�r�r�rwTr�)r)r+r*rvr9rrrr=>s

zNetBsdService.service_control)
r�r�r�r�ryr�r:r;r<r=rrrrrsrc@sHeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�SunOSServicez�
    This is the SunOS Service manipulation class - it uses the svcadm
    command for controlling services, and svcs command for checking status.
    It also tries to be smart about taking the service out of maintenance
    state if necessary.
    rNcCsb|j�dd�|_|js$|jjdd�|j�dd�|_|jsH|jjdd�|��rXd|_nd|_dS)	NZsvcsTzunable to find svcs binaryr5Zsvcadmzunable to find svcadm binary�-sr")r#r{�svcs_cmdr8�
svcadm_cmd�svcadm_supports_sync�svcadm_syncr9rrrr:RszSunOSService.get_service_toolscCs>tdd���D]*}t�d|���}|r|��dkrdSqdS)Nz/etc/releaser�z \s+Oracle Solaris (\d+)\.(\d+).*)Z11�2T)rX�	readlinesr��matchr�r�)r3r~�mrrrrbsz!SunOSService.svcadm_supports_synccCs"|��}|dkrd|_nd|_dS)N�onlineTF)�get_sunos_svcs_statusr'�r3r�rrrr<jszSunOSService.get_service_statuscCsl|�d|j|jf�\}}}|dkrF|r8|jj|d�n|jj|d�|�d��d�}|d�d�d}|S)NrwrAr5rxrTr�r)rvrrr#r8r�r`)r3r|rQrRr}r�rrrrssz"SunOSService.get_sunos_svcs_statusc	Cs |�d|j|jf�\}}}|dkrF|r8|jj|d�n|jj|d�d}d}|�d�D]&}|�d�rXd|vrrd}d	|vrXd}qX|r�|p�|o�|}|jr�|r�dS|js�|s�dS|jj�s|jr�d
}nd}|�d|j	||jf�\}}}|dk�r|�r|jj|d�n|jj|d�d|_
dS)
Nz%s -l %srr5Frxr�trueT�	temporaryz
enable -rsz
disable -sr�)rvrrr#r8r`r�r%r�rr&)	r3r|rQrRrrr~Zstartup_enabled�subcmdrrrr;�s8




zSunOSService.service_enablecCs�|��}|jdvrP|dvrP|�d|j|jf�\}}}|dkrH|||fS|��}|dvrj|jjd|d�|jdkrzd}nZ|jd	kr�d
}nJ|jdkr�d|j}n4|jd
kr�|dkr�d|j}n|jd
kr�|dkr�d}|�d|j||jf�S)N)r�r�r�)ZmaintenanceZdegradedz%s clear %srz)Failed to bring service out of %s status.r5r�zenable -rstr�zdisable -str�z
refresh %sr�rz
restart %sr�)rr)rvrrr#r8r)r3r�r|rQrRrrrrr=�s&



zSunOSService.service_control)r�r�r�r�ryr�r:rr<rr;r=rrrrrHs	2rc@s8eZdZdZdZdZdd�Zdd�Zdd�Zd	d
�Z	dS)�AIXa
    This is the AIX Service (SRC) manipulation class - it uses lssrc, startsrc, stopsrc
    and refresh for service control. Enabling a service is currently not supported.
    Would require to add an entry in the /etc/inittab file (mkitab, chitab and rmitab
    commands)
    NcCs�|j�dd�|_|js$|jjdd�|j�dd�|_|jsH|jjdd�|j�dd�|_|jsl|jjdd�|j�d	d�|_|js�|jjd
d�dS)NZlssrcTzunable to find lssrc binaryr5Zstartsrczunable to find startsrc binaryZstopsrczunable to find stopsrc binaryZrefreshzunable to find refresh binary)r#r{�	lssrc_cmdr8�startsrc_cmd�stopsrc_cmd�refresh_cmdr9rrrr:�szAIX.get_service_toolscCs"|��}|dkrd|_nd|_dS)Nr�TF)�get_aix_src_statusr'rrrrr<�szAIX.get_service_statuscCs�|�d|j|jf�\}}}|dkr�|�d|j|jf�\}}}|dkrl|r\|jj|d�q�|jj|d�q�|��}|dd�D],}|��d��dkr�|��d��}q�q�d}|Sn&|�d��d�}|d�d�d}|SdS)	Nz%s -s %srAz%s -g %sr5rTr�rxr�)	rvrrr#r8r�r`r�r�)r3r|rQrRr}rr�rrrr!�s"zAIX.get_aix_src_statuscCsv|�d|j�\}}}|dkrB|r2|jj|d�q�|jj|d�nx|��}g}g}|dd�D]<}|��d��}|��d��}	|�|�|	r^|�|	�q^|j|vr�d}
n|j|vr�d}
|j	dkr�|j
}nb|j	dkr�|j}nP|j	d	kr�|j}n>|j	d
k�r.|�d|j|
|jf�|j
�r(t�
|j
�|j
}|j�r\|j	dv�r\|�d
||j|
|jf�S|�d||
|jf�SdS)Nz%s -arAr5rr
z-gr�r�r�r�r�)r�r�z%s -a "%s" %s %s)rvrr#r8r�r`r�r�rr)rrr rr�r!)r3r|rQrRr}Z
subsystemsr�r~Z	subsystem�groupZsrccmd_parameterZsrccmdrrrr=s@





zAIX.service_control)
r�r�r�r�ryr�r:r<r!r=rrrrr�s	 rc
Cs"tttddd�tdgd�d�tdd�tdd�tdd�tdd	d
�tdddgd
�d�dddggd�}t|�}|�d|j�|jr�|�d|j�d}d}d}i}|j|d<|��|jj	ddur�|�
�|j|d<|j	ddur�|j|d<|j
fi|��|j|d<|j�r|��n|��|��|��\}}}|dk�rp|�rPd|v�rPn |�rd|j|d�n|j|d�|j|jB|d<|jj	ddu�r�|jj	d|d<|jj	d�s�|��}|du�r�d|d<n|du�r�d|d<nd|d<n$|jj	ddv�rd|d<nd|d<|j
fi|��dS)N�strT)�type�required)r�r�r�r�)r$�choices�int)r$r��default)r$r(r"r)r$r(�aliases)rrrrrr r!rr)Z
argument_specZsupports_check_modeZrequired_one_ofz"Service instantiated - platform %sz&Service instantiated - distribution %srrr&zJob is already runningr5ZabsentFr�r�)r�r�r�)r
rUr�debugryr�rr:r#r$r;r%r&r�rrrr<r�r�r8r2)r#r�r|r�r��resultr�rrr�mainGsn

�	�











r,�__main__)/Z
__future__rrrr$Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNr�rirKryr�rdr_rar�r�rzZ#ansible.module_utils.compat.versionrZansible.module_utils._textrr	Zansible.module_utils.basicr
Z"ansible.module_utils.common.localerZ$ansible.module_utils.common.sys_inforZansible.module_utils.servicer
Zansible.module_utils.sixrr�objectrr�r�rrrrrr,r�rrrr�<module>sRi'0o8y[