%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/runit.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZej	e
�Zddlm
Z
ddlZddlZidd6Zddd	gZdZx*eD]"Zejje�r�eZPq�q�WgZd
ad'Zd�Zd�Zd
�Zd�Zd�Zd�Z d�Z!dd�Z"d�Z#d�Z$dd�Z%d�Z&d�Z'ddd�Z(ddd�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d �Z/d!�Z0d"�Z1d#�Z2e3d$�Z4e3d%�Z5d&�Z6dS((u�
runit service module
(http://smarden.org/runit)

This module is compatible with the :mod:`service <salt.states.service>` states,
so it can be used to maintain services using the ``provider`` argument:

.. code-block:: yaml

    myservice:
      service:
        - running
        - provider: runit

Provides virtual `service` module on systems using runit as init.


Service management rules (`sv` command):

    service $n is ENABLED   if file SERVICE_DIR/$n/run exists
    service $n is AVAILABLE if ENABLED or if file AVAIL_SVR_DIR/$n/run exists
    service $n is DISABLED  if AVAILABLE but not ENABLED

    SERVICE_DIR/$n is normally a symlink to a AVAIL_SVR_DIR/$n folder


Service auto-start/stop mechanism:

    `sv` (auto)starts/stops service as soon as SERVICE_DIR/<service> is
    created/deleted, both on service creation or a boot time.

    autostart feature is disabled if file SERVICE_DIR/<n>/down exists. This
    does not affect the current's service status (if already running) nor
    manual service management.


Service's alias:

    Service `sva` is an alias of service `svc` when `AVAIL_SVR_DIR/sva` symlinks
    to folder `AVAIL_SVR_DIR/svc`. `svc` can't be enabled if it is already
    enabled through an alias already enabled, since `sv` files are stored in
    folder `SERVICE_DIR/svc/`.

    XBPS package management uses a service's alias to provides service
    alternative(s), such as chrony and openntpd both aliased to ntpd.
i(tabsolute_importtunicode_literalstprint_functionN(tCommandExecutionErrorureloadureload_u/serviceu/var/serviceu/etc/serviceurunitcC@s_tjd�dkr<tddkr2td�ndatStjjjd�rUtStdfS(	u�
    Virtual service only on systems using runit as init process (PID 1).
    Otherwise, use this module with the provider mechanism.
    uiniturunituosuVoidu/etc/svuserviceusvu'Runit not available.  Please install sv(	t
__grains__tgettadd_svc_avail_patht__virtualname__tsalttutilstpathtwhichtFalse(((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt__virtual__Xs
cC@s(tstd��ntjjt|�S(u]
    Return SERVICE_DIR+name if possible

    name
        the service's name to work on
    u!Could not find service directory.(tSERVICE_DIRRtosR
tjoin(tname((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt
_service_pathhscC@s$djt|��}td|�S(u�
    Start service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.start <service name>
    usv start {0}ucmd.retcode(tformatRt__salt__(Rtcmd((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytstartus
cC@s$djt|��}td|�S(u�
    Stop service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.stop <service name>
    usv stop {0}ucmd.retcode(RRR(RR((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytstop�s
cC@s$djt|��}td|�S(u�
    Reload service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.reload <service name>
    u
sv reload {0}ucmd.retcode(RRR(RR((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytreload_�s
cC@s$djt|��}td|�S(u�
    Restart service

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.restart <service name>
    usv restart {0}ucmd.retcode(RRR(RR((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytrestart�s
cC@st|�dS(u�
    Calls runit.restart()

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.full_restart <service name>
    N(R(R((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytfull_restart�s
cC@s�|rttd|��St|�}tjj|�s<tSdj|�}y!td|�}|jd�SWnt	k
r�tSXdS(u�
    Return ``True`` if service is running

    name
        the service's name

    sig
        signature to identify with ps

    CLI Example:

    .. code-block:: bash

        salt '*' runit.status <service name>
    u
status.pidu
sv status {0}ucmd.run_stdouturun: N(
tboolRRRR
texistsRRt
startswitht	Exception(Rtsigtsvc_pathRtout((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytstatus�s
cC@sVtjj|d�}tjj|�rRtjj|�rRtj|tj�rRtStS(u�
    Return ``True`` if directory <svc_path> is really a service:
    file <svc_path>/run exists and is executable

    svc_path
        the (absolute) directory to check for compatibility
    urun(RR
RRtaccesstX_OKtTrueR(R trun_file((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt_is_svc�scC@s&tjjtjjt|�d��S(u0
    Return ``True`` if service <name> is autostarted by sv
    (file $service_folder/down does not exist)
    NB: return ``False`` if the service is not enabled.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.status_autostart <service name>
    udown(RR
RRR(R((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytstatus_autostartsu*cC@smtstd��nt�}xBtjtjjt|��D]"}t|�s=|j|�q=q=Wt	|�S(u9
    Return list of broken path(s) in SERVICE_DIR that match ``name``

    A path is broken if it is a broken symlink or can not be a runit service

    name
        a glob for service name. default is '*'

    CLI Example:

    .. code-block:: bash

        salt '*' runit.get_svc_broken_path <service name>
    u!Could not find service directory.(
RRtsettglobRR
RR'taddtsorted(Rtrettel((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytget_svc_broken_paths	%cC@stS(uB
    Return list of paths that may contain available services
    (tAVAIL_SVR_DIRS(((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytget_svc_avail_path/scC@s6tjj|�r2|tkr.tj|�ntStS(u�
    Add a path that may contain available services.
    Return ``True`` if added (or already present), ``False`` on error.

    path
        directory to add to AVAIL_SVR_DIRS
    (RR
RR0tappendR%R(R
((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyR6s
cC@s8tstd��nt�}x[tjtjjt|��D];}t|�r=|jtj	|��t
jd|�q=q=W|dkr�t|�St�}xct
D][}xRtjtjj||��D]2}t|�r�|j|�t
jd|�q�q�Wq�W|dkr|j|�}n|j|�}t|�S(ue
    Return a list of paths to services with ``name`` that have the specified ``status``

    name
        a glob for service name. default is '*'

    status
        None       : all services (no filter, default choice)
        'DISABLED' : available service(s) that is not enabled
        'ENABLED'  : enabled service (whether started on boot or not)
    u!Could not find service directory.ufound enabled service path: %suENABLEDu found available service path: %suDISABLED(RRR)R*RR
RR'R+treadlinktlogttraceR,R0t
differencetunion(RR"tenaR.tavatdR-((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt
_get_svc_pathEs&	%
	
%
cC@s2tgt||�D]}tjj|�^q�S(uQ
    Return list of services that have the specified service ``status``

    name
        a glob for service name. default is '*'

    status
        None       : all services (no filter, default choice)
        'DISABLED' : available service that is not enabled
        'ENABLED'  : enabled service (whether started on boot or not)
    (R,R;RR
tbasename(RR"R.((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt
_get_svc_listyscC@s�i}x�tD]�}x�tjtjj|d��D]�}tjj|�sPq2ntj|�}tjj|�s�tjj||�}ntjj|�}||kr�g||<n||j	|�q2Wq
W|S(uU
    Returns the list of service's name that are aliased and their alias path(s)
    u*(
R0R*RR
RtislinkR3tisabsR<R2(R-R:R.tpsvctnsvc((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt
get_svc_alias�s
%
cC@s|t|�kS(u�
    Returns ``True`` if the specified service is available, otherwise returns
    ``False``.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.available <service name>
    (R=(R((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt	available�scC@s|t|�kS(u

    The inverse of runit.available.
    Returns ``True`` if the specified service is not available, otherwise returns
    ``False``.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' runit.missing <service name>
    (R=(R((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytmissing�scC@st�S(u}
    Return a list of all available services

    CLI Example:

    .. code-block:: bash

        salt '*' runit.get_all
    (R=(((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytget_all�s
cC@s
tdd�S(u�
    Return a list of all enabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_enabled
    R"uENABLED(R=(((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytget_enabled�s
cC@s
tdd�S(u�
    Return a list of all disabled services

    CLI Example:

    .. code-block:: bash

        salt '*' service.get_disabled
    R"uDISABLED(R=(((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytget_disabled�s
cC@s|t|d�kS(u�
    Return ``True`` if the named service is enabled, ``False`` otherwise

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.enabled <service name>
    uENABLED(R=(R((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytenabled�scC@s|t|d�kS(u�
    Return ``True`` if the named service is disabled, ``False``  otherwise

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.disabled <service name>
    uENABLED(R=(R((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytdisabled�scC@s�i}t|d<t|d<t|d<d
|d<t|d<d
|d<t|�|d<|ds`|St|�|d<|d|d<t|�|d<t|�|d<t|�d|d<|dr�tj	j
|dd	�|d<n|S(u�
    Show properties of one or more units/jobs or the manager

    name
        the service's name

    CLI Example:

        salt '*' service.show <service name>
    uenabledudisabledurunninguservice_pathu	autostartucommand_pathu	availableiurunN(RR%tNoneRCRHR"R(R;RR
R(RR-((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytshows$







 c
K@s�t|�stSt�}||kr6tjd�tSt|�d}tjj|d�}t	|�r�tjj
|�r�ytj|�Wq�tk
r�tjd|�tSXnt
S|s/tjd|�tjj
|�s/y tjjj|d�j�Wq,tk
r(tjdj|��tSXq/nytj|t|��Wn>tk
r�tjdj|��|s�tj|�ntSXd	jt|��}d
}d}xM|dkr�|dkr�tjd�|d
7}td
|�}	|	d}q�W|rRtjj
|�rRytj|�WqRtk
rNtjd|�d
}qRXn|dkr�tjtjjt|�|g��tSt
S(u'
    Start service ``name`` at boot.
    Returns ``True`` if operation is successful

    name
        the service's name

    start : False
        If ``True``, start the service once enabled.

    CLI Example:

    .. code-block:: bash

        salt '*' service.enable <name> [start=True]
    u1This service is aliased, enable its alias insteadiudownuUnable to remove file %suneed a temporary file %suwuUnable to create file {0}uUnable to create symlink {0}u
sv status {0}ii
g�?ucmd.run_alluretcodeuUnable to remove temp file %s(RCRRBR4terrorR;RR
RRHRtunlinktOSErrorR%R5RR	tfilestfopentclosetIOErrorRtsymlinkRttimetsleepR(
RRtkwargstaliastsvc_realpatht	down_fileRt
retcode_svtcount_svtcall((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytenable,sb	

 





%cK@s�t|�stSt|�d}tjj|d�}|rH||�ntjj|�s�y tjj	j
|d�j�Wq�tk
r�t
jd|�tSXntS(u
    Don't start service ``name`` at boot
    Returns ``True`` if operation is successful

    name
        the service's name

    stop
        if True, also stops the service

    CLI Example:

    .. code-block:: bash

        salt '*' service.disable <name> [stop=True]
    iudownuwuUnable to create file %s(RHRR;RR
RRRR	RORPRQRRR4RLR%(RRRVRXRY((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pytdisable�s
 
cC@s�t|�stSt|�}tjj|�sBtjd|�tSt|�sbtjd|�tSytj	|�Wn"t
k
r�tjd|�tSXtS(u
    Remove the service <name> from system.
    Returns ``True`` if operation is successful.
    The service will be also stopped.

    name
        the service's name

    CLI Example:

    .. code-block:: bash

        salt '*' service.remove <name>
    u %s is not a symlink: not removeduFailed to stop service %suUnable to remove symlink %s(RHRRRR
R>R4RLRtremoveRRR%(RR ((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyR_�s
(urunit(7t__doc__t
__future__RRRRR*tloggingRTt	getLoggert__name__R4tsalt.exceptionsRtsalt.utils.filesRtsalt.utils.patht__func_alias__tVALID_SERVICE_DIRSRJRtservice_dirR
RR0Rt__virtual_aliases__R
RRRRRRR"R'R(R/R1RR;R=RBRCRDRERFRGRHRIRKRR]R^R_(((s6/usr/lib/python2.7/site-packages/salt/modules/runit.pyt<module>/sb
	
		
					%				4				
	
	
			$_'

Zerion Mini Shell 1.0