
    VhU                     j    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ dadad Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functiona  
module: openwrt_init
author:
  - "Andrew Gaffney (@agaffney)"
short_description: Manage services on OpenWrt
description:
  - Controls OpenWrt services on remote hosts.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    type: str
    description:
      - Name of the service.
    required: true
    aliases: ['service']
  state:
    type: str
    description:
      - V(started)/V(stopped) are idempotent actions that will not run commands unless necessary.
      - V(restarted) will always bounce the service.
      - V(reloaded) will always reload.
    choices: ['started', 'stopped', 'restarted', 'reloaded']
  enabled:
    description:
      - Whether the service should start on boot. B(At least one of state and enabled are required).
    type: bool
  pattern:
    type: str
    description:
      - If the service does not respond to the 'running' command, name a substring to look for as would be found in the output
        of the C(ps) command as a stand-in for a 'running' result. If the string is found, the service will be assumed to
        be running.
notes:
  - One option other than O(name) is required.
requirements:
  - An OpenWrt system (with python)
a  
- name: Start service httpd, if not running
  community.general.openwrt_init:
    state: started
    name: httpd

- name: Stop service cron, if running
  community.general.openwrt_init:
    name: cron
    state: stopped

- name: Reload service httpd, in all cases
  community.general.openwrt_init:
    name: httpd
    state: reloaded

- name: Enable service httpd
  community.general.openwrt_init:
    name: httpd
    enabled: true

N)AnsibleModulec                  J    t         j                  t        dg      \  } }}| dk(  S )Nenabledr   )modulerun_commandinit_script)rcdummys     r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/openwrt_init.py
is_enabledr   Y   s'    ));	*BCBu7N    c            
         t        t        t        dddg      t        dg d      t        d      t        d      	      dd
g      at        j                  d   } d| z   a| dd}t
        j                  j                  t              st        j                  d| z         t        j                  d   t               }||d<   |t        j                  d   k7  rd|d<   t        j                  d   rdnd}t        j                  s\t        j                  t        |g      \  }}}t               t        j                  d   k7  rt        j                  d|d| d|       | |d<   t        j                  d   bd}t        j                  d   rZt        j                  dd      }t        j                  |dg      \  }}	}|dk(  rJ|	j                  d      }
t        d |
D              }n&t        j                  t        d g      \  }}}|dk(  rd}t        j                  d   |d<   d }t        j                  d   d!k(  r
|sHd"}d|d<   n@t        j                  d   d#k(  r
|r(d$}d|d<   n t        j                  d   d d% }d!|d<   d|d<   |rSt        j                  sCt        j                  t        |g      \  }}}|dk7  rt        j                  d|d| d|       t        j                  d&i | y )'NTstrservice)requiredtypealiases)startedstopped	restartedreloaded)r   choicesbool)r   )namestater	   pattern)r   r	   )argument_specsupports_check_moderequired_one_ofr   z/etc/init.d/F)r   changedzservice %s does not exist)msgr	   r$   enabledisablez
Unable to z	 service z: r   r    pswr   r   c              3   R   K   | ]  }t         j                  d    |v xr d|v ! yw)r    zpattern=N)r
   params).0lines     r   	<genexpr>zmain.<locals>.<genexpr>   s-     n`dv}}Y74?ZJVZDZZns   %'runningr   startr   stop )r   dictr
   r+   r   ospathexists	fail_jsonr   
check_moder   get_bin_pathsplitany	exit_json)r   resultr	   actionr   r   errr/   psbinpsoutliness              r   mainrD   `   s    t%)EE+Z[f%e$	
 !-.	F mmF#G 7*KF
 77>>+&87BC }}Y+, $y fmmI.. $F9!'y!9XyF$$!'!3!3[&4I!JE3 <6==#;;$$&RY[^)_$`$+F9}}W) ==#''d3E  &115#,?BuQwD)nhmnn%11;	2JKBuQw !--0w ==!Y. $(y!]]7#y0$(y!]]7+CR0F'F7O $F9$$!'!3!3[&4I!JE37$$&RY[^)_$`
vr   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr5   ansible.module_utils.basicr   r
   r   r   rD   __name__r3   r   r   <module>rM      s[    A @*X,
 
 4	
[| zF r   